/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow * @format */ import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; import type {TextLayoutEvent} from 'react-native'; import RNTesterText from '../../components/RNTesterText'; import {useTheme} from '../../components/RNTesterTheme'; import {useState} from 'react'; import {StyleSheet, Text, View} from 'react-native'; type TextLayoutLine = TextLayoutEvent['nativeEvent']['lines'][number]; function InlineView(props: { textAlign: 'auto' | 'left' | 'right' | 'center' | 'justify', long?: boolean, }): React.Node { return ( Parent Child Child { /* $FlowFixMe[invalid-compare] Error discovered during Constant * Condition roll out. See https://fburl.com/workplace/5whu3i34. */ props !== null && props.long === true && ( aaaa a aaaa aaaaaa aaa a a a aaaaa sdsds dsdSAD asd ASDasd ASDas ) } ); } function TextInlineViewsExample(props: {}): React.Node { return ( BoringLayout StaticLayout ); } function EmptyTextExample(): React.Node { const {BorderColor} = useTheme(); return ( ); } function TextAndLayoutLinesJSON({ testID, ellipsizeMode, }: Readonly<{ testID: string, ellipsizeMode: 'head' | 'tail' | 'middle' | 'clip', }>): React.Node { const [lines, setLines] = useState(); return ( {ellipsizeMode} setLines(ev.nativeEvent.lines)}> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin volutpat molestie nunc non tristique. {JSON.stringify(lines, null, 2)} ); } function NumberOfLinesTextLayoutExample(): React.Node { return ( ); } component RtlInlineViewExample( label: string, testID: string, children: React.Node, ) { return ( {label} {children} ); } component RtlAndInlineViewsExample() { return ( مَٰنِ ٱلرَّحِيمِ Hello {' '} World! مَٰنِ ٱلرَّحِيمِ مَٰنِ ٱلرَّحِيمِ مَٰنِ ٱلرَّحِيمِ Hello Hello مَٰنِ ٱلرَّحِيمِ ); } component TextWithLinkRoleExample() { const [pressed, setPressed] = useState(false); const handlePress = () => setPressed(true); const linkColor = pressed ? 'red' : 'teal'; return ( Link Text Nested Link Before{' '} Nested Link {' After'} Nested Link 1 {' - '} Nested Link 2 ); } const styles = StyleSheet.create({ link: { color: 'teal', textDecorationLine: 'underline', }, }); function LastLineClippingExample(): React.Node { // Wrapped paragraphs at assorted font sizes are prone to the final line being // clipped by one physical pixel after layout rounding (issue #53450). The // border makes any clipping of the last line visible. return ( {[11, 12, 13, 14, 15, 16, 17].map(fontSize => ( {`(${fontSize}px) This sentence wraps across multiple lines so the ` + 'final line sits near a pixel boundary and must render fully, ' + 'without being cut off.'} ))} ); } export default [ { title: 'Empty Text', name: 'emptyText', render: EmptyTextExample, }, { title: 'TextInlineViewsExample', name: 'inlineViews', description: 'Shows how inline views are rendered when text is subject to alignment.', expect: 'The red box should align correctly with the rest of the text.', render: TextInlineViewsExample, }, { title: 'RTL and Inline Views', name: 'rtlInlineViews', description: 'RTL Script and Layout Direction, Combined with Inline Views', scrollable: true, render: RtlAndInlineViewsExample, }, { title: 'numberOfLines with onTextLayout', name: 'numberOfLinesLayout', description: 'Shows the behavior of numberOfLines and ellipsizeMode in conjunction with the onTextLayout event', scrollable: true, render: NumberOfLinesTextLayoutExample, }, { title: 'Text with link role', name: 'textWithLinkRole', description: 'Shows the a11y behavior of Text with role="link"', render: TextWithLinkRoleExample, }, { title: 'Wrapped text last-line clipping', name: 'wrappedLastLineClipping', description: 'The final line of wrapped text must render fully, not clipped by one ' + 'physical pixel after layout rounding (issue #53450).', render: LastLineClippingExample, }, ] as ReadonlyArray;