-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
145 lines (137 loc) · 3.4 KB
/
App.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
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
import { ActionSheetProvider } from "@expo/react-native-action-sheet";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import { PortalHost, PortalProvider } from "@gorhom/portal";
import { Fragment, Suspense, useRef, useState } from "react";
import { Button, I18nManager, Text, View } from "react-native";
import {
DrawerLayout,
GestureHandlerRootView,
TouchableOpacity,
} from "react-native-gesture-handler";
import {
NativeRouter,
NavigateFunction,
Route,
Routes,
useNavigate,
} from "react-router-native";
import { DEVICE_WIDTH } from "./mobile/utils/constants";
import { APP_LINKS } from "./routes";
import "./styles";
export default function App() {
return (
<GestureHandlerRootView style={{ flex: 1, backgroundColor: "#cece" }}>
<ActionSheetProvider>
<PortalProvider>
<NativeRouter>
<Suspense>
<RoutesConfig />
</Suspense>
</NativeRouter>
</PortalProvider>
</ActionSheetProvider>
</GestureHandlerRootView>
);
}
function RoutesConfig() {
const navigate = useNavigate();
const drawer = useRef<DrawerLayout>(null!);
return (
<DrawerLayout
ref={drawer}
/** @see https://reactnative.dev/docs/drawerlayoutandroid.html#drawerlockmode */
drawerLockMode="locked-open"
// ios only
enableTrackpadTwoFingerGesture
// common props
minSwipeDistance={320}
userSelect="text"
edgeWidth={100}
drawerWidth={DEVICE_WIDTH * 0.5}
drawerPosition={I18nManager.isRTL ? "right" : "left"}
drawerType="slide"
drawerBackgroundColor="#b3b3b3"
onDrawerSlide={(status: any) => console.log(status)}
renderNavigationView={() => (
<Sidebar drawer={drawer} navigate={navigate} />
)}
>
<OpenDrawer drawer={drawer} />
<GlobalLogger />
<Routes>
{APP_LINKS.map((link) => {
return (
<Fragment key={link.uuid}>
<Route path={link.path} element={link.element} />
</Fragment>
);
})}
</Routes>
</DrawerLayout>
);
}
function GlobalLogger() {
const [isOpen, toggleOpen] = useState(true);
return (
<View className="flex items-center justify-center bg-purple-400">
<Button
title={isOpen ? "Close Log" : "Open Log"}
onPress={() => toggleOpen(!isOpen)}
/>
{isOpen && (
<Text className="text-xl text-slate-100">
<PortalHost name="global-btn" />
<PortalHost name="global-log" />
</Text>
)}
</View>
);
}
function Sidebar(
{ drawer, navigate }: {
drawer: React.MutableRefObject<DrawerLayout>;
navigate: NavigateFunction;
},
) {
return (
<View
style={{
flex: 1,
justifyContent: "center",
alignContent: "center",
}}
>
<CloseDrawer drawer={drawer} />
<Text style={{ textAlign: "center" }}>Links</Text>
{APP_LINKS.map((link) => {
return (
<Fragment key={link.uuid}>
<Button onPress={() => navigate(link.path)} title={link.alias} />
</Fragment>
);
})}
</View>
);
}
function OpenDrawer(
{ drawer }: { drawer: React.MutableRefObject<DrawerLayout> },
) {
return (
<View>
<TouchableOpacity onPress={() => drawer.current.openDrawer()}>
<MaterialCommunityIcons name="backburger" size={64} color="black" />
</TouchableOpacity>
</View>
);
}
function CloseDrawer(
{ drawer }: { drawer: React.MutableRefObject<DrawerLayout> },
) {
return (
<View>
<TouchableOpacity onPress={() => drawer.current.closeDrawer()}>
<MaterialCommunityIcons name="backburger" size={64} color="black" />
</TouchableOpacity>
</View>
);
}