|
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 } 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 | + <Text>Model is generating. Interrupt before switching model</Text> |
| 25 | + )} |
| 26 | + </DrawerContentScrollView> |
| 27 | + ); |
| 28 | +} |
4 | 29 |
|
5 | 30 | export default function _layout() { |
| 31 | + const [isGenerating, setIsGenerating] = useState(false); |
| 32 | + |
6 | 33 | return ( |
7 | | - <Drawer |
8 | | - screenOptions={{ |
9 | | - drawerActiveTintColor: ColorPalette.primary, |
10 | | - drawerInactiveTintColor: '#888', |
11 | | - headerTintColor: ColorPalette.primary, |
12 | | - headerTitleStyle: { color: ColorPalette.primary }, |
| 34 | + <GeneratingContext |
| 35 | + value={{ |
| 36 | + setGlobalGenerating: (newState: boolean) => { |
| 37 | + setIsGenerating(newState); |
| 38 | + }, |
13 | 39 | }} |
14 | 40 | > |
15 | | - <Drawer.Screen |
16 | | - name="index" |
17 | | - options={{ |
18 | | - drawerLabel: 'Menu', |
19 | | - title: 'Main Menu', |
20 | | - headerTitleStyle: { color: ColorPalette.primary }, |
21 | | - }} |
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', |
| 41 | + <Drawer |
| 42 | + drawerContent={(props) => ( |
| 43 | + <CustomDrawerContent {...props} isGenerating={isGenerating} /> |
| 44 | + )} |
| 45 | + screenOptions={{ |
| 46 | + drawerActiveTintColor: ColorPalette.primary, |
| 47 | + drawerInactiveTintColor: '#888', |
| 48 | + headerTintColor: ColorPalette.primary, |
68 | 49 | headerTitleStyle: { color: ColorPalette.primary }, |
69 | 50 | }} |
70 | | - /> |
71 | | - </Drawer> |
| 51 | + > |
| 52 | + <Drawer.Screen |
| 53 | + name="classification/index" |
| 54 | + options={{ |
| 55 | + drawerLabel: 'Classification', |
| 56 | + title: 'Classification', |
| 57 | + headerTitleStyle: { color: ColorPalette.primary }, |
| 58 | + }} |
| 59 | + /> |
| 60 | + <Drawer.Screen |
| 61 | + name="image_segmentation/index" |
| 62 | + options={{ |
| 63 | + drawerLabel: 'Image Segmentation', |
| 64 | + title: 'Image Segmentation', |
| 65 | + headerTitleStyle: { color: ColorPalette.primary }, |
| 66 | + }} |
| 67 | + /> |
| 68 | + <Drawer.Screen |
| 69 | + name="object_detection/index" |
| 70 | + options={{ |
| 71 | + drawerLabel: 'Object Detection', |
| 72 | + title: 'Object Detection', |
| 73 | + headerTitleStyle: { color: ColorPalette.primary }, |
| 74 | + }} |
| 75 | + /> |
| 76 | + <Drawer.Screen |
| 77 | + name="ocr/index" |
| 78 | + options={{ |
| 79 | + drawerLabel: 'OCR', |
| 80 | + title: 'OCR', |
| 81 | + headerTitleStyle: { color: ColorPalette.primary }, |
| 82 | + }} |
| 83 | + /> |
| 84 | + <Drawer.Screen |
| 85 | + name="ocr_vertical/index" |
| 86 | + options={{ |
| 87 | + drawerLabel: 'OCR Vertical', |
| 88 | + title: 'Vertical OCR', |
| 89 | + headerTitleStyle: { color: ColorPalette.primary }, |
| 90 | + }} |
| 91 | + /> |
| 92 | + <Drawer.Screen |
| 93 | + name="style_transfer/index" |
| 94 | + options={{ |
| 95 | + drawerLabel: 'Style Transfer', |
| 96 | + title: 'Style Transfer', |
| 97 | + headerTitleStyle: { color: ColorPalette.primary }, |
| 98 | + }} |
| 99 | + /> |
| 100 | + <Drawer.Screen |
| 101 | + name="index" |
| 102 | + options={{ |
| 103 | + drawerLabel: () => null, |
| 104 | + drawerItemStyle: { display: 'none' }, |
| 105 | + }} |
| 106 | + /> |
| 107 | + </Drawer> |
| 108 | + </GeneratingContext> |
72 | 109 | ); |
73 | 110 | } |
0 commit comments