2015-01-30 01:10:49 +00:00
|
|
|
/**
|
2016-07-12 12:51:57 +00:00
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
|
|
* 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-03-26 18:24:15 +00:00
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
2015-03-23 22:07:33 +00:00
|
|
|
*
|
2015-03-26 18:24:15 +00:00
|
|
|
* Facebook reserves all rights not expressly granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2015-03-23 22:07:33 +00:00
|
|
|
*
|
|
|
|
* @flow
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2015-01-30 01:10:49 +00:00
|
|
|
var {
|
|
|
|
ScrollView,
|
|
|
|
StyleSheet,
|
2016-02-03 11:59:20 +00:00
|
|
|
Text,
|
|
|
|
TouchableOpacity,
|
2015-01-30 01:10:49 +00:00
|
|
|
View,
|
|
|
|
Image
|
2016-04-09 03:36:40 +00:00
|
|
|
} = ReactNative;
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-06-22 16:43:30 +00:00
|
|
|
exports.displayName = (undefined: ?string);
|
2015-01-30 01:10:49 +00:00
|
|
|
exports.title = '<ScrollView>';
|
|
|
|
exports.description = 'Component that enables scrolling through child components';
|
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: '<ScrollView>',
|
|
|
|
description: 'To make content scrollable, wrap it within a <ScrollView> component',
|
|
|
|
render: function() {
|
2016-02-03 11:59:20 +00:00
|
|
|
var _scrollView: ScrollView;
|
2015-02-12 02:26:03 +00:00
|
|
|
return (
|
2016-02-03 11:59:20 +00:00
|
|
|
<View>
|
|
|
|
<ScrollView
|
|
|
|
ref={(scrollView) => { _scrollView = scrollView; }}
|
|
|
|
automaticallyAdjustContentInsets={false}
|
|
|
|
onScroll={() => { console.log('onScroll!'); }}
|
|
|
|
scrollEventThrottle={200}
|
|
|
|
style={styles.scrollView}>
|
|
|
|
{THUMBS.map(createThumbRow)}
|
|
|
|
</ScrollView>
|
|
|
|
<TouchableOpacity
|
|
|
|
style={styles.button}
|
|
|
|
onPress={() => { _scrollView.scrollTo({y: 0}); }}>
|
|
|
|
<Text>Scroll to top</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
2015-02-12 02:26:03 +00:00
|
|
|
);
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
title: '<ScrollView> (horizontal = true)',
|
|
|
|
description: 'You can display <ScrollView>\'s child components horizontally rather than vertically',
|
|
|
|
render: function() {
|
2016-02-03 11:59:20 +00:00
|
|
|
var _scrollView: ScrollView;
|
2015-02-12 02:26:03 +00:00
|
|
|
return (
|
2016-02-03 11:59:20 +00:00
|
|
|
<View>
|
|
|
|
<ScrollView
|
|
|
|
ref={(scrollView) => { _scrollView = scrollView; }}
|
|
|
|
automaticallyAdjustContentInsets={false}
|
|
|
|
horizontal={true}
|
|
|
|
style={[styles.scrollView, styles.horizontalScrollView]}>
|
|
|
|
{THUMBS.map(createThumbRow)}
|
|
|
|
</ScrollView>
|
|
|
|
<TouchableOpacity
|
|
|
|
style={styles.button}
|
|
|
|
onPress={() => { _scrollView.scrollTo({x: 0}); }}>
|
|
|
|
<Text>Scroll to start</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
2015-02-12 02:26:03 +00:00
|
|
|
);
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class Thumb extends React.Component {
|
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
2015-01-30 01:10:49 +00:00
|
|
|
return false;
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2015-01-30 01:10:49 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Image style={styles.img} source={{uri:this.props.uri}} />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
var THUMBS = ['https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-ash3/t39.1997/p128x128/851549_767334479959628_274486868_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851561_767334496626293_1958532586_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-ash3/t39.1997/p128x128/851579_767334503292959_179092627_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851589_767334513292958_1747022277_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851563_767334559959620_1193692107_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851593_767334566626286_1953955109_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851591_767334523292957_797560749_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851567_767334529959623_843148472_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851548_767334489959627_794462220_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851575_767334539959622_441598241_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-ash3/t39.1997/p128x128/851573_767334549959621_534583464_n.png', 'https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/t39.1997/p128x128/851583_767334573292952_1519550680_n.png'];
|
|
|
|
THUMBS = THUMBS.concat(THUMBS); // double length of THUMBS
|
2015-02-08 01:23:25 +00:00
|
|
|
var createThumbRow = (uri, i) => <Thumb key={i} uri={uri} />;
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
scrollView: {
|
|
|
|
backgroundColor: '#6A85B1',
|
|
|
|
height: 300,
|
|
|
|
},
|
|
|
|
horizontalScrollView: {
|
|
|
|
height: 120,
|
|
|
|
},
|
|
|
|
containerPage: {
|
|
|
|
height: 50,
|
|
|
|
width: 50,
|
|
|
|
backgroundColor: '#527FE4',
|
|
|
|
padding: 5,
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
fontSize: 20,
|
|
|
|
color: '#888888',
|
|
|
|
left: 80,
|
|
|
|
top: 20,
|
|
|
|
height: 40,
|
|
|
|
},
|
|
|
|
button: {
|
|
|
|
margin: 7,
|
|
|
|
padding: 5,
|
|
|
|
alignItems: 'center',
|
|
|
|
backgroundColor: '#eaeaea',
|
|
|
|
borderRadius: 3,
|
|
|
|
},
|
|
|
|
buttonContents: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
width: 64,
|
|
|
|
height: 64,
|
|
|
|
},
|
|
|
|
img: {
|
|
|
|
width: 64,
|
|
|
|
height: 64,
|
|
|
|
}
|
|
|
|
});
|