Skip to content

Commit 5e895f2

Browse files
committed
Support FlatLists in keyboard insets tester
1 parent 62fc88a commit 5e895f2

File tree

1 file changed

+51
-17
lines changed

1 file changed

+51
-17
lines changed

packages/rn-tester/js/examples/ScrollView/ScrollViewKeyboardInsetsExample.ios.js

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as React from 'react';
1111

1212
import {
1313
ScrollView,
14+
FlatList,
1415
StyleSheet,
1516
Switch,
1617
Text,
@@ -20,6 +21,26 @@ import {
2021

2122
export function ScrollViewKeyboardInsetsExample() {
2223
const [automaticallyAdjustKeyboardInsets, setAutomaticallyAdjustKeyboardInsets] = React.useState(true);
24+
const [flatList, setFlatList] = React.useState(false);
25+
const [inverted, setInverted] = React.useState(false);
26+
27+
const scrollViewProps = {
28+
contentContainerStyle: styles.scrollViewContent,
29+
automaticallyAdjustKeyboardInsets: automaticallyAdjustKeyboardInsets,
30+
keyboardDismissMode: 'interactive',
31+
};
32+
33+
const data = [...Array(20).keys()];
34+
const renderItem = ({ item, index }) => {
35+
const largeInput = (index % 5) === 4;
36+
return (
37+
<View key={item} style={styles.textInputRow}>
38+
<TextInput placeholder={item.toString()}
39+
multiline={largeInput}
40+
style={[styles.textInput, largeInput && styles.textInputLarger]}/>
41+
</View>
42+
);
43+
};
2344

2445
return (
2546
<View style={styles.container}>
@@ -30,26 +51,39 @@ export function ScrollViewKeyboardInsetsExample() {
3051
value={automaticallyAdjustKeyboardInsets}
3152
style={styles.controlSwitch}/>
3253
</View>
54+
<View style={styles.controlRow}>
55+
<Text><Text style={styles.code}>FlatList</Text> is {flatList + ''}</Text>
56+
<Switch
57+
onValueChange={v => setFlatList(v)}
58+
value={flatList}
59+
style={styles.controlSwitch}/>
60+
</View>
61+
{flatList && (
62+
<View style={styles.controlRow}>
63+
<Text><Text style={styles.code}>inverted</Text> is {inverted + ''}</Text>
64+
<Switch
65+
onValueChange={v => setInverted(v)}
66+
value={inverted}
67+
style={styles.controlSwitch}/>
68+
</View>
69+
)}
3370
<View style={styles.controlRow}>
3471
<TextInput placeholder={'Text input outside scroll view'} style={styles.controlTextInput} />
3572
</View>
36-
<ScrollView
37-
contentContainerStyle={[
38-
styles.scrollViewContent,
39-
]}
40-
automaticallyAdjustKeyboardInsets={automaticallyAdjustKeyboardInsets}
41-
keyboardDismissMode={'interactive'}>
42-
{[...Array(20).keys()].map((item, index) => {
43-
const largeInput = (index % 5) === 4;
44-
return (
45-
<View key={item} style={styles.textInputRow}>
46-
<TextInput placeholder={item.toString()}
47-
multiline={largeInput}
48-
style={[styles.textInput, largeInput && styles.textInputLarger]}/>
49-
</View>
50-
);
51-
})}
52-
</ScrollView>
73+
{flatList
74+
? (
75+
<FlatList
76+
{...scrollViewProps}
77+
inverted={inverted}
78+
data={data}
79+
renderItem={renderItem}/>
80+
)
81+
: (
82+
<ScrollView {...scrollViewProps}>
83+
{data.map((item, index) => renderItem({ item, index }))}
84+
</ScrollView>
85+
)
86+
}
5387
</View>
5488
);
5589
}

0 commit comments

Comments
 (0)