/** * 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. * * The examples provided by Facebook are for non-commercial testing and * evaluation purposes only. * * 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. * * @flow * @providesModule ScrollViewExample */ 'use strict'; var React = require('react'); var ReactNative = require('react-native'); var { ScrollView, StyleSheet, Text, TouchableOpacity, View, Image } = ReactNative; exports.displayName = 'ScrollViewExample'; exports.title = ''; exports.description = 'Component that enables scrolling through child components'; exports.examples = [ { title: '', description: 'To make content scrollable, wrap it within a component', render: function() { var _scrollView: ScrollView; return ( { _scrollView = scrollView; }} automaticallyAdjustContentInsets={false} onScroll={() => { console.log('onScroll!'); }} scrollEventThrottle={200} style={styles.scrollView}> {THUMB_URLS.map(createThumbRow)} { _scrollView.scrollTo({y: 0}); }}> Scroll to top { _scrollView.scrollToEnd({animated: true}); }}> Scroll to bottom ); } }, { title: ' (horizontal = true)', description: 'You can display \'s child components horizontally rather than vertically', render: function() { function renderScrollView(title: string, addtionalStyles: typeof StyleSheet) { var _scrollView: ScrollView; return ( {title} { _scrollView = scrollView; }} automaticallyAdjustContentInsets={false} horizontal={true} style={[styles.scrollView, styles.horizontalScrollView]}> {THUMB_URLS.map(createThumbRow)} { _scrollView.scrollTo({x: 0}); }}> Scroll to start { _scrollView.scrollToEnd({animated: true}); }}> Scroll to end ); } return ( {renderScrollView('LTR layout', {direction: 'ltr'})} {renderScrollView('RTL layout', {direction: 'rtl'})} ); } }]; class Thumb extends React.Component { shouldComponentUpdate(nextProps, nextState) { return false; } render() { return ( ); } } var THUMB_URLS = [ require('./Thumbnails/like.png'), require('./Thumbnails/dislike.png'), require('./Thumbnails/call.png'), require('./Thumbnails/fist.png'), require('./Thumbnails/bandaged.png'), require('./Thumbnails/flowers.png'), require('./Thumbnails/heart.png'), require('./Thumbnails/liking.png'), require('./Thumbnails/party.png'), require('./Thumbnails/poke.png'), require('./Thumbnails/superlike.png'), require('./Thumbnails/victory.png'), ]; THUMB_URLS = THUMB_URLS.concat(THUMB_URLS); // double length of THUMB_URLS var createThumbRow = (uri, i) => ; var styles = StyleSheet.create({ scrollView: { backgroundColor: '#eeeeee', height: 300, }, horizontalScrollView: { height: 106, }, text: { fontSize: 16, fontWeight: 'bold', margin: 5, }, button: { margin: 5, padding: 5, alignItems: 'center', backgroundColor: '#cccccc', borderRadius: 3, }, thumb: { margin: 5, padding: 5, backgroundColor: '#cccccc', borderRadius: 3, minWidth: 96, }, img: { width: 64, height: 64, } });