mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
23c8787fe2
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52691 Unannotated array literals are unsound in Flow right now. This diff adds in annotations and makes a few things readonly, to reduce future errors. Changelog: [Internal] Reviewed By: marcoww6 Differential Revision: D78519638 fbshipit-source-id: d98a7668ecf97bcc87dcb3fad25ade736d885d9a
147 lines
3.4 KiB
JavaScript
147 lines
3.4 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
|
|
|
|
const React = require('react');
|
|
const {
|
|
ScrollView,
|
|
StyleSheet,
|
|
Text,
|
|
TouchableOpacity,
|
|
} = require('react-native');
|
|
|
|
const NUM_ITEMS = 20;
|
|
|
|
class ScrollViewSimpleExample extends React.Component<{...}> {
|
|
makeItems: (nItems: number, styles: any) => Array<any> = (
|
|
nItems: number,
|
|
styles,
|
|
): Array<any> => {
|
|
const items = [];
|
|
for (let i = 0; i < nItems; i++) {
|
|
items[i] = (
|
|
<TouchableOpacity key={i} style={styles}>
|
|
<Text testID="scroll_view_item">{'Item ' + i}</Text>
|
|
</TouchableOpacity>
|
|
);
|
|
}
|
|
return items;
|
|
};
|
|
|
|
render(): React.Node {
|
|
// One of the items is a horizontal scroll view
|
|
const items = this.makeItems(NUM_ITEMS, styles.itemWrapper);
|
|
items[4] = (
|
|
<ScrollView key={'scrollView'} horizontal={true}>
|
|
{this.makeItems(NUM_ITEMS, [
|
|
styles.itemWrapper,
|
|
styles.horizontalItemWrapper,
|
|
])}
|
|
</ScrollView>
|
|
);
|
|
items.push(
|
|
<ScrollView
|
|
key={'scrollViewSnap'}
|
|
horizontal
|
|
snapToInterval={210.0}
|
|
pagingEnabled>
|
|
{this.makeItems(NUM_ITEMS, [
|
|
styles.itemWrapper,
|
|
styles.horizontalItemWrapper,
|
|
styles.horizontalPagingItemWrapper,
|
|
])}
|
|
</ScrollView>,
|
|
);
|
|
items.push(
|
|
<ScrollView
|
|
key={'scrollViewSnapStart'}
|
|
horizontal
|
|
snapToAlignment={'start'}
|
|
pagingEnabled>
|
|
{this.makeItems(NUM_ITEMS, [
|
|
styles.itemWrapper,
|
|
styles.horizontalItemWrapper,
|
|
styles.horizontalPagingItemWrapper,
|
|
])}
|
|
</ScrollView>,
|
|
);
|
|
items.push(
|
|
<ScrollView
|
|
key={'scrollViewSnapCenter'}
|
|
horizontal
|
|
snapToAlignment={'center'}
|
|
pagingEnabled>
|
|
{this.makeItems(NUM_ITEMS, [
|
|
styles.itemWrapper,
|
|
styles.horizontalItemWrapper,
|
|
styles.horizontalPagingItemWrapper,
|
|
])}
|
|
</ScrollView>,
|
|
);
|
|
items.push(
|
|
<ScrollView
|
|
key={'scrollViewSnapEnd'}
|
|
horizontal
|
|
snapToAlignment={'end'}
|
|
pagingEnabled>
|
|
{this.makeItems(NUM_ITEMS, [
|
|
styles.itemWrapper,
|
|
styles.horizontalItemWrapper,
|
|
styles.horizontalPagingItemWrapper,
|
|
])}
|
|
</ScrollView>,
|
|
);
|
|
|
|
const verticalScrollView = (
|
|
<ScrollView style={styles.verticalScrollView}>{items}</ScrollView>
|
|
);
|
|
|
|
return verticalScrollView;
|
|
}
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
verticalScrollView: {
|
|
margin: 10,
|
|
},
|
|
itemWrapper: {
|
|
backgroundColor: '#dddddd',
|
|
alignItems: 'center',
|
|
borderRadius: 5,
|
|
borderWidth: 5,
|
|
borderColor: '#a52a2a',
|
|
padding: 30,
|
|
margin: 5,
|
|
},
|
|
horizontalItemWrapper: {
|
|
padding: 50,
|
|
},
|
|
horizontalPagingItemWrapper: {
|
|
width: 200,
|
|
},
|
|
});
|
|
|
|
exports.title = 'ScrollViewSimpleExample';
|
|
exports.category = 'Basic';
|
|
exports.description =
|
|
'Component that enables scrolling through child components.';
|
|
|
|
exports.examples = [
|
|
{
|
|
title: 'Simple scroll view',
|
|
render(): React.MixedElement {
|
|
return <ScrollViewSimpleExample />;
|
|
},
|
|
},
|
|
] as Array<RNTesterModuleExample>;
|