-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathmain.js
72 lines (62 loc) · 1.52 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// @noflow
import Expo from 'expo';
import React, { Component, PureComponent } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import MasonryList from '@appandflow/masonry-list';
const COLORS = ['green', 'blue', 'red'];
const DATA = Array.from({ length: 50000 }).map((_, i) => ({
id: `item_${i}`,
height: Math.round(Math.random() * 100 + 50),
color: COLORS[i % COLORS.length],
}));
class Cell extends PureComponent {
componentDidMount() {
console.warn('mount cell');
}
componentWillUnmount() {
console.warn('unmount cell');
}
render() {
const { item } = this.props;
return (
<View
style={[
styles.cell,
{ height: item.height, backgroundColor: item.color },
]}
>
<Text>{item.id}</Text>
</View>
);
}
}
class App extends Component {
state = { isRefreshing: false };
_refreshRequest = () => {
this.setState({ isRefreshing: true });
setTimeout(() => {
this.setState({ isRefreshing: false });
}, 1000);
};
render() {
return (
<MasonryList
onRefresh={this._refreshRequest}
refreshing={this.state.isRefreshing}
data={DATA}
renderItem={({ item }) => <Cell item={item} />}
getHeightForItem={({ item }) => item.height + 2}
numColumns={2}
keyExtractor={item => item.id}
/>
);
}
}
const styles = StyleSheet.create({
cell: {
margin: 1,
alignItems: 'center',
justifyContent: 'center',
},
});
Expo.registerRootComponent(App);