-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathindex.tsx
100 lines (93 loc) · 3.11 KB
/
index.tsx
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
/**
* Sample React Native App for react-native-svg library
* https://github.com/software-mansion/react-native-svg/tree/main/apps/common/example
*/
'use strict';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import {createStackNavigator} from '@react-navigation/stack';
import React from 'react';
import {ActivityIndicator, Platform, View} from 'react-native';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {ListScreen} from './ListScreen';
import * as E2e from './e2e/index';
import {examples} from './examples';
import * as FilterImage from './examples/FilterImage';
import * as Filters from './examples/Filters';
import {commonStyles} from './utils/commonStyles';
import composeComponents from './utils/composeComponent';
import {
Example,
Examples,
NavigationProp,
RootStackParamList,
} from './utils/types';
import {usePersistNavigation} from './utils/usePersistNavigation';
export default function App() {
const {isReady, initialState, persistNavigationState} =
usePersistNavigation();
if (!isReady) {
return (
<View style={[commonStyles.container, commonStyles.center]}>
<ActivityIndicator />
</View>
);
}
if (process.env.E2E) {
console.log('Opening E2E example, as E2E env is set to ' + process.env.E2E);
return <E2e.component />;
}
return (
<GestureHandlerRootView style={commonStyles.container}>
<NavigationContainer
initialState={initialState}
onStateChange={persistNavigationState}>
<Stack.Navigator
screenOptions={{headerTintColor: '#f60', headerTitleAlign: 'center'}}>
<Stack.Screen name="RNSVG" component={HomeList} />
<Stack.Screen name="Filters" component={FiltersList} />
<Stack.Screen name="Filter Image" component={FilterImageList} />
{allScreensKeys.map(name => (
<Stack.Screen
key={name}
name={name}
component={composeComponents(
allScreens[name].samples,
(allScreens as Examples)[name].shouldBeRenderInView,
)}
/>
))}
<Stack.Screen name={'E2E'}>{E2e.component}</Stack.Screen>
</Stack.Navigator>
</NavigationContainer>
</GestureHandlerRootView>
);
}
type ScreenProps = {navigation: NavigationProp};
const HomeList = (props: ScreenProps) => (
<ListScreen
{...props}
examples={{
...examples,
Filters,
'Filter Image': FilterImage,
E2E: E2e as unknown as Example,
}}
/>
);
const FiltersList = (props: ScreenProps) => (
<ListScreen {...props} examples={Filters.samples} />
);
const FilterImageList = (props: ScreenProps) => (
<ListScreen {...props} examples={FilterImage.samples} />
);
const Stack =
Platform.OS === 'macos'
? createStackNavigator<RootStackParamList>()
: createNativeStackNavigator<RootStackParamList>();
const allScreens = {
...examples,
...Filters.samples,
...FilterImage.samples,
};
const allScreensKeys = Object.keys(allScreens) as (keyof typeof allScreens)[];