Skip to content

Commit

Permalink
Add testIDs to first example in ScrollViewExample
Browse files Browse the repository at this point in the history
Summary: Changelog: Internal

Reviewed By: nadiia

Differential Revision: D26075302

fbshipit-source-id: 921700c185e9ca9c2608fa18af83b7dca2d18346
  • Loading branch information
kacieb authored and facebook-github-bot committed Jan 27, 2021
1 parent 6661517 commit 2840e8a
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions packages/rn-tester/js/examples/ScrollView/ScrollViewExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
const nullthrows = require('nullthrows');

import {useState, useCallback} from 'react';
import type {RNTesterExampleModuleItem} from '../../types/RNTesterTypes';
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';

exports.displayName = 'ScrollViewExample';
Expand All @@ -35,8 +36,9 @@ exports.documentationURL = 'https://reactnative.dev/docs/scrollview';
exports.category = 'Basic';
exports.description =
'Component that enables scrolling through child components';
exports.examples = [
exports.examples = ([
{
name: 'scrollTo',
title: '<ScrollView>\n',
description:
'To make content scrollable, wrap it within a <ScrollView> component',
Expand All @@ -53,26 +55,30 @@ exports.examples = [
console.log('onScroll!');
}}
scrollEventThrottle={200}
style={styles.scrollView}>
style={styles.scrollView}
testID="scroll_vertical">
{ITEMS.map(createItemRow)}
</ScrollView>
<Button
label="Scroll to top"
onPress={() => {
nullthrows(_scrollView).scrollTo({y: 0});
}}
testID="scroll_to_top_button"
/>
<Button
label="Scroll to bottom"
onPress={() => {
nullthrows(_scrollView).scrollToEnd({animated: true});
}}
testID="scroll_to_bottom_button"
/>
<Button
label="Flash scroll indicators"
onPress={() => {
nullthrows(_scrollView).flashScrollIndicators();
}}
testID="flash_scroll_indicators_button"
/>
</View>
);
Expand Down Expand Up @@ -261,7 +267,8 @@ exports.examples = [
return <SnapToOptions />;
},
},
];
]: Array<RNTesterExampleModuleItem>);

if (Platform.OS === 'ios') {
exports.examples.push({
title: '<ScrollView> smooth bi-directional content loading\n',
Expand Down Expand Up @@ -1140,9 +1147,16 @@ let ITEMS = [...Array(12)].map((_, i) => `Item ${i}`);

const createItemRow = (msg, index) => <Item key={index} msg={msg} />;

const Button = ({label, onPress}) => (
<TouchableOpacity style={styles.button} onPress={onPress}>
<Text>{label}</Text>
const Button = (props: {
label: string,
onPress: () => void,
testID?: string,
}) => (
<TouchableOpacity
style={styles.button}
onPress={props.onPress}
testID={props.testID}>
<Text>{props.label}</Text>
</TouchableOpacity>
);

Expand Down

0 comments on commit 2840e8a

Please sign in to comment.