From c4e93ce2a53ddf038be3a0c93b79b2666e485567 Mon Sep 17 00:00:00 2001 From: Christopher Poile Date: Thu, 11 Aug 2022 14:03:25 -0400 Subject: [PATCH] Fix for call screen popping errors (#6569) --- .../calls/connection/websocket_event_handlers.ts | 4 ++-- .../calls/screens/call_screen/call_screen.tsx | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/products/calls/connection/websocket_event_handlers.ts b/app/products/calls/connection/websocket_event_handlers.ts index 48d5bc0b1..eef5ff4f3 100644 --- a/app/products/calls/connection/websocket_event_handlers.ts +++ b/app/products/calls/connection/websocket_event_handlers.ts @@ -68,11 +68,11 @@ export const handleCallStarted = (serverUrl: string, msg: WebSocketMessage) => { }; export const handleCallEnded = (serverUrl: string, msg: WebSocketMessage) => { - callEnded(serverUrl, msg.broadcast.channel_id); - DeviceEventEmitter.emit(WebsocketEvents.CALLS_CALL_END, { channelId: msg.broadcast.channel_id, }); + + callEnded(serverUrl, msg.broadcast.channel_id); }; export const handleCallChannelEnabled = (serverUrl: string, msg: WebSocketMessage) => { diff --git a/app/products/calls/screens/call_screen/call_screen.tsx b/app/products/calls/screens/call_screen/call_screen.tsx index 394a6b55e..4cb854cbd 100644 --- a/app/products/calls/screens/call_screen/call_screen.tsx +++ b/app/products/calls/screens/call_screen/call_screen.tsx @@ -13,6 +13,7 @@ import { useWindowDimensions, DeviceEventEmitter, Keyboard, } from 'react-native'; +import {Navigation} from 'react-native-navigation'; import {useSafeAreaInsets} from 'react-native-safe-area-context'; import {RTCView} from 'react-native-webrtc'; @@ -37,6 +38,7 @@ import {WebsocketEvents, Screens} from '@constants'; import {useTheme} from '@context/theme'; import DatabaseManager from '@database/manager'; import {bottomSheet, dismissBottomSheet, goToScreen, popTopScreen} from '@screens/navigation'; +import NavigationStore from '@store/navigation_store'; import {bottomSheetSnapPoint} from '@utils/helpers'; import {mergeNavigationOptions} from '@utils/navigation'; import {makeStyleSheetFromTheme} from '@utils/theme'; @@ -358,8 +360,8 @@ const CallScreen = ({componentId, currentCall, participantsDict, teammateNameDis useEffect(() => { const listener = DeviceEventEmitter.addListener(WebsocketEvents.CALLS_CALL_END, ({channelId}) => { - if (channelId === currentCall?.channelId) { - popTopScreen(componentId); + if (channelId === currentCall?.channelId && NavigationStore.getNavigationTopComponentId() === componentId) { + Navigation.pop(componentId); } }); @@ -367,8 +369,13 @@ const CallScreen = ({componentId, currentCall, participantsDict, teammateNameDis }, []); if (!currentCall || !myParticipant) { - // TODO: will figure out a way to remove the need for this check: https://mattermost.atlassian.net/browse/MM-46050 - popTopScreen(componentId); + // Note: this happens because the screen is "rendered", even after the screen has been popped, and the + // currentCall will have already been set to null when those extra renders run. We probably don't ever need + // to pop, but just in case. + if (NavigationStore.getNavigationTopComponentId() === componentId) { + // ignore the error because the call screen has likely already been popped async + Navigation.pop(componentId).catch(() => null); + } return null; }