-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
91 lines (81 loc) · 2.19 KB
/
App.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import React from 'react'
import { Text, View, FlatList, StyleSheet } from 'react-native'
import { createStackNavigator } from 'react-navigation'
import { RectButton, ScrollView } from 'react-native-gesture-handler'
import { useScreens } from 'react-native-screens'
useScreens()
import SortableFlatlist from './src/SortableFlatlist'
import SortableScrollView from './src/SortableScrollView'
import SortableFrankenView from './src/SortableFrankenView'
const SCREENS = {
SortableFlatlist: { screen: SortableFlatlist, title: 'Using Flatlist' },
SortableScrollView: { screen: SortableScrollView, title: 'Using ScrollView' },
SortableFrankenView: {
screen: SortableFrankenView,
title: 'Using FrankenView',
},
}
class MainScreen extends React.Component {
static navigationOptions = {
title: '🎬 Sortable List Examples',
}
render() {
const data = Object.keys(SCREENS).map(key => ({ key }))
return (
<FlatList
style={styles.list}
data={data}
ItemSeparatorComponent={ItemSeparator}
renderItem={props => (
<MainScreenItem
{...props}
onPressItem={({ key }) => this.props.navigation.navigate(key)}
/>
)}
renderScrollComponent={props => <ScrollView {...props} />}
/>
)
}
}
const ItemSeparator = () => <View style={styles.separator} />
class MainScreenItem extends React.Component {
_onPress = () => this.props.onPressItem(this.props.item)
render() {
const { key } = this.props.item
return (
<RectButton style={styles.button} onPress={this._onPress}>
<Text style={styles.buttonText}>{SCREENS[key].title || key}</Text>
</RectButton>
)
}
}
const ExampleApp = createStackNavigator(
{
Main: { screen: MainScreen },
...SCREENS,
},
{
initialRouteName: 'Main',
},
)
const styles = StyleSheet.create({
list: {
backgroundColor: '#EFEFF4',
},
separator: {
height: 1,
backgroundColor: '#DBDBE0',
},
buttonText: {
backgroundColor: 'transparent',
},
button: {
flex: 1,
height: 60,
padding: 10,
flexDirection: 'row',
alignItems: 'center',
backgroundColor: '#fff',
},
})
export default ExampleApp