|
| 1 | +import { Drawer } from 'expo-router/drawer'; |
| 2 | +import ColorPalette from '../colors'; |
| 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 | +} |
| 32 | + |
| 33 | +export default function _layout() { |
| 34 | + const [isGenerating, setIsGenerating] = useState(false); |
| 35 | + |
| 36 | + return ( |
| 37 | + <GeneratingContext |
| 38 | + value={{ |
| 39 | + setGlobalGenerating: (newState: boolean) => { |
| 40 | + setIsGenerating(newState); |
| 41 | + }, |
| 42 | + }} |
| 43 | + > |
| 44 | + <Drawer |
| 45 | + drawerContent={(props) => ( |
| 46 | + <CustomDrawerContent {...props} isGenerating={isGenerating} /> |
| 47 | + )} |
| 48 | + screenOptions={{ |
| 49 | + drawerActiveTintColor: ColorPalette.primary, |
| 50 | + drawerInactiveTintColor: '#888', |
| 51 | + headerTintColor: ColorPalette.primary, |
| 52 | + headerTitleStyle: { color: ColorPalette.primary }, |
| 53 | + }} |
| 54 | + > |
| 55 | + <Drawer.Screen |
| 56 | + name="text-embeddings/index" |
| 57 | + options={{ |
| 58 | + drawerLabel: 'Text embeddings', |
| 59 | + title: 'Text embeddings', |
| 60 | + headerTitleStyle: { color: ColorPalette.primary }, |
| 61 | + }} |
| 62 | + /> |
| 63 | + <Drawer.Screen |
| 64 | + name="clip-embeddings/index" |
| 65 | + options={{ |
| 66 | + drawerLabel: 'CLIP embeddings', |
| 67 | + title: 'CLIP embeddings', |
| 68 | + headerTitleStyle: { color: ColorPalette.primary }, |
| 69 | + }} |
| 70 | + /> |
| 71 | + <Drawer.Screen |
| 72 | + name="index" |
| 73 | + options={{ |
| 74 | + drawerLabel: () => null, |
| 75 | + title: 'Main Menu', |
| 76 | + drawerItemStyle: { display: 'none' }, |
| 77 | + }} |
| 78 | + /> |
| 79 | + </Drawer> |
| 80 | + </GeneratingContext> |
| 81 | + ); |
| 82 | +} |
| 83 | + |
| 84 | +const styles = StyleSheet.create({ |
| 85 | + centerContent: { |
| 86 | + flex: 1, |
| 87 | + justifyContent: 'center', |
| 88 | + alignItems: 'center', |
| 89 | + padding: 20, |
| 90 | + }, |
| 91 | + mainText: { |
| 92 | + fontSize: 18, |
| 93 | + fontWeight: 'bold', |
| 94 | + marginBottom: 10, |
| 95 | + color: ColorPalette.primary, |
| 96 | + }, |
| 97 | + subText: { |
| 98 | + fontSize: 14, |
| 99 | + color: ColorPalette.strongPrimary, |
| 100 | + }, |
| 101 | +}); |
0 commit comments