-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
154 lines (137 loc) · 4.24 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
146
147
148
149
150
151
152
153
154
import { SafeAreaView, ScrollView, StyleSheet } from "react-native";
import * as SplashScreen from "expo-splash-screen";
import React, { useCallback, useEffect, useState } from "react";
import {
PaperProvider,
AnimatedFAB,
Snackbar,
Appbar,
} from "react-native-paper";
import { useValtioFirestore } from "./useFirestore";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { useFirebaseAuth } from "./useFirebaseAuth";
import { Navigation } from "./Navigation";
import { TodoAccordionListIds } from "./TodoAccordionList";
import { BottomSheetModalProvider } from "@gorhom/bottom-sheet";
import { TodoCreateModal } from "./TodoCreateModal";
import { handlePresentPress } from "./TodoCreateBottomSheetUtils";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { TodoDetail } from "./TodoDetail";
import { snackbarProxy, userProxy } from "./proxies";
import { useProxy } from "valtio/utils";
import auth from "@react-native-firebase/auth";
const styles = StyleSheet.create({
container: {
flexGrow: 1,
},
fabStyle: {
bottom: 16,
right: 16,
position: "absolute",
},
});
const signOut = () => auth().signOut();
function HomeScreen() {
const [isExtended, setIsExtended] = React.useState(true);
const _ = useValtioFirestore();
const onScroll = ({ nativeEvent }) => {
const currentScrollPosition =
Math.floor(nativeEvent?.contentOffset?.y) ?? 0;
setIsExtended(currentScrollPosition <= 0);
};
return (
<>
<Appbar.Header statusBarHeight={0} mode="center-aligned">
<Appbar.Content title="Todos" />
<Appbar.Action icon="logout" onPress={signOut} />
</Appbar.Header>
<ScrollView onScroll={onScroll} style={styles.container}>
<TodoAccordionListIds />
</ScrollView>
<AnimatedFAB
icon={"plus"}
label={" New Todo"}
extended={isExtended}
onPress={() => {
// open add bottom sheet...
handlePresentPress();
}}
visible={true}
animateFrom={"right"}
iconMode={"dynamic"}
style={styles.fabStyle}
/>
<BottomSheetModalProvider>
<TodoCreateModal />
</BottomSheetModalProvider>
</>
);
}
const Stack = createNativeStackNavigator();
SplashScreen.preventAutoHideAsync();
export default function App() {
const [appIsReady, setAppIsReady] = useState(false);
const { initializing } = useFirebaseAuth();
const userState = useProxy(userProxy);
const snackbarState = useProxy(snackbarProxy);
useEffect(() => {
async function prepare() {
try {
await new Promise((resolve) => setTimeout(resolve, 0));
} catch (e) {
console.warn(e);
} finally {
setAppIsReady(true);
}
}
prepare();
}, []);
const onLayoutRootView = useCallback(async () => {
if (appIsReady) {
await SplashScreen.hideAsync();
}
}, [appIsReady]);
if (!appIsReady) {
return null;
}
return (
<>
<GestureHandlerRootView style={{ flex: 1 }}>
<NavigationContainer>
<PaperProvider>
<SafeAreaView style={{ flex: 1 }} onLayout={onLayoutRootView}>
{userState.user.uid !== null ? (
<>
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="TodoDetail" component={TodoDetail} />
</Stack.Navigator>
</>
) : (
<>
<Navigation />
</>
)}
<Snackbar
style={{ marginBottom: 80 }}
onDismiss={() => {
snackbarState.content = "";
snackbarState.isVisible = false;
}}
duration={3000}
visible={snackbarState.isVisible}
>
{snackbarState.content}
</Snackbar>
</SafeAreaView>
</PaperProvider>
</NavigationContainer>
</GestureHandlerRootView>
</>
);
}