From a62263607f07b684c4bf51949fcdcda5c4ec8e8f Mon Sep 17 00:00:00 2001 From: Chris Bobbe Date: Thu, 17 Nov 2022 13:24:13 -0800 Subject: [PATCH] handleOutboundEvents: Stop using NavigationService Further in the direction of #5408, which switched most of our then-existing uses of NavigationService to use `navigation` instead. As noted there: > Switching away from `NavigationService` is recommended by React > Navigation upstream, as described at #4417. We also now get > type-checking on those `navigation.push` calls -- Flow is able to > check that the route params we pass line up with what the route in > question expects -- which wasn't/isn't the case for the > implementations of the `navActions` functions. This causes a few of the navActions functions to lose their last remaining caller, so delete those. --- src/nav/navActions.js | 13 +------------ src/webview/handleOutboundEvents.js | 19 +++++-------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/src/nav/navActions.js b/src/nav/navActions.js index f03cabc434d..977c72294f6 100644 --- a/src/nav/navActions.js +++ b/src/nav/navActions.js @@ -7,7 +7,7 @@ import { } from '@react-navigation/native'; import * as NavigationService from './NavigationService'; -import type { Message, Narrow, UserId } from '../types'; +import type { Narrow } from '../types'; import type { SharedData } from '../sharing/types'; // TODO: Probably just do a StackActions.pop()? @@ -46,16 +46,5 @@ export const navigateToChat = (narrow: Narrow): NavigationAction => export const replaceWithChat = (narrow: Narrow): NavigationAction => StackActions.replace('chat', { narrow, editMessage: null }); -export const navigateToAccountDetails = (userId: UserId): NavigationAction => - StackActions.push('account-details', { userId }); - -export const navigateToLightbox = (src: URL, message: Message): NavigationAction => - StackActions.push('lightbox', { src, message }); - -export const navigateToMessageReactionScreen = ( - messageId: number, - reactionName?: string, -): NavigationAction => StackActions.push('message-reactions', { messageId, reactionName }); - export const navigateToSharing = (sharedData: SharedData): NavigationAction => StackActions.push('sharing', { sharedData }); diff --git a/src/webview/handleOutboundEvents.js b/src/webview/handleOutboundEvents.js index 0b5a71f00fa..d0ae32d8228 100644 --- a/src/webview/handleOutboundEvents.js +++ b/src/webview/handleOutboundEvents.js @@ -1,7 +1,6 @@ /* @flow strict-local */ import { Clipboard, Alert } from 'react-native'; -import * as NavigationService from '../nav/NavigationService'; import * as api from '../api'; import config from '../config'; import type { UserId } from '../types'; @@ -12,15 +11,7 @@ import { isUrlAnImage, tryParseUrl } from '../utils/url'; import * as logging from '../utils/logging'; import { filterUnreadMessagesInRange } from '../utils/unread'; import { parseNarrow } from '../utils/narrow'; -import { - fetchOlder, - fetchNewer, - navigateToAccountDetails, - navigateToMessageReactionScreen, - doNarrow, - navigateToLightbox, - messageLinkPress, -} from '../actions'; +import { fetchOlder, fetchNewer, doNarrow, messageLinkPress } from '../actions'; import { showTopicActionSheet, showPmConversationActionSheet, @@ -203,7 +194,7 @@ const handleImage = ( const message = props.messages.find(x => x.id === messageId); if (message && message.isOutbox !== true) { - NavigationService.dispatch(navigateToLightbox(parsedSrc, message)); + navigation.push('lightbox', { src: parsedSrc, message }); } }; @@ -281,7 +272,7 @@ export const handleWebViewOutboundEvent = ( break; case 'request-user-profile': { - NavigationService.dispatch(navigateToAccountDetails(event.fromUserId)); + navigation.push('account-details', { userId: event.fromUserId }); break; } @@ -326,12 +317,12 @@ export const handleWebViewOutboundEvent = ( case 'reactionDetails': { const { messageId, reactionName } = event; - NavigationService.dispatch(navigateToMessageReactionScreen(messageId, reactionName)); + navigation.push('message-reactions', { messageId, reactionName }); } break; case 'mention': { - NavigationService.dispatch(navigateToAccountDetails(event.userId)); + navigation.push('account-details', { userId: event.userId }); break; }