From df4dee6db2c9543164e4107b8420e4ed5de34911 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 9 Mar 2023 20:02:54 -0600 Subject: [PATCH] Convert all screens to react navigation --- src/lib/routes/types.ts | 27 ++ src/view/routes.ts | 9 - src/view/screens.tsx | 235 +++----------- src/view/screens/Contacts.tsx | 88 ------ src/view/screens/Debug.tsx | 6 +- src/view/screens/Home.tsx | 71 ++--- src/view/screens/Log.tsx | 22 +- src/view/screens/Notifications.tsx | 39 +-- src/view/screens/PostDownvotedBy.tsx | 27 -- src/view/screens/PostRepostedBy.tsx | 19 +- src/view/screens/PostThread.tsx | 52 ++-- src/view/screens/PostUpvotedBy.tsx | 20 +- src/view/screens/Profile.tsx | 57 ++-- src/view/screens/ProfileFollowers.tsx | 19 +- src/view/screens/ProfileFollows.tsx | 17 +- src/view/screens/Search.tsx | 30 +- src/view/screens/Search.web.tsx | 28 +- src/view/screens/Settings.tsx | 424 +++++++++++++------------- 18 files changed, 465 insertions(+), 725 deletions(-) create mode 100644 src/lib/routes/types.ts delete mode 100644 src/view/screens/Contacts.tsx delete mode 100644 src/view/screens/PostDownvotedBy.tsx diff --git a/src/lib/routes/types.ts b/src/lib/routes/types.ts new file mode 100644 index 0000000000..d0f75b0ea7 --- /dev/null +++ b/src/lib/routes/types.ts @@ -0,0 +1,27 @@ +import {NavigationState, PartialState} from '@react-navigation/native' + +export type {NativeStackScreenProps} from '@react-navigation/native-stack' + +export type CommonNavigatorParams = { + Settings: undefined + Profile: {name: string} + ProfileFollowers: {name: string} + ProfileFollows: {name: string} + PostThread: {name: string; rkey: string} + PostUpvotedBy: {name: string; rkey: string} + PostRepostedBy: {name: string; rkey: string} + Debug: undefined + Log: undefined +} +export type HomeStackNavigatorParams = CommonNavigatorParams & { + Home: undefined +} +export type NotificationsStackNavigatorParams = CommonNavigatorParams & { + Notifications: undefined +} +export type SearchStackNavigatorParams = CommonNavigatorParams & { + Search: undefined +} +export type State = + | NavigationState + | Omit, 'stale'> diff --git a/src/view/routes.ts b/src/view/routes.ts index 1cd9ef8e2e..cadf596f98 100644 --- a/src/view/routes.ts +++ b/src/view/routes.ts @@ -1,13 +1,11 @@ import React from 'react' import {IconProp} from '@fortawesome/fontawesome-svg-core' import {Home} from './screens/Home' -import {Contacts} from './screens/Contacts' import {Search} from './screens/Search' import {Notifications} from './screens/Notifications' import {NotFound} from './screens/NotFound' import {PostThread} from './screens/PostThread' import {PostUpvotedBy} from './screens/PostUpvotedBy' -import {PostDownvotedBy} from './screens/PostDownvotedBy' import {PostRepostedBy} from './screens/PostRepostedBy' import {Profile} from './screens/Profile' import {ProfileFollowers} from './screens/ProfileFollowers' @@ -33,7 +31,6 @@ export type MatchResult = { const r = (pattern: string) => new RegExp('^' + pattern + '([?]|$)', 'i') export const routes: Route[] = [ [Home, 'Home', 'house', r('/')], - [Contacts, 'Contacts', ['far', 'circle-user'], r('/contacts')], [Search, 'Search', 'magnifying-glass', r('/search')], [Notifications, 'Notifications', 'bell', r('/notifications')], [Settings, 'Settings', 'bell', r('/settings')], @@ -57,12 +54,6 @@ export const routes: Route[] = [ 'heart', r('/profile/(?[^/]+)/post/(?[^/]+)/upvoted-by'), ], - [ - PostDownvotedBy, - 'Downvoted by', - 'heart', - r('/profile/(?[^/]+)/post/(?[^/]+)/downvoted-by'), - ], [ PostRepostedBy, 'Reposted by', diff --git a/src/view/screens.tsx b/src/view/screens.tsx index 97cc093b16..00cfb95652 100644 --- a/src/view/screens.tsx +++ b/src/view/screens.tsx @@ -1,36 +1,29 @@ import * as React from 'react' -import {View, Text, Button} from 'react-native' +import {View, Text} from 'react-native' import {NavigationContainer} from '@react-navigation/native' -import { - createNativeStackNavigator, - NativeStackScreenProps, -} from '@react-navigation/native-stack' +import {createNativeStackNavigator} from '@react-navigation/native-stack' import {createDrawerNavigator} from '@react-navigation/drawer' import {createBottomTabNavigator} from '@react-navigation/bottom-tabs' -import {NavigationState, PartialState} from '@react-navigation/native' +import { + HomeStackNavigatorParams, + NotificationsStackNavigatorParams, + SearchStackNavigatorParams, + State, +} from 'lib/routes/types' -type CommonNavigatorParams = { - Settings: undefined - Profile: {name: string} - ProfileFollowers: {name: string} - ProfileFollows: {name: string} - PostThread: {name: string; rkey: string} - PostUpvotedBy: {name: string; rkey: string} - PostRepostedBy: {name: string; rkey: string} - Debug: undefined - Log: undefined -} -type HomeStackNavigatorParams = CommonNavigatorParams & { - Home: undefined -} -type NotificationsStackNavigatorParams = CommonNavigatorParams & { - Notifications: undefined -} -type SearchStackNavigatorParams = CommonNavigatorParams & { - Search: undefined -} -type State = NavigationState | Omit, 'stale'> +import {HomeScreen} from './screens/Home' +import {SearchScreen} from './screens/Search' +import {NotificationsScreen} from './screens/Notifications' +import {SettingsScreen} from './screens/Settings' +import {ProfileScreen} from './screens/Profile' +import {ProfileFollowersScreen} from './screens/ProfileFollowers' +import {ProfileFollowsScreen} from './screens/ProfileFollows' +import {PostThreadScreen} from './screens/PostThread' +import {PostUpvotedByScreen} from './screens/PostUpvotedBy' +import {PostRepostedByScreen} from './screens/PostRepostedBy' +import {DebugScreen} from './screens/Debug' +import {LogScreen} from './screens/Log' const HomeDrawer = createDrawerNavigator() const HomeStack = createNativeStackNavigator() @@ -71,8 +64,11 @@ function r(pattern: string): Route { } const ROUTES: Record = { Home: r('/'), + HomeInner: r('/'), Search: r('/search'), + SearchInner: r('/search'), Notifications: r('/notifications'), + NotificationsInner: r('/notifications'), Settings: r('/settings'), Profile: r('/profile/:name'), ProfileFollowers: r('/profile/:name/followers'), @@ -116,182 +112,31 @@ const LINKING = { } // build the state object - let container = 'HomeStack' + if (match === 'Search') { + return buildStateObject('SearchStack', 'Search', params) + } if (match === 'Notifications') { - container = 'NotificationsStack' - } else if (match === 'Search') { - container = 'SearchStack' - } - return { - routes: [ - { - name: container, - state: { - routes: [{name: match, params}], - }, - }, - ], + return buildStateObject('NotificationsStack', 'Notifications', params) } + return buildStateObject('HomeStack', match, params) }, } -function HomeScreen({ - navigation, -}: NativeStackScreenProps) { - return ( - - Home Screen -