Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix testScrollViewExample flakiness #23541

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 11 additions & 36 deletions RNTester/js/ScrollViewExample.js
Expand Up @@ -47,7 +47,7 @@ exports.examples = [
}}
scrollEventThrottle={200}
style={styles.scrollView}>
{THUMB_URLS.map(createThumbRow)}
{ITEMS.map(createItemRow)}
</ScrollView>
<Button
label="Scroll to top"
Expand Down Expand Up @@ -91,7 +91,7 @@ exports.examples = [
automaticallyAdjustContentInsets={false}
horizontal={true}
style={[styles.scrollView, styles.horizontalScrollView]}>
{THUMB_URLS.map(createThumbRow)}
{ITEMS.map(createItemRow)}
</ScrollView>
<Button
label="Scroll to start"
Expand Down Expand Up @@ -141,7 +141,7 @@ exports.examples = [
automaticallyAdjustContentInsets={false}
style={styles.scrollView}
scrollEnabled={this.state.scrollEnabled}>
{THUMB_URLS.map(createThumbRow)}
{ITEMS.map(createItemRow)}
</ScrollView>
<Text>
{'Scrolling enabled = ' + this.state.scrollEnabled.toString()}
Expand Down Expand Up @@ -180,7 +180,7 @@ if (Platform.OS === 'ios') {
* an error found when Flow v0.85 was deployed. To see the error,
* delete this comment and run Flow. */
items: [...Array(itemCount)].map((_, ii) => (
<Thumb msg={`Item ${ii}`} />
<Item msg={`Item ${ii}`} />
)),
};
render() {
Expand Down Expand Up @@ -217,7 +217,7 @@ if (Platform.OS === 'ios') {
const idx = itemCount++;
return {
items: [
<Thumb
<Item
style={{paddingTop: idx * 5}}
msg={`Item ${idx}`}
/>,
Expand Down Expand Up @@ -253,7 +253,7 @@ if (Platform.OS === 'ios') {
onPress={() => {
this.setState(state => ({
items: state.items.concat(
<Thumb msg={`Item ${itemCount++}`} />,
<Item msg={`Item ${itemCount++}`} />,
),
}));
}}
Expand Down Expand Up @@ -291,43 +291,22 @@ if (Platform.OS === 'ios') {
});
}

class Thumb extends React.PureComponent<{|
source?: string | number,
class Item extends React.PureComponent<{|
msg?: string,
style?: ViewStyleProp,
|}> {
render() {
const {source} = this.props;
return (
<View style={[styles.thumb, this.props.style]}>
<Image
style={styles.img}
source={source == null ? THUMB_URLS[6] : source}
/>
<View style={[styles.item, this.props.style]}>
<Text>{this.props.msg}</Text>
</View>
);
}
}

let 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
let ITEMS = [...Array(12)].map((_, i) => `Item ${i}`);

const createThumbRow = (uri, i) => <Thumb key={i} source={uri} />;
const createItemRow = (msg, index) => <Item key={index} msg={msg} />;

const Button = ({label, onPress}) => (
<TouchableOpacity style={styles.button} onPress={onPress}>
Expand Down Expand Up @@ -359,15 +338,11 @@ const styles = StyleSheet.create({
flexDirection: 'row',
justifyContent: 'space-around',
},
thumb: {
item: {
margin: 5,
padding: 5,
backgroundColor: '#cccccc',
borderRadius: 3,
minWidth: 96,
},
img: {
width: 64,
height: 64,
},
});