-
Notifications
You must be signed in to change notification settings - Fork 218
Expand file tree
/
Copy pathApp.tsx
More file actions
206 lines (196 loc) · 5.58 KB
/
App.tsx
File metadata and controls
206 lines (196 loc) · 5.58 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import { Ionicons } from '@expo/vector-icons'
import Constants from 'expo-constants'
import * as React from 'react'
import {
Platform,
ScrollView,
StatusBar,
SafeAreaView,
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native'
import AndroidSharedPullToRefresh from './AndroidSharedPullToRefresh'
import AnimatedHeader from './AnimatedHeader'
import CenteredEmptyList from './CenteredEmptyList'
import Default from './Default'
import DynamicTabs from './DynamicTabs'
import HeaderOverscrollExample from './HeaderOverscroll'
import Lazy from './Lazy'
import MinHeaderHeight from './MinHeaderHeight'
import OnTabChange from './OnTabChange'
import QuickStartDemo from './QuickStartDemo'
import Ref from './Ref'
import RevealHeaderOnScroll from './RevealHeaderOnScroll'
import RevealHeaderOnScrollSnap from './RevealHeaderOnScrollSnap'
import ScrollOnHeader from './ScrollOnHeader'
import ScrollableTabs from './ScrollableTabs'
import Snap from './Snap'
import StartOnSpecificTab from './StartOnSpecificTab'
import StretchableHeader from './StretchableHeader'
import UndefinedHeaderHeight from './UndefinedHeaderHeight'
import { ExampleComponentType } from './types'
const EXAMPLE_COMPONENTS: ExampleComponentType[] = [
Default,
Snap,
RevealHeaderOnScroll,
RevealHeaderOnScrollSnap,
Lazy,
ScrollableTabs,
CenteredEmptyList,
ScrollOnHeader,
QuickStartDemo,
UndefinedHeaderHeight,
StartOnSpecificTab,
Ref,
OnTabChange,
DynamicTabs,
MinHeaderHeight,
AnimatedHeader,
StretchableHeader,
AndroidSharedPullToRefresh,
HeaderOverscrollExample,
]
const ExampleList: React.FC<object> = () => {
const [index, setIndex] = React.useState(-1)
const [title] = React.useState('Examples')
const handleNavigate = React.useCallback((index: number) => {
setIndex(index)
}, [])
const handleNavigateBack = React.useCallback(() => {
handleNavigate(-1)
}, [handleNavigate])
const renderItem = React.useCallback(
(component: ExampleComponentType, i: number) => {
const enabled = !component.platform || component.platform === Platform.OS
return (
<TouchableOpacity
key={i}
style={styles.touchable}
onPress={enabled ? () => handleNavigate(i) : undefined}
>
<Text style={[styles.item, !enabled && styles.disabled]}>
{i + 1}. {component.title}
</Text>
</TouchableOpacity>
)
},
[handleNavigate]
)
const ExampleComponent = EXAMPLE_COMPONENTS[index] || null
const backgroundColor = ExampleComponent?.backgroundColor
? ExampleComponent.backgroundColor
: '#111'
const tintColor =
ExampleComponent && typeof ExampleComponent.tintColor === 'string'
? ExampleComponent.tintColor
: 'white'
const appbarElevation =
ExampleComponent && typeof ExampleComponent.appbarElevation === 'number'
? ExampleComponent.appbarElevation
: 4
const statusBarStyle =
ExampleComponent && typeof ExampleComponent.statusBarStyle === 'string'
? ExampleComponent.statusBarStyle
: 'light-content'
const borderBottomWidth = Platform.OS === 'ios' ? StyleSheet.hairlineWidth : 0
return (
<View style={styles.container}>
<StatusBar
translucent
barStyle={Platform.OS === 'ios' ? statusBarStyle : 'light-content'}
/>
<View
style={[
styles.appbar,
backgroundColor ? { backgroundColor } : null,
appbarElevation
? { elevation: appbarElevation, borderBottomWidth }
: null,
]}
>
<View style={styles.statusbar} />
<SafeAreaView>
<View style={styles.content}>
{index > -1 ? (
<TouchableOpacity
style={styles.button}
onPress={handleNavigateBack}
>
<Ionicons
name={
Platform.OS === 'android'
? 'md-arrow-back'
: 'ios-arrow-back'
}
size={24}
color={tintColor}
/>
</TouchableOpacity>
) : null}
<Text
style={[styles.title, tintColor ? { color: tintColor } : null]}
>
{index > -1 ? EXAMPLE_COMPONENTS[index].title : title}
</Text>
{index > -1 ? <View style={styles.button} /> : null}
</View>
</SafeAreaView>
</View>
{index === -1 ? (
<ScrollView>{EXAMPLE_COMPONENTS.map(renderItem)}</ScrollView>
) : ExampleComponent ? (
<ExampleComponent />
) : null}
</View>
)
}
const styles = StyleSheet.create({
container: {
backgroundColor: '#eceff1',
height: Platform.OS === 'web' ? '100vh' : '100%',
},
statusbar: {
height: Platform.select({
android: Constants.statusBarHeight,
ios: Platform.Version < 11 ? Constants.statusBarHeight : 0,
}),
},
appbar: {
borderBottomColor: 'rgba(0, 0, 0, 0.1)',
zIndex: 1,
},
content: {
flexDirection: 'row',
alignItems: 'center',
height: 56,
},
title: {
flex: 1,
textAlign: Platform.OS === 'ios' ? 'center' : 'left',
fontSize: Platform.OS === 'ios' ? 17 : 18,
color: '#fff',
margin: 16,
},
button: {
flexDirection: 'row',
alignItems: 'center',
width: 56,
padding: 16,
},
touchable: {
padding: 16,
backgroundColor: '#fff',
borderBottomWidth: 1,
borderBottomColor: 'rgba(0, 0, 0, .06)',
},
item: {
fontSize: 16,
color: '#333',
},
disabled: {
color: '#dddddd',
},
})
export { ExampleList as App }