Handle notifee card presses

This commit is contained in:
Paul Frazee
2023-03-10 15:08:29 -06:00
parent 3df953b73d
commit 330a1a0be4
3 changed files with 31 additions and 9 deletions
+4 -3
View File
@@ -1,9 +1,10 @@
import notifee, {EventType} from '@notifee/react-native' import notifee, {EventType} from '@notifee/react-native'
import {StackActions} from '@react-navigation/native'
import {AppBskyEmbedImages} from '@atproto/api' import {AppBskyEmbedImages} from '@atproto/api'
import {RootStoreModel} from 'state/models/root-store' import {RootStoreModel} from 'state/models/root-store'
import {TabPurpose} from 'state/models/navigation'
import {NotificationsViewItemModel} from 'state/models/notifications-view' import {NotificationsViewItemModel} from 'state/models/notifications-view'
import {enforceLen} from 'lib/strings/helpers' import {enforceLen} from 'lib/strings/helpers'
import {navigation} from '../Routes'
export function init(store: RootStoreModel) { export function init(store: RootStoreModel) {
store.onUnreadNotifications(count => notifee.setBadgeCount(count)) store.onUnreadNotifications(count => notifee.setBadgeCount(count))
@@ -16,8 +17,8 @@ export function init(store: RootStoreModel) {
store.log.debug('Notifee foreground event', {type}) store.log.debug('Notifee foreground event', {type})
if (type === EventType.PRESS) { if (type === EventType.PRESS) {
store.log.debug('User pressed a notifee, opening notifications') store.log.debug('User pressed a notifee, opening notifications')
// TODO navigation.navigate('NotificationsTab')
// store.nav.switchTo(TabPurpose.Notifs, true) navigation.dispatch(StackActions.popToTop())
} }
}) })
notifee.onBackgroundEvent(async _e => {}) // notifee requires this but we handle it with onForegroundEvent notifee.onBackgroundEvent(async _e => {}) // notifee requires this but we handle it with onForegroundEvent
+9
View File
@@ -40,6 +40,15 @@ export type NotificationsDrawerNavigatorParams = {
NotificationsInner: undefined NotificationsInner: undefined
} }
export type AllNavigatorParams = CommonNavigatorParams & {
HomeTab: undefined
Home: undefined
SeachTab: undefined
Search: undefined
NotificationsTab: undefined
Notifications: undefined
}
// NOTE // NOTE
// this isn't strictly correct but it should be close enough // this isn't strictly correct but it should be close enough
// a TS wizard might be able to get this 100% // a TS wizard might be able to get this 100%
+18 -6
View File
@@ -1,5 +1,8 @@
import * as React from 'react' 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 {createNativeStackNavigator} from '@react-navigation/native-stack'
import {createDrawerNavigator} from '@react-navigation/drawer' import {createDrawerNavigator} from '@react-navigation/drawer'
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs' import {createBottomTabNavigator} from '@react-navigation/bottom-tabs'
@@ -11,6 +14,7 @@ import {
SearchDrawerNavigatorParams, SearchDrawerNavigatorParams,
NotificationsTabNavigatorParams, NotificationsTabNavigatorParams,
NotificationsDrawerNavigatorParams, NotificationsDrawerNavigatorParams,
AllNavigatorParams,
State, State,
} from 'lib/routes/types' } from 'lib/routes/types'
@@ -31,6 +35,8 @@ import {PostRepostedByScreen} from './view/screens/PostRepostedBy'
import {DebugScreen} from './view/screens/Debug' import {DebugScreen} from './view/screens/Debug'
import {LogScreen} from './view/screens/Log' import {LogScreen} from './view/screens/Log'
const navigationRef = createNavigationContainerRef<AllNavigatorParams>()
const HomeDrawer = createDrawerNavigator<HomeDrawerNavigatorParams>() const HomeDrawer = createDrawerNavigator<HomeDrawerNavigatorParams>()
const HomeTab = createNativeStackNavigator<HomeTabNavigatorParams>() const HomeTab = createNativeStackNavigator<HomeTabNavigatorParams>()
const SearchDrawer = createDrawerNavigator<SearchDrawerNavigatorParams>() const SearchDrawer = createDrawerNavigator<SearchDrawerNavigatorParams>()
@@ -87,7 +93,7 @@ const ROUTES: Record<string, Route> = {
Log: r('/sys/log'), 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 name = 'NotFound'
let params: RouteParams = {} let params: RouteParams = {}
for (const [screenName, matcher] of Object.entries(ROUTES)) { for (const [screenName, matcher] of Object.entries(ROUTES)) {
@@ -101,7 +107,7 @@ export function matchPath(path: string): {name: string; params: RouteParams} {
return {name, params} return {name, params}
} }
export const LINKING = { const LINKING = {
prefixes: ['bsky://', 'https://bsky.app'], prefixes: ['bsky://', 'https://bsky.app'],
getPathFromState(state: State) { getPathFromState(state: State) {
@@ -245,7 +251,7 @@ function NotificationsTabNavigator() {
) )
} }
export function TabsNavigator() { function TabsNavigator() {
const tabBar = React.useCallback(props => <BottomBar {...props} />, []) const tabBar = React.useCallback(props => <BottomBar {...props} />, [])
return ( return (
<Tab.Navigator <Tab.Navigator
@@ -263,6 +269,12 @@ export function TabsNavigator() {
) )
} }
export function RoutesContainer({children}: React.PropsWithChildren<{}>) { function RoutesContainer({children}: React.PropsWithChildren<{}>) {
return <NavigationContainer linking={LINKING}>{children}</NavigationContainer> return (
<NavigationContainer ref={navigationRef} linking={LINKING}>
{children}
</NavigationContainer>
)
} }
export {navigationRef as navigation, matchPath, TabsNavigator, RoutesContainer}