Skip to content

Commit b815eb5

Browse files
sahrensfacebook-github-bot
authored andcommitted
Prettier ScrollViewExample
Reviewed By: TheSavior, shergin Differential Revision: D6712726 fbshipit-source-id: 30d8bcdcf6a1cbf1c05048462c7b8444b4ea5ede
1 parent 5c17db8 commit b815eb5

File tree

1 file changed

+87
-61
lines changed

1 file changed

+87
-61
lines changed

RNTester/js/ScrollViewExample.js

Lines changed: 87 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
* @flow
1010
* @providesModule ScrollViewExample
11+
* @format
1112
*/
1213
'use strict';
1314

@@ -20,90 +21,115 @@ var {
2021
Text,
2122
TouchableOpacity,
2223
View,
23-
Image
24+
Image,
2425
} = ReactNative;
2526

2627
exports.displayName = 'ScrollViewExample';
2728
exports.title = '<ScrollView>';
28-
exports.description = 'Component that enables scrolling through child components';
29+
exports.description =
30+
'Component that enables scrolling through child components';
2931
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() {
6937
var _scrollView: ScrollView;
7038
return (
71-
<View style={addtionalStyles}>
72-
<Text style={styles.text}>{title}</Text>
39+
<View>
7340
<ScrollView
74-
ref={(scrollView) => { _scrollView = scrollView; }}
41+
ref={scrollView => {
42+
_scrollView = scrollView;
43+
}}
7544
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}>
7850
{THUMB_URLS.map(createThumbRow)}
7951
</ScrollView>
8052
<TouchableOpacity
8153
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>
8458
</TouchableOpacity>
8559
<TouchableOpacity
8660
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>
8965
</TouchableOpacity>
9066
<TouchableOpacity
9167
style={styles.button}
92-
onPress={() => { _scrollView.flashScrollIndicators(); }}>
68+
onPress={() => {
69+
_scrollView.flashScrollIndicators();
70+
}}>
9371
<Text>Flash scroll indicators</Text>
9472
</TouchableOpacity>
9573
</View>
9674
);
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+
}
98123

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+
];
107133

108134
class Thumb extends React.Component<$FlowFixMeProps, $FlowFixMeState> {
109135
shouldComponentUpdate(nextProps, nextState) {
@@ -168,5 +194,5 @@ var styles = StyleSheet.create({
168194
img: {
169195
width: 64,
170196
height: 64,
171-
}
197+
},
172198
});

0 commit comments

Comments
 (0)