-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy path_layout.tsx
More file actions
206 lines (197 loc) · 5.6 KB
/
_layout.tsx
File metadata and controls
206 lines (197 loc) · 5.6 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 { Drawer } from 'expo-router/drawer';
import { initExecutorch } from 'react-native-executorch';
import { ExpoResourceFetcher } from 'react-native-executorch-expo-resource-fetcher';
import ColorPalette from '../colors';
import React, { useState } from 'react';
import { Text, StyleSheet, View, TouchableOpacity } from 'react-native';
import {
DrawerContentComponentProps,
DrawerContentScrollView,
DrawerItemList,
} from '@react-navigation/drawer';
import { DrawerActions } from '@react-navigation/native';
import { useNavigation } from 'expo-router';
import Svg, { Rect } from 'react-native-svg';
import { GeneratingContext } from '../context';
initExecutorch({
resourceFetcher: ExpoResourceFetcher,
});
function HamburgerIcon({ tintColor }: { tintColor?: string }) {
const navigation = useNavigation();
return (
<TouchableOpacity
onPress={() => navigation.dispatch(DrawerActions.toggleDrawer())}
style={{ marginLeft: 12 }}
>
<Svg width={24} height={24} viewBox="0 0 24 24">
<Rect
x={2}
y={4}
width={20}
height={2}
rx={1}
fill={tintColor ?? '#000'}
/>
<Rect
x={2}
y={11}
width={20}
height={2}
rx={1}
fill={tintColor ?? '#000'}
/>
<Rect
x={2}
y={18}
width={20}
height={2}
rx={1}
fill={tintColor ?? '#000'}
/>
</Svg>
</TouchableOpacity>
);
}
interface CustomDrawerProps extends DrawerContentComponentProps {
isGenerating: boolean;
}
function CustomDrawerContent(props: CustomDrawerProps) {
const { isGenerating, ...otherProps } = props;
return (
<DrawerContentScrollView {...otherProps}>
{!isGenerating ? (
<DrawerItemList {...otherProps} />
) : (
<View style={styles.centerContent}>
<Text style={styles.mainText}>Model is generating...</Text>
<Text style={styles.subText}>Interrupt before switching model</Text>
</View>
)}
</DrawerContentScrollView>
);
}
export default function _layout() {
const [isGenerating, setIsGenerating] = useState(false);
return (
<GeneratingContext
value={{
setGlobalGenerating: (newState: boolean) => {
setIsGenerating(newState);
},
}}
>
<Drawer
drawerContent={(props) => (
<CustomDrawerContent {...props} isGenerating={isGenerating} />
)}
screenOptions={{
drawerActiveTintColor: ColorPalette.primary,
drawerInactiveTintColor: '#888',
headerTintColor: ColorPalette.primary,
headerTitleStyle: { color: ColorPalette.primary },
headerLeft: (props) => <HamburgerIcon tintColor={props.tintColor} />,
}}
>
<Drawer.Screen
name="index"
options={{
drawerLabel: () => null,
title: 'Main Menu',
drawerItemStyle: { display: 'none' },
}}
/>
<Drawer.Screen
name="vision_camera/index"
options={{
drawerLabel: 'Vision Camera',
title: 'Vision Camera',
headerShown: false,
headerTitleStyle: { color: ColorPalette.primary },
}}
/>
<Drawer.Screen
name="classification/index"
options={{
drawerLabel: 'Classification',
title: 'Classification',
headerTitleStyle: { color: ColorPalette.primary },
}}
/>
<Drawer.Screen
name="semantic_segmentation/index"
options={{
drawerLabel: 'Semantic Segmentation',
title: 'Semantic Segmentation',
headerTitleStyle: { color: ColorPalette.primary },
}}
/>
<Drawer.Screen
name="instance_segmentation/index"
options={{
drawerLabel: 'Instance Segmentation',
title: 'Instance Segmentation',
headerTitleStyle: { color: ColorPalette.primary },
}}
/>
<Drawer.Screen
name="object_detection/index"
options={{
drawerLabel: 'Object Detection',
title: 'Object Detection',
headerTitleStyle: { color: ColorPalette.primary },
}}
/>
<Drawer.Screen
name="ocr/index"
options={{
drawerLabel: 'OCR',
title: 'OCR',
headerTitleStyle: { color: ColorPalette.primary },
}}
/>
<Drawer.Screen
name="ocr_vertical/index"
options={{
drawerLabel: 'OCR Vertical',
title: 'Vertical OCR',
headerTitleStyle: { color: ColorPalette.primary },
}}
/>
<Drawer.Screen
name="style_transfer/index"
options={{
drawerLabel: 'Style Transfer',
title: 'Style Transfer',
headerTitleStyle: { color: ColorPalette.primary },
}}
/>
<Drawer.Screen
name="text_to_image/index"
options={{
drawerLabel: 'Image Generation',
title: 'Image Generation',
headerTitleStyle: { color: ColorPalette.primary },
}}
/>
</Drawer>
</GeneratingContext>
);
}
const styles = StyleSheet.create({
centerContent: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 20,
},
mainText: {
fontSize: 18,
fontWeight: 'bold',
marginBottom: 10,
color: ColorPalette.primary,
},
subText: {
fontSize: 14,
color: ColorPalette.strongPrimary,
},
});