-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathApp.tsx
More file actions
461 lines (431 loc) · 11.8 KB
/
App.tsx
File metadata and controls
461 lines (431 loc) · 11.8 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
import Constants from "expo-constants";
import * as SplashScreen from "expo-splash-screen";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import {
Animated,
View,
Text,
Image,
TouchableOpacity,
StyleSheet,
ImageSourcePropType,
} from "react-native";
import {
NavigationContainer,
useNavigation,
DrawerActions,
} from "@react-navigation/native";
import { createDrawerNavigator } from "@react-navigation/drawer";
import "react-native-gesture-handler";
import {
Provider,
DefaultTheme,
ScreenContainer,
useTheme,
createTheme,
useChangeTheme,
} from "@draftbit/ui";
import {
SafeAreaProvider,
initialWindowMetrics,
} from "react-native-safe-area-context";
import * as Font from "expo-font";
import AudioPlayerExample from "./AudioPlayerExample";
import IconExample from "./IconExample";
import ButtonExample from "./ButtonExample";
import RadioButtonExample from "./RadioButtonExample";
import DatePickerExample from "./DatePickerExample";
import LayoutExample from "./LayoutExample";
import MapViewExample from "./MapViewExample";
import MapViewDataDrivenExample from "./MapViewDataDrivenExample";
import PickerExample from "./PickerExample";
import SliderExample from "./SliderExample";
import SwitchExample from "./SwitchExample";
import StepperExample from "./StepperExample";
import TextFieldExample from "./TextFieldExample";
import TextInputExample from "./TextInputExample";
import NumberInputExample from "./NumberInputExample";
import CheckboxExample from "./CheckboxExample";
import WebViewExample from "./WebViewExample";
import AccordionExample from "./AccordionExample";
import ActionSheetExample from "./ActionSheetExample";
import StarRatingExample from "./StarRatingExample";
import SwiperExample from "./SwiperExample";
import SVGExample from "./SVGExample";
import LinearGradientExample from "./LinearGradientExample";
import SurfaceExample from "./SurfaceExample";
import ShadowExample from "./ShadowExample";
import DeckSwiperExample from "./DeckSwiperExample";
import TabViewExample from "./TabViewExample";
import MarkdownExample from "./MarkdownExample";
import BottomSheetExample from "./BottomSheetExample";
import YoutubeExample from "./YoutubeExample";
import TableExample from "./TableExample";
import SwipeableItemExample from "./SwipeableItemExample";
import SectionListExample from "./SectionListExample";
import LinearProgressExample from "./LinearProgressExample";
import CircularProgressExample from "./CircularProgressExample";
import VideoPlayerExample from "./VideoPlayerExample";
import PinInputExample from "./PinInputExample";
import KeyboardAvoidingViewExample from "./KeyboardAvoidingViewExample";
import ThemeExample from "./ThemeExample";
import LoadingIndicatorExample from "./LoadingIndicatorExample";
import SelectableTextExample from "./SelectableTextExample";
const ROUTES = {
SelectableText: SelectableTextExample,
LoadingIndicator: LoadingIndicatorExample,
Theme: ThemeExample,
AudioPlayer: AudioPlayerExample,
Layout: LayoutExample,
Icon: IconExample,
Button: ButtonExample,
RadioButton: RadioButtonExample,
ActionSheet: ActionSheetExample,
Checkbox: CheckboxExample,
Accordion: AccordionExample,
DatePicker: DatePickerExample,
LinearGradient: LinearGradientExample,
MapView: MapViewExample,
MapViewDataDriven: MapViewDataDrivenExample,
Picker: PickerExample,
Slider: SliderExample,
Switch: SwitchExample,
Stepper: StepperExample,
StarRating: StarRatingExample,
Surface: SurfaceExample,
Swiper: SwiperExample,
SVG: SVGExample,
TextField: TextFieldExample,
TextInput: TextInputExample,
NumberInput: NumberInputExample,
WebView: WebViewExample,
Shadow: ShadowExample,
DeckSwiper: DeckSwiperExample,
TabView: TabViewExample,
Markdown: MarkdownExample,
BottomSheet: BottomSheetExample,
Youtube: YoutubeExample,
Table: TableExample,
SwipeableView: SwipeableItemExample,
SectionList: SectionListExample,
LinearProgress: LinearProgressExample,
CircularProgress: CircularProgressExample,
VideoPlayer: VideoPlayerExample,
PinInput: PinInputExample,
KeyboardAvoidingView: KeyboardAvoidingViewExample,
};
let customFonts = {
"FiraCode": require("./assets/fonts/FiraCode-Bold.otf"),
"Testing": require("./assets/fonts/Sriracha-Regular.ttf"),
"Inter-SemiBoldItalic":
"https://rsms.me/inter/font-files/Inter-SemiBoldItalic.otf?v=3.12",
};
const splashImage = require("./assets/images/splash.png");
const Drawer = createDrawerNavigator();
type ExampleProps = { title: string; children: React.ReactNode };
type SplashScreenProviderProps = { image: ImageSourcePropType };
SplashScreen.preventAutoHideAsync().catch(() => {});
const themeBreakpoints = {
mobile: 0,
tablet: 480,
laptop: 992,
desktop: 1440,
bigScreen: 1920,
};
const BaseTheme = createTheme({
breakpoints: themeBreakpoints,
palettes: {},
theme: {
name: "BaseTheme",
colors: {
background: {
platformTest: {
default: "purple",
ios: "blue",
android: "green",
},
breakpointTest: {
default: "purple",
tablet: "yellow",
laptop: "red",
},
},
},
typography: {},
},
baseTheme: DefaultTheme,
});
const DarkTheme = createTheme({
breakpoints: themeBreakpoints,
palettes: {},
theme: {
name: "DarkTheme",
colors: {
background: {
brand: "#404040",
},
text: {
normal: "white",
strong: "white",
},
},
typography: {},
},
baseTheme: BaseTheme,
});
const LightTheme = createTheme({
breakpoints: themeBreakpoints,
palettes: {},
theme: {
name: "LightTheme",
colors: {},
typography: {},
},
baseTheme: BaseTheme,
});
const OtherTheme = createTheme({
breakpoints: themeBreakpoints,
palettes: {},
theme: {
name: "OtherTheme",
colors: {
branding: {
primary: "#A91D3A",
secondary: "#824D74",
},
background: {
brand: "black",
},
text: {
strong: "white",
normal: "white",
},
border: {
brand: "#FDAF7B",
},
},
typography: {},
},
baseTheme: BaseTheme,
});
export default function App() {
return (
<SplashScreenProvider image={splashImage}>
<Provider
themes={[LightTheme, DarkTheme, OtherTheme]}
breakpoints={themeBreakpoints}
initialThemeName={"LightTheme"}
>
<SafeAreaProvider initialMetrics={initialWindowMetrics}>
<Examples />
</SafeAreaProvider>
</Provider>
</SplashScreenProvider>
);
}
const SplashScreenProvider: React.FC<
React.PropsWithChildren<SplashScreenProviderProps>
> = ({ children, image }) => {
const [isSplashReady, setSplashReady] = useState(false);
useEffect(() => {
async function prepare() {
try {
await Font.loadAsync(customFonts);
} catch (e) {
console.warn(e);
} finally {
setSplashReady(true);
}
}
prepare();
}, [image]);
if (!isSplashReady) {
return null;
}
return <AnimatedSplashScreen image={image}>{children}</AnimatedSplashScreen>;
};
const AnimatedSplashScreen: React.FC<
React.PropsWithChildren<SplashScreenProviderProps>
> = ({ children, image }) => {
const animation = useMemo(() => new Animated.Value(1), []);
const [isAppReady, setAppReady] = useState(false);
const [isSplashAnimationComplete, setAnimationComplete] = useState(false);
useEffect(() => {
if (isAppReady) {
Animated.timing(animation, {
toValue: 0,
duration: 1000,
useNativeDriver: true,
}).start(() => setAnimationComplete(true));
}
}, [isAppReady, animation]);
const onImageLoaded = useCallback(async () => {
try {
await SplashScreen.hideAsync();
} catch (e) {
console.warn(e);
} finally {
setAppReady(true);
}
}, []);
return (
<View style={{ flex: 1 }}>
{isAppReady && children}
{!isSplashAnimationComplete && (
<Animated.View
pointerEvents="none"
style={[
StyleSheet.absoluteFill,
{
backgroundColor:
Constants?.expoConfig?.splash?.backgroundColor ||
"rgba(90, 69, 255, 1)",
opacity: animation,
},
]}
>
<Animated.Image
style={{
width: "100%",
height: "100%",
resizeMode:
Constants?.expoConfig?.splash?.resizeMode || "contain",
transform: [
{
scale: animation,
},
],
}}
source={image}
onLoadEnd={onImageLoaded}
fadeDuration={0}
/>
</Animated.View>
)}
</View>
);
};
function Example({ title, children }: ExampleProps) {
const navigation = useNavigation();
const theme = useTheme();
const changeTheme = useChangeTheme();
return (
<ScreenContainer
hasSafeArea={true}
hasTopSafeArea={true}
hasBottomSafeArea={true}
scrollable={false}
style={{ backgroundColor: theme.colors.background.brand }}
>
<View
style={[
exampleStyles.headerStyle,
{ backgroundColor: theme.colors.branding.primary },
]}
>
<TouchableOpacity
style={exampleStyles.menuButtonStyle}
onPress={() => navigation.dispatch(DrawerActions.toggleDrawer())}
>
<Image
style={exampleStyles.menuButtonImageStyle}
source={require("./assets/images/hamburger.png")}
/>
</TouchableOpacity>
<Text style={[exampleStyles.headerTextStyle]}>{title}</Text>
<TouchableOpacity
style={exampleStyles.menuButtonStyle}
onPress={() => {
if (theme.name === "LightTheme") {
changeTheme("DarkTheme");
} else if (theme.name === "DarkTheme") {
changeTheme("OtherTheme");
} else {
changeTheme("LightTheme");
}
}}
>
<Image
style={exampleStyles.menuButtonImageStyle}
source={require("./assets/images/theme.png")}
/>
</TouchableOpacity>
</View>
<ScreenContainer scrollable={true} hasSafeArea={false}>
{children}
</ScreenContainer>
</ScreenContainer>
);
}
function Examples() {
const theme = useTheme();
return (
<NavigationContainer>
<Drawer.Navigator
initialRouteName="Theme"
screenOptions={{
drawerActiveTintColor: theme.colors.branding.primary,
headerShown: false,
}}
>
{Object.entries(ROUTES).map(([key, Screen]) => {
return (
<Drawer.Screen key={key} name={key}>
{() => (
<Example title={key}>
<Screen theme={{}} />
</Example>
)}
</Drawer.Screen>
);
})}
</Drawer.Navigator>
</NavigationContainer>
);
}
const exampleStyles = StyleSheet.create({
mainParent: {
width: "100%",
height: "100%",
backgroundColor: "rgba(251, 252, 253, 1)",
},
headerStyle: {
flexDirection: "row",
alignItems: "center",
justifyContent: "flex-start",
height: "10%",
maxHeight: 60,
overflow: "hidden",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 3,
},
shadowOpacity: 0.29,
shadowRadius: 4.65,
elevation: 7,
},
menuButtonStyle: {
flex: 0.2,
alignItems: "center",
},
menuButtonImageStyle: {
height: 30,
width: 30,
resizeMode: "contain",
tintColor: "white",
},
headerTextStyle: {
flex: 1,
fontWeight: "bold",
color: "white",
fontSize: 20,
marginTop: 5,
marginStart: "2%",
marginBottom: 8,
paddingVertical: 4,
},
scrollViewStyle: {
paddingBottom: 20,
},
});