From b815eb59bef7bed9825027adc676b8d09db463c6 Mon Sep 17 00:00:00 2001 From: Spencer Ahrens Date: Fri, 12 Jan 2018 19:07:17 -0800 Subject: [PATCH] Prettier ScrollViewExample Reviewed By: TheSavior, shergin Differential Revision: D6712726 fbshipit-source-id: 30d8bcdcf6a1cbf1c05048462c7b8444b4ea5ede --- RNTester/js/ScrollViewExample.js | 148 ++++++++++++++++++------------- 1 file changed, 87 insertions(+), 61 deletions(-) diff --git a/RNTester/js/ScrollViewExample.js b/RNTester/js/ScrollViewExample.js index 87eee3fbb..0074ea91c 100644 --- a/RNTester/js/ScrollViewExample.js +++ b/RNTester/js/ScrollViewExample.js @@ -8,6 +8,7 @@ * * @flow * @providesModule ScrollViewExample + * @format */ 'use strict'; @@ -20,90 +21,115 @@ var { Text, TouchableOpacity, View, - Image + Image, } = ReactNative; exports.displayName = 'ScrollViewExample'; exports.title = ''; -exports.description = 'Component that enables scrolling through child components'; +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 - - { _scrollView.flashScrollIndicators(); }}> - Flash scroll indicators - - - ); - } -}, { - title: ' (horizontal = true)', - description: 'You can display \'s child components horizontally rather than vertically', - render: function() { - - function renderScrollView(title: string, addtionalStyles: typeof StyleSheet) { + { + title: '', + description: + 'To make content scrollable, wrap it within a component', + render: function() { var _scrollView: ScrollView; return ( - - {title} + { _scrollView = scrollView; }} + ref={scrollView => { + _scrollView = scrollView; + }} automaticallyAdjustContentInsets={false} - horizontal={true} - style={[styles.scrollView, styles.horizontalScrollView]}> + onScroll={() => { + console.log('onScroll!'); + }} + scrollEventThrottle={200} + style={styles.scrollView}> {THUMB_URLS.map(createThumbRow)} { _scrollView.scrollTo({x: 0}); }}> - Scroll to start + onPress={() => { + _scrollView.scrollTo({y: 0}); + }}> + Scroll to top { _scrollView.scrollToEnd({animated: true}); }}> - Scroll to end + onPress={() => { + _scrollView.scrollToEnd({animated: true}); + }}> + Scroll to bottom { _scrollView.flashScrollIndicators(); }}> + onPress={() => { + _scrollView.flashScrollIndicators(); + }}> Flash scroll indicators ); - } + }, + }, + { + 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 + + { + _scrollView.flashScrollIndicators(); + }}> + Flash scroll indicators + + + ); + } - return ( - - {renderScrollView('LTR layout', {direction: 'ltr'})} - {renderScrollView('RTL layout', {direction: 'rtl'})} - - ); - } -}]; + return ( + + {renderScrollView('LTR layout', {direction: 'ltr'})} + {renderScrollView('RTL layout', {direction: 'rtl'})} + + ); + }, + }, +]; class Thumb extends React.Component<$FlowFixMeProps, $FlowFixMeState> { shouldComponentUpdate(nextProps, nextState) { @@ -168,5 +194,5 @@ var styles = StyleSheet.create({ img: { width: 64, height: 64, - } + }, });