Skip to content

Commit

Permalink
handleOutboundEvents: Stop using NavigationService
Browse files Browse the repository at this point in the history
Further in the direction of zulip#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 zulip#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.
  • Loading branch information
chrisbobbe committed Nov 17, 2022
1 parent 898a0d3 commit a622636
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
13 changes: 1 addition & 12 deletions src/nav/navActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()?
Expand Down Expand Up @@ -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 });
19 changes: 5 additions & 14 deletions src/webview/handleOutboundEvents.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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 });
}
};

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit a622636

Please sign in to comment.