diff --git a/packages/rn-tester/js/examples/ScrollView/ScrollViewExample.js b/packages/rn-tester/js/examples/ScrollView/ScrollViewExample.js
index 7aa352b4228..ecb390db26e 100644
--- a/packages/rn-tester/js/examples/ScrollView/ScrollViewExample.js
+++ b/packages/rn-tester/js/examples/ScrollView/ScrollViewExample.js
@@ -15,14 +15,18 @@ const React = require('react');
const {
Platform,
ScrollView,
+ Picker,
StyleSheet,
Text,
TouchableOpacity,
View,
+ TextInput,
+ RefreshControl,
} = require('react-native');
const nullthrows = require('nullthrows');
+import {useState, useCallback} from 'react';
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';
exports.displayName = 'ScrollViewExample';
@@ -165,6 +169,98 @@ exports.examples = [
return ;
},
},
+ {
+ title: ' Content\n',
+ description: 'Adjust properties of content inside ScrollView.',
+ render: function(): React.Node {
+ return ;
+ },
+ },
+ {
+ title: ' Deceleration Rate\n',
+ description:
+ 'Determines how quickly the scroll view decelerates after the user lifts their finger.',
+ render: function(): React.Node {
+ return ;
+ },
+ },
+ {
+ title: ' Enable & Disable Scrolling Behavior\n',
+ description:
+ 'DirectionalLockEnabled (iOS), disableIntervalMomentum, disableScrollViewPanResponder can be enabled or disabled.',
+ render: function(): React.Node {
+ return ;
+ },
+ },
+ {
+ title: ' Invert Sticky Headers\n',
+ description:
+ 'If sticky headers should stick at the bottom instead of the top of the ScrollView. This is usually used with inverted ScrollViews.',
+ render: function(): React.Node {
+ return ;
+ },
+ },
+ {
+ title: ' Keyboard Options\n',
+ description:
+ 'Toggle the keyboard using the search bar and determine keyboard behavior in response to drag and tap.',
+ render: function(): React.Node {
+ return ;
+ },
+ },
+ {
+ title: ' OnContentSizeChange\n',
+ description:
+ 'The text below will change when scrollable content view of the ScrollView changes.',
+ render: function(): React.Node {
+ return ;
+ },
+ },
+ {
+ title: ' OnMomentumScroll\n',
+ description:
+ 'An alert will be called when the momentum scroll starts or ends.',
+ render: function(): React.Node {
+ return ;
+ },
+ },
+ {
+ title: ' OnScroll Options\n',
+ description:
+ 'Change the behavior of onScroll using these options: onScrollBeginDrag, onScrollEndDrag, onScrollToTop (iOS), and overScrollMode (Android).',
+ render: function(): React.Node {
+ return ;
+ },
+ },
+ {
+ title: ' RefreshControl\n',
+ description: 'Pull down to see RefreshControl indicator.',
+ render: function(): React.Node {
+ return ;
+ },
+ },
+ {
+ title: ' Remove Clipped Subviews\n',
+ description:
+ 'When true, offscreen child views (whose overflow value is hidden) are removed from their native backing superview when offscreen.',
+ render: function(): React.Node {
+ return ;
+ },
+ },
+ {
+ title: ' Scroll Indicator\n',
+ description: 'Adjust properties of the scroll indicator.',
+ render: function(): React.Node {
+ return ;
+ },
+ },
+ {
+ title: ' SnapTo Options\n',
+ description: 'Adjust properties of snapping to the scroll view.',
+ render: function(): React.Node {
+ return ;
+ },
+ },
];
if (Platform.OS === 'ios') {
exports.examples.push({
@@ -321,8 +417,712 @@ if (Platform.OS === 'ios') {
return ;
},
});
+ exports.examples.push({
+ title: ' Always Bounces\n',
+ description: 'Always bounce vertically or horizontally.',
+ render: function(): React.Node {
+ return (
+ <>
+ Vertical
+
+ Horizontal
+
+ >
+ );
+ },
+ });
+ exports.examples.push({
+ title: ' Bounces & Bounces Zoom\n',
+ description: 'There are different options for bouncing behavior.',
+ render: function(): React.Node {
+ return ;
+ },
+ });
+ exports.examples.push({
+ title: ' Indicator Style\n',
+ description: 'There are different options for indicator style colors.',
+ render: function(): React.Node {
+ return ;
+ },
+ });
+ exports.examples.push({
+ title: ' Maximum & Minimum Zoom Scale\n',
+ description: 'Set the maximum and minimum allowed zoom scale.',
+ render: function(): React.Node {
+ return ;
+ },
+ });
+ exports.examples.push({
+ title: ' Maximum & Minimum Zoom Scale\n',
+ description: 'Set the maximum and minimum allowed zoom scale.',
+ render: function(): React.Node {
+ return ;
+ },
+ });
+ exports.examples.push({
+ title: ' ScrollTo Options\n',
+ description:
+ 'Toggle scrollToOverflowEnabled and scrollsToTop. When scrollToOverflowEnabled is true, the scroll view can be programmatically scrolled beyond its content size. When scrollsToTop is true, the scroll view scrolls to top when the status bar is tapped.',
+ render: function(): React.Node {
+ return ;
+ },
+ });
+} else {
+ exports.examples.push({
+ title: ' EndFillColor & FadingEdgeLength\n',
+ description: 'Toggle to set endFillColor and fadingEdgeLength.',
+ render: function(): React.Node {
+ return ;
+ },
+ });
}
+const AndroidScrollBarOptions = () => {
+ const [persistentScrollBar, setPersistentScrollBar] = useState(false);
+ return (
+
+
+ {ITEMS.map(createItemRow)}
+
+
+ );
+};
+
+const EndFillColorFadingEdgeLen = () => {
+ const [endFillColor, setEndFillColor] = useState('');
+ const [fadingEdgeLen, setFadingEdgeLen] = useState(0);
+ return (
+
+
+ {ITEMS.map(createItemRow)}
+
+
+ );
+};
+
+const SnapToOptions = () => {
+ const [snapToAlignment, setSnapToAlignment] = useState('start');
+ const snapToAlignmentModes = ['start', 'center', 'end'];
+ const [snapToEnd, setSnapToEnd] = useState(true);
+ const [snapToInterval, setSnapToInterval] = useState(0);
+ const [snapToOffsets, setSnapToOffsets] = useState([]);
+ const [snapToStart, setSnapToStart] = useState(true);
+ return (
+
+
+ {ITEMS.map(createItemRow)}
+
+ {Platform.OS === 'ios' ? (
+ <>
+ Snap to Alignment Mode
+ {
+ if (value === 'start' || value === 'center' || value === 'end')
+ setSnapToAlignment(value);
+ }}
+ itemStyle={styles.pickerItem}>
+ {snapToAlignmentModes.map(label => {
+ return ;
+ })}
+
+ >
+ ) : null}
+ setSnapToEnd(!snapToEnd)}
+ />
+ setSnapToStart(!snapToStart)}
+ />
+
+ snapToInterval === 0 ? setSnapToInterval(2) : setSnapToInterval(0)
+ }
+ />
+
+ snapToOffsets === []
+ ? setSnapToOffsets([2, 4, 6, 8, 10])
+ : setSnapToOffsets([])
+ }
+ />
+
+ );
+};
+
+const ScrollToOptions = () => {
+ const [scrollToOverflowEnabled, setScrollToOverflowEnabled] = useState(false);
+ const [scrollsToTop, setScrollsToTop] = useState(true);
+ return (
+
+
+ {ITEMS.map(createItemRow)}
+
+ setScrollToOverflowEnabled(!scrollToOverflowEnabled)}
+ />
+ setScrollsToTop(!scrollsToTop)}
+ />
+
+ );
+};
+
+const ScrollIndicatorExample = () => {
+ const [scrollIndicatorInsets, setScrollIndicatorInsets] = useState(null);
+ const [showsHorizontalScrollIndic, setShowsHorizontalScrollIndic] = useState(
+ true,
+ );
+ const [showsVerticallScrollIndic, setShowsVerticalScrollIndic] = useState(
+ true,
+ );
+ return (
+
+
+ {ITEMS.map(createItemRow)}
+
+
+ scrollIndicatorInsets == null
+ ? setScrollIndicatorInsets({
+ top: 10,
+ left: 10,
+ bottom: 10,
+ right: 10,
+ })
+ : setScrollIndicatorInsets(null)
+ }
+ />
+
+ setShowsHorizontalScrollIndic(!showsHorizontalScrollIndic)
+ }
+ />
+ setShowsVerticalScrollIndic(!showsVerticallScrollIndic)}
+ />
+
+ );
+};
+
+const RemoveClippedSubviews = () => {
+ const [removeClippedSubviews, setRemoveClippedSubviews] = useState(false);
+ return (
+
+
+ {ITEMS.map(createItemRow)}
+
+ setRemoveClippedSubviews(!removeClippedSubviews)}
+ />
+
+ );
+};
+
+const RefreshControlExample = () => {
+ const [refreshing, setRefreshing] = useState(false);
+ const onRefresh = useCallback(() => {
+ setRefreshing(true);
+ wait(2000).then(() => setRefreshing(false));
+ }, []);
+
+ const wait = timeout => {
+ return new Promise(resolve => {
+ setTimeout(resolve, timeout);
+ });
+ };
+
+ return (
+
+
+ }
+ nestedScrollEnabled>
+ {ITEMS.map(createItemRow)}
+
+
+ );
+};
+
+const OnScrollOptions = () => {
+ const [onScrollDrag, setOnScrollDrag] = useState('none');
+ const [overScrollMode, setOverScrollMode] = useState('auto');
+ const overScrollModeOptions = ['auto', 'always', 'never'];
+ return (
+
+ onScroll: {onScrollDrag}
+ setOnScrollDrag('onScrollBeginDrag')}
+ onScrollEndDrag={() => setOnScrollDrag('onScrollEndDrag')}
+ onScrollToTop={() => setOnScrollDrag('onScrollToTop')}
+ overScrollMode={overScrollMode}
+ nestedScrollEnabled>
+ {ITEMS.map(createItemRow)}
+
+ {Platform.OS === 'android' ? (
+ <>
+ Over Scroll Mode
+ {
+ if (value === 'always' || value === 'auto' || value === 'never')
+ setOverScrollMode(value);
+ }}
+ itemStyle={styles.pickerItem}>
+ {overScrollModeOptions.map(label => {
+ return ;
+ })}
+
+ >
+ ) : null}
+
+ );
+};
+
+const OnMomentumScroll = () => {
+ const [scroll, setScroll] = useState('none');
+ return (
+
+ Scroll State: {scroll}
+ setScroll('onMomentumScrollBegin')}
+ onMomentumScrollEnd={() => setScroll('onMomentumScrollEnd')}
+ nestedScrollEnabled>
+ {ITEMS.map(createItemRow)}
+
+
+ );
+};
+
+const OnContentSizeChange = () => {
+ const [items, setItems] = useState(ITEMS);
+ const [contentSizeChanged, setContentSizeChanged] = useState('original');
+ return (
+
+ Content Size Changed: {contentSizeChanged}
+
+ contentSizeChanged === 'original'
+ ? setContentSizeChanged('changed')
+ : setContentSizeChanged('original')
+ }
+ nestedScrollEnabled>
+ {items.map(createItemRow)}
+
+
+ items === ITEMS
+ ? setItems(['1', '2', '3', '4', '5'])
+ : setItems(ITEMS)
+ }
+ />
+
+ );
+};
+
+const MaxMinZoomScale = () => {
+ const [maxZoomScale, setMaxZoomScale] = useState('1.0');
+ const [minZoomScale, setMinZoomScale] = useState('1.0');
+ const [zoomScale, setZoomScale] = useState('1.0');
+ return (
+
+
+ {ITEMS.map(createItemRow)}
+
+ Set Maximum Zoom Scale
+ setMaxZoomScale(val)}
+ keyboardType="decimal-pad"
+ />
+ Set Minimum Zoom Scale
+ setMinZoomScale(val)}
+ keyboardType="decimal-pad"
+ />
+ {Platform.OS === 'ios' ? (
+ <>
+ Set Zoom Scale
+ setZoomScale(val)}
+ keyboardType="decimal-pad"
+ />
+ >
+ ) : null}
+
+ );
+};
+
+const KeyboardExample = () => {
+ const [keyboardDismissMode, setKeyboardDismissMode] = useState('none');
+ const [keyboardShouldPersistTaps, setKeyboardShouldPersistTaps] = useState(
+ 'never',
+ );
+ const dismissOptions =
+ Platform.OS === 'ios'
+ ? ['none', 'on-drag', 'interactive']
+ : ['none', 'on-drag'];
+ const persistOptions = ['never', 'always', 'handled'];
+ return (
+
+
+ {ITEMS.map(createItemRow)}
+
+ Keyboard Dismiss Mode
+ {
+ if (
+ value === 'none' ||
+ value === 'on-drag' ||
+ value === 'interactive'
+ )
+ setKeyboardDismissMode(value);
+ }}
+ itemStyle={styles.pickerItem}>
+ {dismissOptions.map(label => {
+ return ;
+ })}
+
+ Keyboard Should Persist taps
+ {
+ if (value === 'never' || value === 'always' || value === 'handled')
+ setKeyboardShouldPersistTaps(value);
+ }}
+ itemStyle={styles.pickerItem}>
+ {persistOptions.map(label => {
+ return ;
+ })}
+
+
+ );
+};
+
+const InvertStickyHeaders = () => {
+ const [invertStickyHeaders, setInvertStickyHeaders] = useState(false);
+ return (
+
+
+ {STICKY HEADER}
+ {ITEMS.map(createItemRow)}
+
+ setInvertStickyHeaders(!invertStickyHeaders)}
+ label={'invertStickyHeaders: ' + invertStickyHeaders.toString()}
+ />
+
+ );
+};
+
+const IndicatorStyle = () => {
+ const [indicatorStyle, setIndicatorStyle] = useState('default');
+ return (
+
+
+ {ITEMS.map(createItemRow)}
+
+
+ indicatorStyle === 'default'
+ ? setIndicatorStyle('white')
+ : setIndicatorStyle('default')
+ }
+ label={'Indicator Style: ' + indicatorStyle}
+ />
+
+ );
+};
+
+const DisableEnable = () => {
+ const [directionalLockEnabled, setDirectionalLockEnabled] = useState(false);
+ const [disableIntervalMomentum, setDisableIntervalMomentum] = useState(false);
+ const [
+ disableScrollViewPanResponder,
+ setDisableScrollViewPanResponder,
+ ] = useState(false);
+ return (
+
+
+ {ITEMS.map(createItemRow)}
+
+ {Platform.OS === 'ios' ? (
+ setDirectionalLockEnabled(!directionalLockEnabled)}
+ label={'directionalLockEnabled: ' + directionalLockEnabled.toString()}
+ />
+ ) : null}
+ setDisableIntervalMomentum(!disableIntervalMomentum)}
+ label={
+ 'setDisableIntervalMomentum: ' + disableIntervalMomentum.toString()
+ }
+ />
+
+ setDisableScrollViewPanResponder(!disableScrollViewPanResponder)
+ }
+ label={
+ 'setDisableScrollViewPanResponder: ' +
+ disableScrollViewPanResponder.toString()
+ }
+ />
+
+ );
+};
+
+const DecelerationRateExample = () => {
+ const [decelRate, setDecelRate] = useState('normal');
+ return (
+
+
+ {ITEMS.map(createItemRow)}
+
+
+ decelRate === 'normal' ? setDecelRate('fast') : setDecelRate('normal')
+ }
+ label={'Deceleration Rate: ' + decelRate}
+ />
+
+ );
+};
+
+const ContentExample = () => {
+ const [canCancelContentTouches, setCanCancelContentTouches] = useState(false);
+ const [contentInset, setContentInset] = useState(null);
+ const [contentContainerStyle, setContentContainerStyle] = useState(null);
+ const [
+ contentInsetAdjustmentBehavior,
+ setContentInsetAdjustmentBehavior,
+ ] = useState('never');
+ return (
+
+
+ {ITEMS.map(createItemRow)}
+
+ {Platform.OS === 'ios' ? (
+ <>
+ setCanCancelContentTouches(!canCancelContentTouches)}
+ label={
+ 'canCancelContentTouches: ' + canCancelContentTouches.toString()
+ }
+ />
+
+ contentInsetAdjustmentBehavior === 'never'
+ ? setContentInsetAdjustmentBehavior('always')
+ : setContentInsetAdjustmentBehavior('never')
+ }
+ label={
+ contentInsetAdjustmentBehavior === 'never'
+ ? "setContentInsetAdjustmentBehavior to 'always'"
+ : 'reset content inset adjustment behavior'
+ }
+ />
+ >
+ ) : null}
+
+ contentContainerStyle === null
+ ? setContentContainerStyle(styles.containerStyle)
+ : setContentContainerStyle(null)
+ }
+ label={
+ contentContainerStyle === null
+ ? 'setContentContainerStyle'
+ : 'reset content container style'
+ }
+ />
+
+ contentInset === null
+ ? setContentInset({top: 10, bottom: 10, left: 10, right: 10})
+ : setContentInset(null)
+ }
+ label={
+ contentInset === null ? 'setContentInset' : 'reset content inset'
+ }
+ />
+
+ );
+};
+
+const BouncesExample = () => {
+ const [bounces, setBounces] = useState(false);
+ const [bouncesZoom, setBouncesZoom] = useState(false);
+ return (
+
+
+ {ITEMS.map(createItemRow)}
+
+ setBounces(!bounces)}
+ label={'Bounces: ' + bounces.toString()}
+ />
+ setBouncesZoom(!bouncesZoom)}
+ label={'Bounces Zoom: ' + bouncesZoom.toString()}
+ />
+
+ );
+};
+
+const BouncesExampleHorizontal = () => {
+ const [bounce, setBounce] = useState(false);
+ return (
+
+
+ {ITEMS.map(createItemRow)}
+
+ setBounce(!bounce)}
+ label={'Always Bounce Horizontal: ' + bounce.toString()}
+ />
+
+ );
+};
+
+const BouncesExampleVertical = () => {
+ const [bounce, setBounce] = useState(false);
+ return (
+
+
+ {ITEMS.map(createItemRow)}
+
+ setBounce(!bounce)}
+ label={'Always Bounce Vertical: ' + bounce.toString()}
+ />
+
+ );
+};
+
class Item extends React.PureComponent<{|
msg?: string,
style?: ViewStyleProp,
@@ -377,4 +1177,19 @@ const styles = StyleSheet.create({
borderRadius: 3,
minWidth: 96,
},
+ containerStyle: {
+ backgroundColor: '#aae3b6',
+ },
+ pickerItem: {
+ fontSize: 16,
+ },
+ rowTitle: {
+ flex: 1,
+ fontWeight: 'bold',
+ },
+ textInput: {
+ height: 40,
+ borderColor: 'gray',
+ borderWidth: 1,
+ },
});