Skip to content

Commit

Permalink
Make text wrap examples not rely on the RNTester window width (facebo…
Browse files Browse the repository at this point in the history
…ok#44505)

Summary:

# Changelist:
[Internal] - 

The RNTester/Text tests, that are related to text wrapping (such as "wrap mode", "ellipsize", "numberOfLines" ones) were written with the mobile form factor in mind, whereas the RNTester window is generally expected to be narrow and tall.

Now, that we are running on other platforms as well, there is no guarantee about the RNTester window width, in general, so these tests relying on particular window width is not practical anymore.

This makes the corresponding tests work in a useful way without making assumptions about the RNTester's window width.

Differential Revision: D57166025
  • Loading branch information
rshest authored and facebook-github-bot committed May 9, 2024
1 parent a45c589 commit 0b740fb
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions packages/rn-tester/js/examples/Text/TextExample.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class TextExample extends React.Component<{...}> {
<TextAdjustsDynamicLayoutExample />
</RNTesterBlock>
<RNTesterBlock title="Wrap">
<Text>
<Text style={styles.wrappedText}>
The text should wrap if it goes on multiple lines. See, this is
going to the next line.
</Text>
Expand Down Expand Up @@ -674,19 +674,19 @@ class TextExample extends React.Component<{...}> {
</Text>
</RNTesterBlock>
<RNTesterBlock title="numberOfLines attribute">
<Text numberOfLines={1}>
<Text numberOfLines={1} style={styles.wrappedText}>
Maximum of one line no matter now much I write here. If I keep
writing it{"'"}ll just truncate after one line
</Text>
<Text style={{fontSize: 31}} numberOfLines={1}>
<Text style={[{fontSize: 31}, styles.wrappedText]} numberOfLines={1}>
Maximum of one line no matter now much I write here. If I keep
writing it{"'"}ll just truncate after one line
</Text>
<Text numberOfLines={2} style={{marginTop: 20}}>
<Text numberOfLines={2} style={[{marginTop: 20}, styles.wrappedText]}>
Maximum of two lines no matter now much I write here. If I keep
writing it{"'"}ll just truncate after two lines
</Text>
<Text style={{marginTop: 20}}>
<Text style={[{marginTop: 20}, styles.wrappedText]}>
No maximum lines specified no matter now much I write here. If I
keep writing it{"'"}ll just keep going and going
</Text>
Expand Down Expand Up @@ -751,16 +751,25 @@ class TextExample extends React.Component<{...}> {
</Text>
</RNTesterBlock>
<RNTesterBlock title="Ellipsize mode">
<Text numberOfLines={1}>
<Text numberOfLines={1} style={styles.wrappedText}>
This very long text should be truncated with dots in the end.
</Text>
<Text ellipsizeMode="middle" numberOfLines={1}>
<Text
ellipsizeMode="middle"
numberOfLines={1}
style={styles.wrappedText}>
This very long text should be truncated with dots in the middle.
</Text>
<Text ellipsizeMode="head" numberOfLines={1}>
<Text
ellipsizeMode="head"
numberOfLines={1}
style={styles.wrappedText}>
This very long text should be truncated with dots in the beginning.
</Text>
<Text ellipsizeMode="clip" numberOfLines={1}>
<Text
ellipsizeMode="clip"
numberOfLines={1}
style={styles.wrappedText}>
This very long text should be clipped and this will not be visible.
</Text>
</RNTesterBlock>
Expand Down Expand Up @@ -926,6 +935,9 @@ const styles = StyleSheet.create({
textAlignVertical: 'center',
alignSelf: 'center',
},
wrappedText: {
maxWidth: 320,
},
});

function TextBaseLineLayoutExample(props: {}): React.Node {
Expand Down

0 comments on commit 0b740fb

Please sign in to comment.