8
8
*
9
9
* @flow
10
10
* @providesModule ScrollViewExample
11
+ * @format
11
12
*/
12
13
'use strict' ;
13
14
@@ -20,90 +21,115 @@ var {
20
21
Text,
21
22
TouchableOpacity,
22
23
View,
23
- Image
24
+ Image,
24
25
} = ReactNative ;
25
26
26
27
exports . displayName = 'ScrollViewExample' ;
27
28
exports . title = '<ScrollView>' ;
28
- exports . description = 'Component that enables scrolling through child components' ;
29
+ exports . description =
30
+ 'Component that enables scrolling through child components' ;
29
31
exports . examples = [
30
- {
31
- title : '<ScrollView>' ,
32
- description : 'To make content scrollable, wrap it within a <ScrollView> component' ,
33
- render : function ( ) {
34
- var _scrollView : ScrollView ;
35
- return (
36
- < View >
37
- < ScrollView
38
- ref = { ( scrollView ) => { _scrollView = scrollView ; } }
39
- automaticallyAdjustContentInsets = { false }
40
- onScroll = { ( ) => { console . log ( 'onScroll!' ) ; } }
41
- scrollEventThrottle = { 200 }
42
- style = { styles . scrollView } >
43
- { THUMB_URLS . map ( createThumbRow ) }
44
- </ ScrollView >
45
- < TouchableOpacity
46
- style = { styles . button }
47
- onPress = { ( ) => { _scrollView . scrollTo ( { y : 0 } ) ; } } >
48
- < Text > Scroll to top</ Text >
49
- </ TouchableOpacity >
50
- < TouchableOpacity
51
- style = { styles . button }
52
- onPress = { ( ) => { _scrollView . scrollToEnd ( { animated : true } ) ; } } >
53
- < Text > Scroll to bottom</ Text >
54
- </ TouchableOpacity >
55
- < TouchableOpacity
56
- style = { styles . button }
57
- onPress = { ( ) => { _scrollView . flashScrollIndicators ( ) ; } } >
58
- < Text > Flash scroll indicators</ Text >
59
- </ TouchableOpacity >
60
- </ View >
61
- ) ;
62
- }
63
- } , {
64
- title : '<ScrollView> (horizontal = true)' ,
65
- description : 'You can display <ScrollView>\'s child components horizontally rather than vertically' ,
66
- render : function ( ) {
67
-
68
- function renderScrollView ( title : string , addtionalStyles : typeof StyleSheet ) {
32
+ {
33
+ title : '<ScrollView>' ,
34
+ description :
35
+ 'To make content scrollable, wrap it within a <ScrollView> component' ,
36
+ render : function ( ) {
69
37
var _scrollView : ScrollView ;
70
38
return (
71
- < View style = { addtionalStyles } >
72
- < Text style = { styles . text } > { title } </ Text >
39
+ < View >
73
40
< ScrollView
74
- ref = { ( scrollView ) => { _scrollView = scrollView ; } }
41
+ ref = { scrollView => {
42
+ _scrollView = scrollView ;
43
+ } }
75
44
automaticallyAdjustContentInsets = { false }
76
- horizontal = { true }
77
- style = { [ styles . scrollView , styles . horizontalScrollView ] } >
45
+ onScroll = { ( ) => {
46
+ console . log ( 'onScroll!' ) ;
47
+ } }
48
+ scrollEventThrottle = { 200 }
49
+ style = { styles . scrollView } >
78
50
{ THUMB_URLS . map ( createThumbRow ) }
79
51
</ ScrollView >
80
52
< TouchableOpacity
81
53
style = { styles . button }
82
- onPress = { ( ) => { _scrollView . scrollTo ( { x : 0 } ) ; } } >
83
- < Text > Scroll to start</ Text >
54
+ onPress = { ( ) => {
55
+ _scrollView . scrollTo ( { y : 0 } ) ;
56
+ } } >
57
+ < Text > Scroll to top</ Text >
84
58
</ TouchableOpacity >
85
59
< TouchableOpacity
86
60
style = { styles . button }
87
- onPress = { ( ) => { _scrollView . scrollToEnd ( { animated : true } ) ; } } >
88
- < Text > Scroll to end</ Text >
61
+ onPress = { ( ) => {
62
+ _scrollView . scrollToEnd ( { animated : true } ) ;
63
+ } } >
64
+ < Text > Scroll to bottom</ Text >
89
65
</ TouchableOpacity >
90
66
< TouchableOpacity
91
67
style = { styles . button }
92
- onPress = { ( ) => { _scrollView . flashScrollIndicators ( ) ; } } >
68
+ onPress = { ( ) => {
69
+ _scrollView . flashScrollIndicators ( ) ;
70
+ } } >
93
71
< Text > Flash scroll indicators</ Text >
94
72
</ TouchableOpacity >
95
73
</ View >
96
74
) ;
97
- }
75
+ } ,
76
+ } ,
77
+ {
78
+ title : '<ScrollView> (horizontal = true)' ,
79
+ description :
80
+ "You can display <ScrollView>'s child components horizontally rather than vertically" ,
81
+ render : function ( ) {
82
+ function renderScrollView (
83
+ title : string ,
84
+ addtionalStyles : typeof StyleSheet ,
85
+ ) {
86
+ var _scrollView : ScrollView ;
87
+ return (
88
+ < View style = { addtionalStyles } >
89
+ < Text style = { styles . text } > { title } </ Text >
90
+ < ScrollView
91
+ ref = { scrollView => {
92
+ _scrollView = scrollView ;
93
+ } }
94
+ automaticallyAdjustContentInsets = { false }
95
+ horizontal = { true }
96
+ style = { [ styles . scrollView , styles . horizontalScrollView ] } >
97
+ { THUMB_URLS . map ( createThumbRow ) }
98
+ </ ScrollView >
99
+ < TouchableOpacity
100
+ style = { styles . button }
101
+ onPress = { ( ) => {
102
+ _scrollView . scrollTo ( { x : 0 } ) ;
103
+ } } >
104
+ < Text > Scroll to start</ Text >
105
+ </ TouchableOpacity >
106
+ < TouchableOpacity
107
+ style = { styles . button }
108
+ onPress = { ( ) => {
109
+ _scrollView . scrollToEnd ( { animated : true } ) ;
110
+ } } >
111
+ < Text > Scroll to end</ Text >
112
+ </ TouchableOpacity >
113
+ < TouchableOpacity
114
+ style = { styles . button }
115
+ onPress = { ( ) => {
116
+ _scrollView . flashScrollIndicators ( ) ;
117
+ } } >
118
+ < Text > Flash scroll indicators</ Text >
119
+ </ TouchableOpacity >
120
+ </ View >
121
+ ) ;
122
+ }
98
123
99
- return (
100
- < View >
101
- { renderScrollView ( 'LTR layout' , { direction : 'ltr' } ) }
102
- { renderScrollView ( 'RTL layout' , { direction : 'rtl' } ) }
103
- </ View >
104
- ) ;
105
- }
106
- } ] ;
124
+ return (
125
+ < View >
126
+ { renderScrollView ( 'LTR layout' , { direction : 'ltr' } ) }
127
+ { renderScrollView ( 'RTL layout' , { direction : 'rtl' } ) }
128
+ </ View >
129
+ ) ;
130
+ } ,
131
+ } ,
132
+ ] ;
107
133
108
134
class Thumb extends React . Component < $FlowFixMeProps , $FlowFixMeState > {
109
135
shouldComponentUpdate ( nextProps , nextState ) {
@@ -168,5 +194,5 @@ var styles = StyleSheet.create({
168
194
img : {
169
195
width : 64 ,
170
196
height : 64 ,
171
- }
197
+ } ,
172
198
} ) ;
0 commit comments