diff --git a/native/chat/chat-list.react.js b/native/chat/chat-list.react.js --- a/native/chat/chat-list.react.js +++ b/native/chat/chat-list.react.js @@ -1,5 +1,10 @@ // @flow +import type { + TabNavigationState, + BottomTabOptions, + BottomTabNavigationEventMap, +} from '@react-navigation/core'; import invariant from 'invariant'; import _sum from 'lodash/fp/sum.js'; import * as React from 'react'; @@ -24,6 +29,7 @@ type KeyboardState, KeyboardContext, } from '../keyboard/keyboard-state.js'; +import type { ScreenParamList } from '../navigation/route-names.js'; import type { TabNavigationProp } from '../navigation/tab-navigator.react.js'; import { useSelector } from '../redux/redux-utils.js'; import type { ChatMessageItemWithHeight } from '../types/chat-types.js'; @@ -80,16 +86,28 @@ } componentDidMount() { - const tabNavigation: ?TabNavigationProp<'Chat'> = - this.props.navigation.getParent(); + const tabNavigation = this.props.navigation.getParent< + ScreenParamList, + 'Chat', + TabNavigationState, + BottomTabOptions, + BottomTabNavigationEventMap, + TabNavigationProp<'Chat'>, + >(); invariant(tabNavigation, 'ChatNavigator should be within TabNavigator'); tabNavigation.addListener('tabPress', this.onTabPress); this.props.inputState?.addScrollToMessageListener(this.scrollToMessage); } componentWillUnmount() { - const tabNavigation: ?TabNavigationProp<'Chat'> = - this.props.navigation.getParent(); + const tabNavigation = this.props.navigation.getParent< + ScreenParamList, + 'Chat', + TabNavigationState, + BottomTabOptions, + BottomTabNavigationEventMap, + TabNavigationProp<'Chat'>, + >(); invariant(tabNavigation, 'ChatNavigator should be within TabNavigator'); tabNavigation.removeListener('tabPress', this.onTabPress); this.props.inputState?.removeScrollToMessageListener(this.scrollToMessage); diff --git a/native/chat/chat-thread-list.react.js b/native/chat/chat-thread-list.react.js --- a/native/chat/chat-thread-list.react.js +++ b/native/chat/chat-thread-list.react.js @@ -1,6 +1,14 @@ // @flow import IonIcon from '@expo/vector-icons/Ionicons.js'; +import type { + TabNavigationState, + BottomTabOptions, + BottomTabNavigationEventMap, + StackNavigationState, + StackOptions, + StackNavigationEventMap, +} from '@react-navigation/core'; import invariant from 'invariant'; import * as React from 'react'; import { @@ -40,6 +48,7 @@ HomeChatThreadListRouteName, BackgroundChatThreadListRouteName, type NavigationRoute, + type ScreenParamList, } from '../navigation/route-names.js'; import type { TabNavigationProp } from '../navigation/tab-navigator.react.js'; import { useSelector } from '../redux/redux-utils.js'; @@ -415,11 +424,24 @@ }, [navigation]); React.useEffect(() => { - const chatNavigation: ?ChatNavigationProp<'ChatThreadList'> = - navigation.getParent(); + const chatNavigation = navigation.getParent< + ScreenParamList, + 'ChatThreadList', + StackNavigationState, + StackOptions, + StackNavigationEventMap, + ChatNavigationProp<'ChatThreadList'>, + >(); invariant(chatNavigation, 'ChatNavigator should be within TabNavigator'); - const tabNavigation: ?TabNavigationProp<'Chat'> = - chatNavigation.getParent(); + + const tabNavigation = chatNavigation.getParent< + ScreenParamList, + 'Chat', + TabNavigationState, + BottomTabOptions, + BottomTabNavigationEventMap, + TabNavigationProp<'Chat'>, + >(); invariant(tabNavigation, 'ChatNavigator should be within TabNavigator'); tabNavigation.addListener('tabPress', onTabPress); diff --git a/native/chat/settings/thread-settings.react.js b/native/chat/settings/thread-settings.react.js --- a/native/chat/settings/thread-settings.react.js +++ b/native/chat/settings/thread-settings.react.js @@ -1,5 +1,10 @@ // @flow +import type { + TabNavigationState, + BottomTabOptions, + BottomTabNavigationEventMap, +} from '@react-navigation/core'; import invariant from 'invariant'; import * as React from 'react'; import { View, Platform } from 'react-native'; @@ -88,8 +93,9 @@ AddUsersModalRouteName, ComposeSubchannelModalRouteName, FullScreenThreadMediaGalleryRouteName, + type ScreenParamList, + type NavigationRoute, } from '../../navigation/route-names.js'; -import type { NavigationRoute } from '../../navigation/route-names.js'; import type { TabNavigationProp } from '../../navigation/tab-navigator.react.js'; import { useSelector } from '../../redux/redux-utils.js'; import type { AppState } from '../../redux/state-types.js'; @@ -1239,7 +1245,14 @@ const { navigation } = props; React.useEffect(() => { - const tabNavigation: ?TabNavigationProp<'Chat'> = navigation.getParent(); + const tabNavigation = navigation.getParent< + ScreenParamList, + 'Chat', + TabNavigationState, + BottomTabOptions, + BottomTabNavigationEventMap, + TabNavigationProp<'Chat'>, + >(); invariant(tabNavigation, 'ChatNavigator should be within TabNavigator'); const onTabPress = () => { diff --git a/native/flow-typed/npm/@react-navigation/core_v6.x.x.js b/native/flow-typed/npm/@react-navigation/core_v6.x.x.js --- a/native/flow-typed/npm/@react-navigation/core_v6.x.x.js +++ b/native/flow-typed/npm/@react-navigation/core_v6.x.x.js @@ -868,7 +868,20 @@ +isFocused: () => boolean, +canGoBack: () => boolean, +getId: () => string | void, - +getParent: >(id?: string) => ?Parent, + +getParent: < + ParamList: ParamListBase, + RouteName: $Keys, + State: PossiblyStaleNavigationState, + ScreenOptions: {...}, + EventMap: EventMapBase, + Parent: NavigationProp< + ParamList, + RouteName, + State, + ScreenOptions, + EventMap, + >, + >(id?: string) => ?Parent, +getState: () => NavigationState, +addListener: |},