diff --git a/src/lib/notifee.ts b/src/lib/notifee.ts index f40e3da706..02b647694b 100644 --- a/src/lib/notifee.ts +++ b/src/lib/notifee.ts @@ -1,9 +1,10 @@ import notifee, {EventType} from '@notifee/react-native' +import {StackActions} from '@react-navigation/native' import {AppBskyEmbedImages} from '@atproto/api' import {RootStoreModel} from 'state/models/root-store' -import {TabPurpose} from 'state/models/navigation' import {NotificationsViewItemModel} from 'state/models/notifications-view' import {enforceLen} from 'lib/strings/helpers' +import {navigation} from '../Routes' export function init(store: RootStoreModel) { store.onUnreadNotifications(count => notifee.setBadgeCount(count)) @@ -16,8 +17,8 @@ export function init(store: RootStoreModel) { store.log.debug('Notifee foreground event', {type}) if (type === EventType.PRESS) { store.log.debug('User pressed a notifee, opening notifications') - // TODO - // store.nav.switchTo(TabPurpose.Notifs, true) + navigation.navigate('NotificationsTab') + navigation.dispatch(StackActions.popToTop()) } }) notifee.onBackgroundEvent(async _e => {}) // notifee requires this but we handle it with onForegroundEvent diff --git a/src/lib/routes/types.ts b/src/lib/routes/types.ts index 89a23cb3c0..e5b62d8731 100644 --- a/src/lib/routes/types.ts +++ b/src/lib/routes/types.ts @@ -40,6 +40,15 @@ export type NotificationsDrawerNavigatorParams = { NotificationsInner: undefined } +export type AllNavigatorParams = CommonNavigatorParams & { + HomeTab: undefined + Home: undefined + SeachTab: undefined + Search: undefined + NotificationsTab: undefined + Notifications: undefined +} + // NOTE // this isn't strictly correct but it should be close enough // a TS wizard might be able to get this 100% diff --git a/src/routes.tsx b/src/routes.tsx index c5fe80d355..196d2b2643 100644 --- a/src/routes.tsx +++ b/src/routes.tsx @@ -1,5 +1,8 @@ import * as React from 'react' -import {NavigationContainer} from '@react-navigation/native' +import { + NavigationContainer, + createNavigationContainerRef, +} from '@react-navigation/native' import {createNativeStackNavigator} from '@react-navigation/native-stack' import {createDrawerNavigator} from '@react-navigation/drawer' import {createBottomTabNavigator} from '@react-navigation/bottom-tabs' @@ -11,6 +14,7 @@ import { SearchDrawerNavigatorParams, NotificationsTabNavigatorParams, NotificationsDrawerNavigatorParams, + AllNavigatorParams, State, } from 'lib/routes/types' @@ -31,6 +35,8 @@ import {PostRepostedByScreen} from './view/screens/PostRepostedBy' import {DebugScreen} from './view/screens/Debug' import {LogScreen} from './view/screens/Log' +const navigationRef = createNavigationContainerRef() + const HomeDrawer = createDrawerNavigator() const HomeTab = createNativeStackNavigator() const SearchDrawer = createDrawerNavigator() @@ -87,7 +93,7 @@ const ROUTES: Record = { Log: r('/sys/log'), } -export function matchPath(path: string): {name: string; params: RouteParams} { +function matchPath(path: string): {name: string; params: RouteParams} { let name = 'NotFound' let params: RouteParams = {} for (const [screenName, matcher] of Object.entries(ROUTES)) { @@ -101,7 +107,7 @@ export function matchPath(path: string): {name: string; params: RouteParams} { return {name, params} } -export const LINKING = { +const LINKING = { prefixes: ['bsky://', 'https://bsky.app'], getPathFromState(state: State) { @@ -245,7 +251,7 @@ function NotificationsTabNavigator() { ) } -export function TabsNavigator() { +function TabsNavigator() { const tabBar = React.useCallback(props => , []) return ( ) { - return {children} +function RoutesContainer({children}: React.PropsWithChildren<{}>) { + return ( + + {children} + + ) } + +export {navigationRef as navigation, matchPath, TabsNavigator, RoutesContainer}