@@ -11,6 +11,7 @@ import * as React from 'react';
11
11
12
12
import {
13
13
ScrollView ,
14
+ FlatList ,
14
15
StyleSheet ,
15
16
Switch ,
16
17
Text ,
@@ -20,6 +21,26 @@ import {
20
21
21
22
export function ScrollViewKeyboardInsetsExample ( ) {
22
23
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
+ } ;
23
44
24
45
return (
25
46
< View style = { styles . container } >
@@ -30,26 +51,39 @@ export function ScrollViewKeyboardInsetsExample() {
30
51
value = { automaticallyAdjustKeyboardInsets }
31
52
style = { styles . controlSwitch } />
32
53
</ 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
+ ) }
33
70
< View style = { styles . controlRow } >
34
71
< TextInput placeholder = { 'Text input outside scroll view' } style = { styles . controlTextInput } />
35
72
</ 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
+ }
53
87
</ View >
54
88
) ;
55
89
}
0 commit comments