diff --git a/app/products/calls/screens/call_screen/call_screen.tsx b/app/products/calls/screens/call_screen/call_screen.tsx index d7bdd2316..de346c0de 100644 --- a/app/products/calls/screens/call_screen/call_screen.tsx +++ b/app/products/calls/screens/call_screen/call_screen.tsx @@ -371,20 +371,22 @@ const CallScreen = ({ const hideCCTitle = intl.formatMessage({id: 'mobile.calls_hide_cc', defaultMessage: 'Hide live captions'}); useEffect(() => { - mergeNavigationOptions('Call', { - layout: { - componentBackgroundColor: callsTheme.callsBg, - orientation: allOrientations, - }, - topBar: { - visible: false, - }, - }); - if (Platform.OS === 'ios') { - RNUtils.unlockOrientation(); - } + const setOrientation = () => { + mergeNavigationOptions('Call', { + layout: { + componentBackgroundColor: callsTheme.callsBg, + orientation: allOrientations, + }, + topBar: { + visible: false, + }, + }); + if (Platform.OS === 'ios') { + RNUtils.unlockOrientation(); + } + }; - return () => { + const unsetOrientation = () => { setScreensOrientation(isTablet); if (Platform.OS === 'ios' && !isTablet) { // We need both the navigation & the module @@ -392,6 +394,30 @@ const CallScreen = ({ } freezeOtherScreens(false); }; + + // Handle component disappearing (e.g. device is locked) + const didDismissListener = Navigation.events().registerComponentDidDisappearListener(async ({componentId: screen}) => { + if (componentId === screen) { + unsetOrientation(); + } + }); + + // Handle component re-appearing (e.g. device is unlocked) + const didAppearListener = Navigation.events().registerComponentWillAppearListener(async ({componentId: screen}) => { + if (componentId === screen) { + setOrientation(); + } + }); + + // Set orientation on component mount. + setOrientation(); + + return () => { + didDismissListener.remove(); + didAppearListener.remove(); + + unsetOrientation(); + }; }, []); const leaveCallHandler = useCallback(() => { @@ -566,16 +592,6 @@ const CallScreen = ({ useAndroidHardwareBackHandler(componentId, collapse); - useEffect(() => { - const didDismissListener = Navigation.events().registerComponentDidDisappearListener(async ({componentId: screen}) => { - if (componentId === screen) { - setScreensOrientation(isTablet); - } - }); - - return () => didDismissListener.remove(); - }, [isTablet]); - useEffect(() => { if (!layout || !layout.height || !layout.width) { return;