2015-09-11 21:05:24 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-07-12 12:51:57 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
2015-09-11 21:05:24 +00:00
|
|
|
* @flow
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule ScrollViewSimpleExample
|
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');
|
2015-09-11 21:05:24 +00:00
|
|
|
var {
|
|
|
|
ScrollView,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TouchableOpacity
|
2016-04-09 03:36:40 +00:00
|
|
|
} = 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>';
|
|
|
|
static description = 'Component that enables scrolling through child components.';
|
|
|
|
|
|
|
|
makeItems = (nItems: number, styles): Array<any> => {
|
2015-09-11 21:05:24 +00:00
|
|
|
var items = [];
|
|
|
|
for (var i = 0; i < nItems; i++) {
|
|
|
|
items[i] = (
|
|
|
|
<TouchableOpacity key={i} style={styles}>
|
|
|
|
<Text>{'Item ' + i}</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
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}>
|
|
|
|
{this.makeItems(NUM_ITEMS, [styles.itemWrapper, styles.horizontalItemWrapper])}
|
|
|
|
</ScrollView>
|
|
|
|
);
|
|
|
|
|
|
|
|
var verticalScrollView = (
|
|
|
|
<ScrollView style={styles.verticalScrollView}>
|
|
|
|
{items}
|
|
|
|
</ScrollView>
|
|
|
|
);
|
|
|
|
|
|
|
|
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: {
|
|
|
|
padding: 50
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = ScrollViewSimpleExample;
|