about summary refs log tree commit diff
path: root/src/routes
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/index.tsx72
-rw-r--r--src/routes/types.ts24
2 files changed, 96 insertions, 0 deletions
diff --git a/src/routes/index.tsx b/src/routes/index.tsx
new file mode 100644
index 000000000..9ea1766f5
--- /dev/null
+++ b/src/routes/index.tsx
@@ -0,0 +1,72 @@
+import React from 'react'
+import {Text} from 'react-native'
+import {
+  NavigationContainer,
+  LinkingOptions,
+  RouteProp,
+  ParamListBase,
+} from '@react-navigation/native'
+import {createNativeStackNavigator} from '@react-navigation/native-stack'
+import {createBottomTabNavigator} from '@react-navigation/bottom-tabs'
+import type {RootStackParamList} from './types'
+import {Home} from '../screens/Home'
+import {Search} from '../screens/Search'
+import {Notifications} from '../screens/Notifications'
+import {Menu} from '../screens/Menu'
+import {Profile} from '../screens/Profile'
+import {NotFound} from '../screens/NotFound'
+
+const linking: LinkingOptions<RootStackParamList> = {
+  prefixes: [
+    'http://localhost:3000', // local dev
+  ],
+  config: {
+    screens: {
+      Primary: {
+        screens: {
+          Home: '',
+          Search: 'search',
+          Notifications: 'notifications',
+          Menu: 'menu',
+        },
+      },
+      Profile: 'profile/:name',
+      NotFound: '*',
+    },
+  },
+}
+
+export const RootStack = createNativeStackNavigator()
+export const PrimaryTab = createBottomTabNavigator()
+
+const tabBarScreenOptions = ({
+  route,
+}: {
+  route: RouteProp<ParamListBase, string>
+}) => ({
+  tabBarIcon: (_state: {focused: boolean; color: string; size: number}) => {
+    // TODO: icons
+    return <Text>{route.name.at(0)}</Text>
+  },
+})
+
+const Primary = () => (
+  <PrimaryTab.Navigator
+    screenOptions={tabBarScreenOptions}
+    initialRouteName="Home">
+    <PrimaryTab.Screen name="Home" component={Home} />
+    <PrimaryTab.Screen name="Search" component={Search} />
+    <PrimaryTab.Screen name="Notifications" component={Notifications} />
+    <PrimaryTab.Screen name="Menu" component={Menu} />
+  </PrimaryTab.Navigator>
+)
+
+export const Root = () => (
+  <NavigationContainer linking={linking} fallback={<Text>Loading...</Text>}>
+    <RootStack.Navigator initialRouteName="Primary">
+      <RootStack.Screen name="Primary" component={Primary} />
+      <RootStack.Screen name="Profile" component={Profile} />
+      <RootStack.Screen name="NotFound" component={NotFound} />
+    </RootStack.Navigator>
+  </NavigationContainer>
+)
diff --git a/src/routes/types.ts b/src/routes/types.ts
new file mode 100644
index 000000000..668dc2e2f
--- /dev/null
+++ b/src/routes/types.ts
@@ -0,0 +1,24 @@
+import type {NavigatorScreenParams} from '@react-navigation/native'
+import type {CompositeScreenProps} from '@react-navigation/native'
+import type {StackScreenProps} from '@react-navigation/stack'
+import type {BottomTabScreenProps} from '@react-navigation/bottom-tabs'
+
+export type RootStackParamList = {
+  Primary: undefined
+  Profile: {name: string}
+  NotFound: undefined
+}
+export type RootStackScreenProps<T extends keyof RootStackParamList> =
+  StackScreenProps<RootStackParamList, T>
+
+export type PrimaryTabParamList = {
+  Home: NavigatorScreenParams<RootStackParamList>
+  Search: undefined
+  Notifications: undefined
+  Menu: undefined
+}
+export type PrimaryTabScreenProps<T extends keyof PrimaryTabParamList> =
+  CompositeScreenProps<
+    BottomTabScreenProps<PrimaryTabParamList, T>,
+    RootStackScreenProps<keyof RootStackParamList>
+  >