|
1 | 1 | import { Drawer } from 'expo-router/drawer'; |
2 | 2 | import ColorPalette from '../colors'; |
3 | | -import React from 'react'; |
| 3 | +import React, { useState } from 'react'; |
| 4 | +import { Text, StyleSheet, View } from 'react-native'; |
| 5 | + |
| 6 | +import { |
| 7 | + DrawerContentComponentProps, |
| 8 | + DrawerContentScrollView, |
| 9 | + DrawerItemList, |
| 10 | +} from '@react-navigation/drawer'; |
| 11 | +import { GeneratingContext } from '../context'; |
| 12 | + |
| 13 | +interface CustomDrawerProps extends DrawerContentComponentProps { |
| 14 | + isGenerating: boolean; |
| 15 | +} |
| 16 | + |
| 17 | +function CustomDrawerContent(props: CustomDrawerProps) { |
| 18 | + const { isGenerating, ...otherProps } = props; |
| 19 | + return ( |
| 20 | + <DrawerContentScrollView {...otherProps}> |
| 21 | + {!isGenerating ? ( |
| 22 | + <DrawerItemList {...otherProps} /> |
| 23 | + ) : ( |
| 24 | + <View style={styles.centerContent}> |
| 25 | + <Text style={styles.mainText}>Model is generating...</Text> |
| 26 | + <Text style={styles.subText}>Interrupt before switching model</Text> |
| 27 | + </View> |
| 28 | + )} |
| 29 | + </DrawerContentScrollView> |
| 30 | + ); |
| 31 | +} |
4 | 32 |
|
5 | 33 | export default function _layout() { |
| 34 | + const [isGenerating, setIsGenerating] = useState(false); |
| 35 | + |
6 | 36 | return ( |
7 | | - <Drawer |
8 | | - screenOptions={{ |
9 | | - drawerActiveTintColor: ColorPalette.primary, |
10 | | - drawerInactiveTintColor: '#888', |
11 | | - headerTintColor: ColorPalette.primary, |
12 | | - headerTitleStyle: { color: ColorPalette.primary }, |
| 37 | + <GeneratingContext |
| 38 | + value={{ |
| 39 | + setGlobalGenerating: (newState: boolean) => { |
| 40 | + setIsGenerating(newState); |
| 41 | + }, |
13 | 42 | }} |
14 | 43 | > |
15 | | - <Drawer.Screen |
16 | | - name="index" |
17 | | - options={{ |
18 | | - drawerLabel: 'Menu', |
19 | | - title: 'Main Menu', |
| 44 | + <Drawer |
| 45 | + drawerContent={(props) => ( |
| 46 | + <CustomDrawerContent {...props} isGenerating={isGenerating} /> |
| 47 | + )} |
| 48 | + screenOptions={{ |
| 49 | + drawerActiveTintColor: ColorPalette.primary, |
| 50 | + drawerInactiveTintColor: '#888', |
| 51 | + headerTintColor: ColorPalette.primary, |
20 | 52 | headerTitleStyle: { color: ColorPalette.primary }, |
21 | 53 | }} |
22 | | - /> |
23 | | - <Drawer.Screen |
24 | | - name="classification/index" |
25 | | - options={{ |
26 | | - drawerLabel: 'Classification', |
27 | | - title: 'Classification', |
28 | | - headerTitleStyle: { color: ColorPalette.primary }, |
29 | | - }} |
30 | | - /> |
31 | | - <Drawer.Screen |
32 | | - name="image_segmentation/index" |
33 | | - options={{ |
34 | | - drawerLabel: 'Image Segmentation', |
35 | | - title: 'Image Segmentation', |
36 | | - headerTitleStyle: { color: ColorPalette.primary }, |
37 | | - }} |
38 | | - /> |
39 | | - <Drawer.Screen |
40 | | - name="object_detection/index" |
41 | | - options={{ |
42 | | - drawerLabel: 'Object Detection', |
43 | | - title: 'Object Detection', |
44 | | - headerTitleStyle: { color: ColorPalette.primary }, |
45 | | - }} |
46 | | - /> |
47 | | - <Drawer.Screen |
48 | | - name="ocr/index" |
49 | | - options={{ |
50 | | - drawerLabel: 'OCR', |
51 | | - title: 'OCR', |
52 | | - headerTitleStyle: { color: ColorPalette.primary }, |
53 | | - }} |
54 | | - /> |
55 | | - <Drawer.Screen |
56 | | - name="ocr_vertical/index" |
57 | | - options={{ |
58 | | - drawerLabel: 'OCR Vertical', |
59 | | - title: 'Vertical OCR', |
60 | | - headerTitleStyle: { color: ColorPalette.primary }, |
61 | | - }} |
62 | | - /> |
63 | | - <Drawer.Screen |
64 | | - name="style_transfer/index" |
65 | | - options={{ |
66 | | - drawerLabel: 'Style Transfer', |
67 | | - title: 'Style Transfer', |
68 | | - headerTitleStyle: { color: ColorPalette.primary }, |
69 | | - }} |
70 | | - /> |
71 | | - </Drawer> |
| 54 | + > |
| 55 | + <Drawer.Screen |
| 56 | + name="classification/index" |
| 57 | + options={{ |
| 58 | + drawerLabel: 'Classification', |
| 59 | + title: 'Classification', |
| 60 | + headerTitleStyle: { color: ColorPalette.primary }, |
| 61 | + }} |
| 62 | + /> |
| 63 | + <Drawer.Screen |
| 64 | + name="image_segmentation/index" |
| 65 | + options={{ |
| 66 | + drawerLabel: 'Image Segmentation', |
| 67 | + title: 'Image Segmentation', |
| 68 | + headerTitleStyle: { color: ColorPalette.primary }, |
| 69 | + }} |
| 70 | + /> |
| 71 | + <Drawer.Screen |
| 72 | + name="object_detection/index" |
| 73 | + options={{ |
| 74 | + drawerLabel: 'Object Detection', |
| 75 | + title: 'Object Detection', |
| 76 | + headerTitleStyle: { color: ColorPalette.primary }, |
| 77 | + }} |
| 78 | + /> |
| 79 | + <Drawer.Screen |
| 80 | + name="ocr/index" |
| 81 | + options={{ |
| 82 | + drawerLabel: 'OCR', |
| 83 | + title: 'OCR', |
| 84 | + headerTitleStyle: { color: ColorPalette.primary }, |
| 85 | + }} |
| 86 | + /> |
| 87 | + <Drawer.Screen |
| 88 | + name="ocr_vertical/index" |
| 89 | + options={{ |
| 90 | + drawerLabel: 'OCR Vertical', |
| 91 | + title: 'Vertical OCR', |
| 92 | + headerTitleStyle: { color: ColorPalette.primary }, |
| 93 | + }} |
| 94 | + /> |
| 95 | + <Drawer.Screen |
| 96 | + name="style_transfer/index" |
| 97 | + options={{ |
| 98 | + drawerLabel: 'Style Transfer', |
| 99 | + title: 'Style Transfer', |
| 100 | + headerTitleStyle: { color: ColorPalette.primary }, |
| 101 | + }} |
| 102 | + /> |
| 103 | + <Drawer.Screen |
| 104 | + name="index" |
| 105 | + options={{ |
| 106 | + drawerLabel: () => null, |
| 107 | + title: 'Main Menu', |
| 108 | + drawerItemStyle: { display: 'none' }, |
| 109 | + }} |
| 110 | + /> |
| 111 | + </Drawer> |
| 112 | + </GeneratingContext> |
72 | 113 | ); |
73 | 114 | } |
| 115 | + |
| 116 | +const styles = StyleSheet.create({ |
| 117 | + centerContent: { |
| 118 | + flex: 1, |
| 119 | + justifyContent: 'center', |
| 120 | + alignItems: 'center', |
| 121 | + padding: 20, |
| 122 | + }, |
| 123 | + mainText: { |
| 124 | + fontSize: 18, |
| 125 | + fontWeight: 'bold', |
| 126 | + marginBottom: 10, |
| 127 | + color: ColorPalette.primary, |
| 128 | + }, |
| 129 | + subText: { |
| 130 | + fontSize: 14, |
| 131 | + color: ColorPalette.strongPrimary, |
| 132 | + }, |
| 133 | +}); |
0 commit comments