2015-09-11 21:05:24 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-05-11 20:32:37 +00:00
|
|
|
* @format
|
2015-09-11 21:05:24 +00:00
|
|
|
* @flow
|
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2015-09-11 21:05:24 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2018-05-11 20:32:37 +00:00
|
|
|
var {ScrollView, StyleSheet, Text, TouchableOpacity} = ReactNative;
|
2015-09-11 21:05:24 +00:00
|
|
|
|
|
|
|
var NUM_ITEMS = 20;
|
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class ScrollViewSimpleExample extends React.Component<{}> {
|
2016-07-26 08:00:02 +00:00
|
|
|
static title = '<ScrollView>';
|
2018-06-06 12:20:40 +00:00
|
|
|
static description =
|
|
|
|
'Component that enables scrolling through child components.';
|
2016-07-26 08:00:02 +00:00
|
|
|
|
|
|
|
makeItems = (nItems: number, styles): Array<any> => {
|
2015-09-11 21:05:24 +00:00
|
|
|
var items = [];
|
|
|
|
for (var i = 0; i < nItems; i++) {
|
2018-05-11 20:32:37 +00:00
|
|
|
items[i] = (
|
|
|
|
<TouchableOpacity key={i} style={styles}>
|
|
|
|
<Text>{'Item ' + i}</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
2015-09-11 21:05:24 +00:00
|
|
|
}
|
|
|
|
return items;
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-09-11 21:05:24 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-09-11 21:05:24 +00:00
|
|
|
// One of the items is a horizontal scroll view
|
|
|
|
var items = this.makeItems(NUM_ITEMS, styles.itemWrapper);
|
|
|
|
items[4] = (
|
|
|
|
<ScrollView key={'scrollView'} horizontal={true}>
|
2018-05-11 20:32:37 +00:00
|
|
|
{this.makeItems(NUM_ITEMS, [
|
|
|
|
styles.itemWrapper,
|
|
|
|
styles.horizontalItemWrapper,
|
|
|
|
])}
|
2015-09-11 21:05:24 +00:00
|
|
|
</ScrollView>
|
|
|
|
);
|
2018-01-03 18:26:56 +00:00
|
|
|
items.push(
|
|
|
|
<ScrollView
|
|
|
|
key={'scrollViewSnap'}
|
|
|
|
horizontal
|
2018-01-09 20:07:45 +00:00
|
|
|
snapToInterval={210.0}
|
2018-05-11 20:32:37 +00:00
|
|
|
pagingEnabled>
|
2018-01-03 18:26:56 +00:00
|
|
|
{this.makeItems(NUM_ITEMS, [
|
|
|
|
styles.itemWrapper,
|
|
|
|
styles.horizontalItemWrapper,
|
|
|
|
styles.horizontalPagingItemWrapper,
|
|
|
|
])}
|
2018-05-11 20:32:37 +00:00
|
|
|
</ScrollView>,
|
2018-01-03 18:26:56 +00:00
|
|
|
);
|
2015-09-11 21:05:24 +00:00
|
|
|
|
|
|
|
var verticalScrollView = (
|
2018-05-11 20:32:37 +00:00
|
|
|
<ScrollView style={styles.verticalScrollView}>{items}</ScrollView>
|
2015-09-11 21:05:24 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return verticalScrollView;
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-09-11 21:05:24 +00:00
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
verticalScrollView: {
|
|
|
|
margin: 10,
|
|
|
|
},
|
|
|
|
itemWrapper: {
|
|
|
|
backgroundColor: '#dddddd',
|
|
|
|
alignItems: 'center',
|
|
|
|
borderRadius: 5,
|
|
|
|
borderWidth: 5,
|
|
|
|
borderColor: '#a52a2a',
|
|
|
|
padding: 30,
|
|
|
|
margin: 5,
|
|
|
|
},
|
|
|
|
horizontalItemWrapper: {
|
2018-05-11 20:32:37 +00:00
|
|
|
padding: 50,
|
2018-01-03 18:26:56 +00:00
|
|
|
},
|
|
|
|
horizontalPagingItemWrapper: {
|
|
|
|
width: 200,
|
|
|
|
},
|
2015-09-11 21:05:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = ScrollViewSimpleExample;
|