Skip to content

Commit 78caaca

Browse files
yungstersfacebook-github-bot
authored andcommitted
RNTester: Text Adjusts Dynamic Layout Example
Summary: Creates a new RNTester example to verify #31538 (D28631465). Changelog: [Android][Added] - RNTester example for adjusting text with dynamic layout. Reviewed By: kacieb Differential Revision: D28779870 fbshipit-source-id: 5297a823645d1e9e35d4c86b491f3c225ecc9543
1 parent b85572a commit 78caaca

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow strict-local
9+
*/
10+
11+
import {Button, Text, StyleSheet, View} from 'react-native';
12+
import * as React from 'react';
13+
import {useState} from 'react';
14+
15+
export default function TextAdjustsDynamicLayoutExample(props: {}): React.Node {
16+
const [height, setHeight] = useState(20);
17+
18+
return (
19+
<>
20+
<View>
21+
<View style={[styles.subjectContainer, {height}]}>
22+
<Text
23+
adjustsFontSizeToFit={true}
24+
numberOfLines={1}
25+
style={styles.subjectText}>
26+
This is adjusting text.
27+
</Text>
28+
</View>
29+
</View>
30+
<View style={styles.row}>
31+
<Button onPress={() => setHeight(20)} title="Set Height to 20" />
32+
</View>
33+
<View style={styles.row}>
34+
<Button onPress={() => setHeight(40)} title="Set Height to 40" />
35+
</View>
36+
<View style={styles.row}>
37+
<Button onPress={() => setHeight(60)} title="Set Height to 60" />
38+
</View>
39+
</>
40+
);
41+
}
42+
43+
const styles = StyleSheet.create({
44+
subjectContainer: {
45+
backgroundColor: 'rgba(254, 255, 0, 0.75)',
46+
justifyContent: 'center',
47+
},
48+
subjectText: {
49+
fontSize: 40,
50+
textAlign: 'center',
51+
},
52+
row: {
53+
marginTop: 10,
54+
},
55+
});

packages/rn-tester/js/examples/Text/TextExample.android.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
'use strict';
1212

13+
import TextAdjustsDynamicLayoutExample from './TextAdjustsDynamicLayoutExample';
14+
1315
const RNTesterBlock = require('../../components/RNTesterBlock');
1416
const RNTesterPage = require('../../components/RNTesterPage');
1517
const React = require('react');
@@ -202,6 +204,9 @@ class TextExample extends React.Component<{...}> {
202204
<RNTesterBlock title="Dynamic Font Size Adjustment">
203205
<AdjustingFontSize />
204206
</RNTesterBlock>
207+
<RNTesterBlock title="Font Size Adjustment with Dynamic Layout">
208+
<TextAdjustsDynamicLayoutExample />
209+
</RNTesterBlock>
205210
<RNTesterBlock title="Wrap">
206211
<Text>
207212
The text should wrap if it goes on multiple lines. See, this is

0 commit comments

Comments
 (0)