about summary refs log tree commit diff
path: root/src/App.native.tsx
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2022-06-09 13:03:25 -0500
committerPaul Frazee <pfrazee@gmail.com>2022-06-09 13:03:25 -0500
commitd6942bffab68ce80d5cb26b42710dd9276f62ded (patch)
tree309f8d64f95d526d3cae6c00611c93b04f12944e /src/App.native.tsx
parent92ca49ab9a309510a5503a4df6a0ebcfba30f918 (diff)
downloadvoidsky-d6942bffab68ce80d5cb26b42710dd9276f62ded.tar.zst
Add state management
Diffstat (limited to 'src/App.native.tsx')
-rw-r--r--src/App.native.tsx80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/App.native.tsx b/src/App.native.tsx
new file mode 100644
index 000000000..40989caf0
--- /dev/null
+++ b/src/App.native.tsx
@@ -0,0 +1,80 @@
+import React, {useState, useEffect} from 'react'
+import {
+  SafeAreaView,
+  ScrollView,
+  StatusBar,
+  Text,
+  Button,
+  useColorScheme,
+  View,
+} from 'react-native'
+import {NavigationContainer} from '@react-navigation/native'
+import {
+  createNativeStackNavigator,
+  NativeStackScreenProps,
+} from '@react-navigation/native-stack'
+import {RootStore, setupState, RootStoreProvider} from './state'
+
+type RootStackParamList = {
+  Home: undefined
+  Profile: {name: string}
+}
+const Stack = createNativeStackNavigator()
+
+const HomeScreen = ({
+  navigation,
+}: NativeStackScreenProps<RootStackParamList, 'Home'>) => {
+  const isDarkMode = useColorScheme() === 'dark'
+
+  return (
+    <SafeAreaView>
+      <StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
+      <ScrollView contentInsetAdjustmentBehavior="automatic">
+        <View>
+          <Text>Native</Text>
+          <Button
+            title="Go to Jane's profile"
+            onPress={() => navigation.navigate('Profile', {name: 'Jane'})}
+          />
+        </View>
+      </ScrollView>
+    </SafeAreaView>
+  )
+}
+
+const ProfileScreen = ({
+  route,
+}: NativeStackScreenProps<RootStackParamList, 'Profile'>) => {
+  return <Text>This is {route.params.name}'s profile</Text>
+}
+
+function App() {
+  const [rootStore, setRootStore] = useState<RootStore | undefined>(undefined)
+
+  // init
+  useEffect(() => {
+    setupState().then(setRootStore)
+  }, [])
+
+  // show nothing prior to init
+  if (!rootStore) {
+    return null
+  }
+
+  return (
+    <RootStoreProvider value={rootStore}>
+      <NavigationContainer>
+        <Stack.Navigator>
+          <Stack.Screen
+            name="Home"
+            component={HomeScreen}
+            options={{title: 'Welcome'}}
+          />
+          <Stack.Screen name="Profile" component={ProfileScreen} />
+        </Stack.Navigator>
+      </NavigationContainer>
+    </RootStoreProvider>
+  )
+}
+
+export default App