forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrollViewSimpleExample.js
More file actions
105 lines (94 loc) · 2.27 KB
/
ScrollViewSimpleExample.js
File metadata and controls
105 lines (94 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
const React = require('react');
const {
ScrollView,
StyleSheet,
Text,
TouchableOpacity,
} = require('react-native');
const NUM_ITEMS = 20;
class ScrollViewSimpleExample extends React.Component<{...}> {
makeItems: (nItems: number, styles: any) => Array<any> = (
nItems: number,
styles,
): Array<any> => {
const items = [];
for (let i = 0; i < nItems; i++) {
items[i] = (
<TouchableOpacity key={i} style={styles}>
<Text>{'Item ' + i}</Text>
</TouchableOpacity>
);
}
return items;
};
render(): React.Node {
// One of the items is a horizontal scroll view
const items = this.makeItems(NUM_ITEMS, styles.itemWrapper);
items[4] = (
<ScrollView key={'scrollView'} horizontal={true}>
{this.makeItems(NUM_ITEMS, [
styles.itemWrapper,
styles.horizontalItemWrapper,
])}
</ScrollView>
);
items.push(
<ScrollView
key={'scrollViewSnap'}
horizontal
snapToInterval={210.0}
pagingEnabled>
{this.makeItems(NUM_ITEMS, [
styles.itemWrapper,
styles.horizontalItemWrapper,
styles.horizontalPagingItemWrapper,
])}
</ScrollView>,
);
const verticalScrollView = (
<ScrollView style={styles.verticalScrollView}>{items}</ScrollView>
);
return verticalScrollView;
}
}
const styles = StyleSheet.create({
verticalScrollView: {
margin: 10,
},
itemWrapper: {
backgroundColor: '#dddddd',
alignItems: 'center',
borderRadius: 5,
borderWidth: 5,
borderColor: '#a52a2a',
padding: 30,
margin: 5,
},
horizontalItemWrapper: {
padding: 50,
},
horizontalPagingItemWrapper: {
width: 200,
},
});
exports.title = '<ScrollViewSimpleExample>';
exports.description =
'Component that enables scrolling through child components.';
exports.examples = [
{
title: 'Simple scroll view',
render: function(): React.Element<typeof ScrollViewSimpleExample> {
return <ScrollViewSimpleExample />;
},
},
];