From 6b4078c601d92a9616377b0d9039a38a7a095930 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Thu, 12 Dec 2024 12:49:02 +0100 Subject: [PATCH 01/14] revert: ws switcher home route setParams changes --- .../createCustomBottomTabNavigator/TopBar.tsx | 13 ++----------- src/libs/Navigation/switchPolicyID.ts | 13 +------------ src/pages/WorkspaceSwitcherPage/index.tsx | 5 ++++- .../SidebarScreen/BaseSidebarScreen.tsx | 19 ++----------------- 4 files changed, 9 insertions(+), 41 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx index 01caa79692f1..c72c4de01e4e 100644 --- a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar.tsx @@ -22,15 +22,9 @@ type TopBarProps = { activeWorkspaceID?: string; shouldDisplaySearch?: boolean; shouldDisplayCancelSearch?: boolean; - - /** - * Callback used to keep track of the workspace switching process in the BaseSidebarScreen. - * Passed to the WorkspaceSwitcherButton component. - */ - onSwitchWorkspace?: () => void; }; -function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true, shouldDisplayCancelSearch = false, onSwitchWorkspace}: TopBarProps) { +function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true, shouldDisplayCancelSearch = false}: TopBarProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); const policy = usePolicy(activeWorkspaceID); @@ -53,10 +47,7 @@ function TopBar({breadcrumbLabel, activeWorkspaceID, shouldDisplaySearch = true, dataSet={{dragArea: true}} > - + { + Navigation.goBack(); + }); }, [activeWorkspaceID, setActiveWorkspaceID, isFocused], ); diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx index 814daa82ea3d..0dcb1124ee3e 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx @@ -1,4 +1,4 @@ -import React, {useEffect, useRef} from 'react'; +import React, {useEffect} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -28,25 +28,11 @@ function BaseSidebarScreen() { Timing.start(CONST.TIMING.SIDEBAR_LOADED); }, []); - const isSwitchingWorkspace = useRef(false); useEffect(() => { - // Whether the active workspace or the "Everything" page is loaded - const isWorkspaceOrEverythingLoaded = !!activeWorkspace || activeWorkspaceID === undefined; - - // If we are currently switching workspaces, we don't want to do anything until the target workspace is loaded - if (isSwitchingWorkspace.current) { - if (isWorkspaceOrEverythingLoaded) { - isSwitchingWorkspace.current = false; - } - return; - } - - // Otherwise, if the workspace is already loaded, we don't need to do anything - if (isWorkspaceOrEverythingLoaded) { + if (!!activeWorkspace || activeWorkspaceID === undefined) { return; } - isSwitchingWorkspace.current = true; Navigation.navigateWithSwitchPolicyID({policyID: undefined}); updateLastAccessedWorkspace(undefined); }, [activeWorkspace, activeWorkspaceID]); @@ -67,7 +53,6 @@ function BaseSidebarScreen() { breadcrumbLabel={translate('common.inbox')} activeWorkspaceID={activeWorkspaceID} shouldDisplaySearch={shouldDisplaySearch} - onSwitchWorkspace={() => (isSwitchingWorkspace.current = true)} /> From a64553edf44482a2e8abae632505a74c64599e40 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Thu, 12 Dec 2024 13:42:21 +0100 Subject: [PATCH 02/14] fix: blank screen when navigating back from WS Switcher --- src/components/WorkspaceSwitcherButton.tsx | 10 ++-------- src/pages/WorkspaceSwitcherPage/index.tsx | 7 +++---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/components/WorkspaceSwitcherButton.tsx b/src/components/WorkspaceSwitcherButton.tsx index 04349526aaea..fa0080c9eff1 100644 --- a/src/components/WorkspaceSwitcherButton.tsx +++ b/src/components/WorkspaceSwitcherButton.tsx @@ -18,14 +18,9 @@ type WorkspaceSwitcherButtonOnyxProps = { policy: OnyxEntry; }; -type WorkspaceSwitcherButtonProps = WorkspaceSwitcherButtonOnyxProps & { - /** - * Callback used to keep track of the workspace switching process in the BaseSidebarScreen. - */ - onSwitchWorkspace?: () => void; -}; +type WorkspaceSwitcherButtonProps = WorkspaceSwitcherButtonOnyxProps; -function WorkspaceSwitcherButton({policy, onSwitchWorkspace}: WorkspaceSwitcherButtonProps) { +function WorkspaceSwitcherButton({policy}: WorkspaceSwitcherButtonProps) { const {translate} = useLocalize(); const theme = useTheme(); @@ -54,7 +49,6 @@ function WorkspaceSwitcherButton({policy, onSwitchWorkspace}: WorkspaceSwitcherB accessible testID="WorkspaceSwitcherButton" onPress={() => { - onSwitchWorkspace?.(); pressableRef?.current?.blur(); interceptAnonymousUser(() => { Navigation.navigate(ROUTES.WORKSPACE_SWITCHER); diff --git a/src/pages/WorkspaceSwitcherPage/index.tsx b/src/pages/WorkspaceSwitcherPage/index.tsx index f631edd2868e..fe4a07025bfe 100644 --- a/src/pages/WorkspaceSwitcherPage/index.tsx +++ b/src/pages/WorkspaceSwitcherPage/index.tsx @@ -87,11 +87,10 @@ function WorkspaceSwitcherPage() { setActiveWorkspaceID(newPolicyID); if (newPolicyID !== activeWorkspaceID) { - Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); + InteractionManager.runAfterInteractions(() => { + Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); + }); } - InteractionManager.runAfterInteractions(() => { - Navigation.goBack(); - }); }, [activeWorkspaceID, setActiveWorkspaceID, isFocused], ); From 30f55fe5dc03a0b2cc4f88342f10828795c1e750 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 13 Dec 2024 10:33:27 +0100 Subject: [PATCH 03/14] fix: only run InteractionManager on iOS --- src/pages/WorkspaceSwitcherPage/index.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pages/WorkspaceSwitcherPage/index.tsx b/src/pages/WorkspaceSwitcherPage/index.tsx index fe4a07025bfe..8e65bc703f28 100644 --- a/src/pages/WorkspaceSwitcherPage/index.tsx +++ b/src/pages/WorkspaceSwitcherPage/index.tsx @@ -1,6 +1,6 @@ import {useIsFocused} from '@react-navigation/native'; import React, {useCallback, useMemo} from 'react'; -import {InteractionManager} from 'react-native'; +import {InteractionManager, Platform} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import * as Expensicons from '@components/Icon/Expensicons'; @@ -86,10 +86,16 @@ function WorkspaceSwitcherPage() { const newPolicyID = policyID === activeWorkspaceID ? undefined : policyID; setActiveWorkspaceID(newPolicyID); + Navigation.goBack(); if (newPolicyID !== activeWorkspaceID) { - InteractionManager.runAfterInteractions(() => { + if (Platform.OS === 'ios') { + InteractionManager.runAfterInteractions(() => { + Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); + }); + } else { Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); - }); + } + } }, [activeWorkspaceID, setActiveWorkspaceID, isFocused], From abed839ba827221ddd1937554000ac5a2d673f3c Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 13 Dec 2024 12:32:37 +0100 Subject: [PATCH 04/14] fix: ios 'none' screen animation not working --- .../createCustomBottomTabNavigator/index.tsx | 3 ++- .../navigationOptions/animation/index.ts | 1 + .../none/{index.native.ts => index.android.ts} | 0 .../navigationOptions/animation/none/index.ios.ts | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) rename src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/{index.native.ts => index.android.ts} (100%) create mode 100644 src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.ios.ts diff --git a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/index.tsx b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/index.tsx index a4e50aeb6516..2461c542ec7d 100644 --- a/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/index.tsx +++ b/src/libs/Navigation/AppNavigator/createCustomBottomTabNavigator/index.tsx @@ -2,13 +2,14 @@ import type {ParamListBase} from '@react-navigation/native'; import {createNavigatorFactory} from '@react-navigation/native'; import React from 'react'; import createPlatformStackNavigatorComponent from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigatorComponent'; +import Animations from '@libs/Navigation/PlatformStackNavigation/navigationOptions/animation'; import type {ExtraContentProps, PlatformStackNavigationEventMap, PlatformStackNavigationOptions, PlatformStackNavigationState} from '@libs/Navigation/PlatformStackNavigation/types'; import BottomTabBar from './BottomTabBar'; import BottomTabNavigationContentWrapper from './BottomTabNavigationContentWrapper'; import useCustomState from './useCustomState'; const defaultScreenOptions: PlatformStackNavigationOptions = { - animation: 'none', + animation: Animations.NONE, }; function ExtraContent({state}: ExtraContentProps) { diff --git a/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/index.ts b/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/index.ts index 17796333cdda..4fbf754d579f 100644 --- a/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/index.ts +++ b/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/index.ts @@ -5,6 +5,7 @@ const InternalPlatformAnimations = { IOS_FROM_LEFT: 'ios_from_left', IOS_FROM_RIGHT: 'ios_from_right', SIMPLE_PUSH: 'simple_push', + FADE_FROM_BOTTOM: 'fade_from_bottom', } as const; const Animations = { diff --git a/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.native.ts b/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.android.ts similarity index 100% rename from src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.native.ts rename to src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.android.ts diff --git a/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.ios.ts b/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.ios.ts new file mode 100644 index 000000000000..0799b1106c1a --- /dev/null +++ b/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.ios.ts @@ -0,0 +1,14 @@ +import type {NativeStackNavigationOptions} from '@react-navigation/native-stack'; +import {InternalPlatformAnimations} from '..'; +import type NoneTransitionNavigationOptions from './types'; + +const none: NoneTransitionNavigationOptions = { + gestureEnabled: false, + // This is a workaround, because `animation: none` does not work on iOS in `@react-navigation/native-stack@6.9.26` + // Additionally, the `fade_from_bottom` animation seems to be the only one where `animationDuration` works + // Upstream issue: + animation: InternalPlatformAnimations.FADE_FROM_BOTTOM, + animationDuration: 0, +} satisfies NativeStackNavigationOptions; + +export default none; From 3aa698daa88f05d1fa1cfe761dd22615b95c75d8 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Sun, 15 Dec 2024 21:21:47 +0100 Subject: [PATCH 05/14] fix: ios fade animation --- ...custom-animations-native-transitions.patch | 26 +++---------------- .../navigationOptions/animation/index.ts | 1 + .../animation/none/index.android.ts | 4 +-- .../animation/none/index.ios.ts | 6 +---- 4 files changed, 8 insertions(+), 29 deletions(-) diff --git a/patches/react-native-screens+3.34.0+004+ios-custom-animations-native-transitions.patch b/patches/react-native-screens+3.34.0+004+ios-custom-animations-native-transitions.patch index 62cbf68f458d..09411a72b3d3 100644 --- a/patches/react-native-screens+3.34.0+004+ios-custom-animations-native-transitions.patch +++ b/patches/react-native-screens+3.34.0+004+ios-custom-animations-native-transitions.patch @@ -1,5 +1,5 @@ diff --git a/node_modules/react-native-screens/ios/RNSScreenStackAnimator.mm b/node_modules/react-native-screens/ios/RNSScreenStackAnimator.mm -index abb2cf6..fb81d52 100644 +index abb2cf6..c21b3e9 100644 --- a/node_modules/react-native-screens/ios/RNSScreenStackAnimator.mm +++ b/node_modules/react-native-screens/ios/RNSScreenStackAnimator.mm @@ -5,13 +5,14 @@ @@ -32,7 +32,7 @@ index abb2cf6..fb81d52 100644 } @@ -129,6 +130,8 @@ - (void)animateSimplePushWithShadowEnabled:(BOOL)shadowEnabled } - + [UIView animateWithDuration:[self transitionDuration:transitionContext] + delay:0 + options:UIViewAnimationOptionCurveDefaultTransition @@ -66,25 +66,7 @@ index abb2cf6..fb81d52 100644 animations:animationBlock completion:completionBlock]; } else { -@@ -251,6 +260,8 @@ - (void)animateFadeWithTransitionContext:(id - animation: InternalPlatformAnimations.FADE_FROM_BOTTOM, - animationDuration: 0, } satisfies NativeStackNavigationOptions; export default none; From 6e3b566845526da1d49f48c0fa8fb67ef8362e60 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Sun, 15 Dec 2024 21:25:06 +0100 Subject: [PATCH 06/14] remove fade_from_bottom animation --- .../PlatformStackNavigation/navigationOptions/animation/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/index.ts b/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/index.ts index 60c3e1b59e14..a890e127d122 100644 --- a/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/index.ts +++ b/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/index.ts @@ -5,7 +5,6 @@ const InternalPlatformAnimations = { IOS_FROM_LEFT: 'ios_from_left', IOS_FROM_RIGHT: 'ios_from_right', SIMPLE_PUSH: 'simple_push', - FADE_FROM_BOTTOM: 'fade_from_bottom', NONE: 'none', } as const; From 9665162f4a0461baad506b0cee5a988a6f55fdc3 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Sun, 15 Dec 2024 21:26:08 +0100 Subject: [PATCH 07/14] rename file --- .../navigationOptions/animation/none/index.android.ts | 7 ------- .../animation/none/{index.ios.ts => index.native.ts} | 0 2 files changed, 7 deletions(-) delete mode 100644 src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.android.ts rename src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/{index.ios.ts => index.native.ts} (100%) diff --git a/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.android.ts b/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.android.ts deleted file mode 100644 index bca4b1cbc207..000000000000 --- a/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.android.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type {NativeStackNavigationOptions} from '@react-navigation/native-stack'; -import {InternalPlatformAnimations} from '..'; -import type NoneTransitionNavigationOptions from './types'; - -const none: NoneTransitionNavigationOptions = {animation: InternalPlatformAnimations.NONE, gestureEnabled: false} satisfies NativeStackNavigationOptions; - -export default none; diff --git a/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.ios.ts b/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.native.ts similarity index 100% rename from src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.ios.ts rename to src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/none/index.native.ts From 4ddab5d6574a4405efc88869d8263f1d7b9c2015 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Sun, 15 Dec 2024 21:35:48 +0100 Subject: [PATCH 08/14] docs: add comment --- src/pages/WorkspaceSwitcherPage/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/WorkspaceSwitcherPage/index.tsx b/src/pages/WorkspaceSwitcherPage/index.tsx index 8e65bc703f28..41e209535fae 100644 --- a/src/pages/WorkspaceSwitcherPage/index.tsx +++ b/src/pages/WorkspaceSwitcherPage/index.tsx @@ -88,6 +88,9 @@ function WorkspaceSwitcherPage() { setActiveWorkspaceID(newPolicyID); Navigation.goBack(); if (newPolicyID !== activeWorkspaceID) { + // On iOS, we will see a blank screen if we navigate to a new HomeScreen route while also navigating back + // Therefore we delay the workspace switching until the back navigation animation is complete. + // On Android, this is not an issue, therefore we only use the InteractionManager on iOS. if (Platform.OS === 'ios') { InteractionManager.runAfterInteractions(() => { Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); @@ -95,7 +98,6 @@ function WorkspaceSwitcherPage() { } else { Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); } - } }, [activeWorkspaceID, setActiveWorkspaceID, isFocused], From 70a19d692094783a642647deecf7215065daeeff Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Sun, 15 Dec 2024 21:38:59 +0100 Subject: [PATCH 09/14] fix: also apply change on Android --- src/pages/WorkspaceSwitcherPage/index.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pages/WorkspaceSwitcherPage/index.tsx b/src/pages/WorkspaceSwitcherPage/index.tsx index 41e209535fae..fc7ea537cf30 100644 --- a/src/pages/WorkspaceSwitcherPage/index.tsx +++ b/src/pages/WorkspaceSwitcherPage/index.tsx @@ -88,10 +88,9 @@ function WorkspaceSwitcherPage() { setActiveWorkspaceID(newPolicyID); Navigation.goBack(); if (newPolicyID !== activeWorkspaceID) { - // On iOS, we will see a blank screen if we navigate to a new HomeScreen route while also navigating back - // Therefore we delay the workspace switching until the back navigation animation is complete. - // On Android, this is not an issue, therefore we only use the InteractionManager on iOS. - if (Platform.OS === 'ios') { + // On native platforms, we will see a blank screen if we navigate to a new HomeScreen route while also navigating back + // Therefore we delay the workspace switching until the back navigation animation is complete, using the InteractionManager. + if (Platform.OS === 'ios' || Platform.OS === 'android') { InteractionManager.runAfterInteractions(() => { Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); }); From 05a55123901a7d2545f58514861007d74f8b826b Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Sun, 15 Dec 2024 21:40:49 +0100 Subject: [PATCH 10/14] fix: use getPlatform --- src/pages/WorkspaceSwitcherPage/index.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pages/WorkspaceSwitcherPage/index.tsx b/src/pages/WorkspaceSwitcherPage/index.tsx index fc7ea537cf30..7ed440f97b10 100644 --- a/src/pages/WorkspaceSwitcherPage/index.tsx +++ b/src/pages/WorkspaceSwitcherPage/index.tsx @@ -1,6 +1,6 @@ import {useIsFocused} from '@react-navigation/native'; import React, {useCallback, useMemo} from 'react'; -import {InteractionManager, Platform} from 'react-native'; +import {InteractionManager} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import * as Expensicons from '@components/Icon/Expensicons'; @@ -12,6 +12,7 @@ import useActiveWorkspace from '@hooks/useActiveWorkspace'; import useDebouncedState from '@hooks/useDebouncedState'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; +import getPlatform from '@libs/getPlatform'; import Navigation from '@libs/Navigation/Navigation'; import * as PolicyUtils from '@libs/PolicyUtils'; import {sortWorkspacesBySelected} from '@libs/PolicyUtils'; @@ -90,7 +91,8 @@ function WorkspaceSwitcherPage() { if (newPolicyID !== activeWorkspaceID) { // On native platforms, we will see a blank screen if we navigate to a new HomeScreen route while also navigating back // Therefore we delay the workspace switching until the back navigation animation is complete, using the InteractionManager. - if (Platform.OS === 'ios' || Platform.OS === 'android') { + const platform = getPlatform(); + if (platform === CONST.PLATFORM.IOS || platform === CONST.PLATFORM.ANDROID) { InteractionManager.runAfterInteractions(() => { Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); }); From 0eda66d6ec78624abac496844598085e19788079 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Sun, 15 Dec 2024 21:43:55 +0100 Subject: [PATCH 11/14] refactor: replace none animation hardcoded strings --- src/libs/Navigation/AppNavigator/AuthScreens.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index e01d0fe3115f..b4a6f4f1129c 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -25,6 +25,7 @@ import Log from '@libs/Log'; import NavBarManager from '@libs/NavBarManager'; import getCurrentUrl from '@libs/Navigation/currentUrl'; import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; +import Animations from '@libs/Navigation/PlatformStackNavigation/navigationOptions/animation'; import Presentation from '@libs/Navigation/PlatformStackNavigation/navigationOptions/presentation'; import type {PlatformStackNavigationOptions} from '@libs/Navigation/PlatformStackNavigation/types'; import shouldOpenOnAdminRoom from '@libs/Navigation/shouldOpenOnAdminRoom'; @@ -464,7 +465,7 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie options={{ headerShown: false, presentation: Presentation.TRANSPARENT_MODAL, - animation: 'none', + animation: Animations.NONE, }} getComponent={loadProfileAvatar} listeners={modalScreenListeners} From 6c7218f64b449821d6aa45fa7f1f314668b71410 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Sun, 15 Dec 2024 21:45:21 +0100 Subject: [PATCH 12/14] update comment --- src/pages/WorkspaceSwitcherPage/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/WorkspaceSwitcherPage/index.tsx b/src/pages/WorkspaceSwitcherPage/index.tsx index 7ed440f97b10..4651fef82f3c 100644 --- a/src/pages/WorkspaceSwitcherPage/index.tsx +++ b/src/pages/WorkspaceSwitcherPage/index.tsx @@ -89,8 +89,8 @@ function WorkspaceSwitcherPage() { setActiveWorkspaceID(newPolicyID); Navigation.goBack(); if (newPolicyID !== activeWorkspaceID) { - // On native platforms, we will see a blank screen if we navigate to a new HomeScreen route while also navigating back - // Therefore we delay the workspace switching until the back navigation animation is complete, using the InteractionManager. + // On native platforms, we will see a blank screen if we navigate to a new HomeScreen route while navigating back at the same time. + // Therefore we delay switching the workspace until after back navigation, using the InteractionManager. const platform = getPlatform(); if (platform === CONST.PLATFORM.IOS || platform === CONST.PLATFORM.ANDROID) { InteractionManager.runAfterInteractions(() => { From 8f7ef9f872d85c06ff00df7766e6f3ef2e7a8cf9 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 18 Dec 2024 15:32:35 +0100 Subject: [PATCH 13/14] fix: move to platform specific code --- src/pages/WorkspaceSwitcherPage/index.tsx | 12 ++---------- .../switchPolicyAfterInteractions/index.native.tsx | 10 ++++++++++ .../switchPolicyAfterInteractions/index.tsx | 7 +++++++ 3 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 src/pages/WorkspaceSwitcherPage/switchPolicyAfterInteractions/index.native.tsx create mode 100644 src/pages/WorkspaceSwitcherPage/switchPolicyAfterInteractions/index.tsx diff --git a/src/pages/WorkspaceSwitcherPage/index.tsx b/src/pages/WorkspaceSwitcherPage/index.tsx index 4651fef82f3c..3e9301a96c42 100644 --- a/src/pages/WorkspaceSwitcherPage/index.tsx +++ b/src/pages/WorkspaceSwitcherPage/index.tsx @@ -1,6 +1,5 @@ import {useIsFocused} from '@react-navigation/native'; import React, {useCallback, useMemo} from 'react'; -import {InteractionManager} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import * as Expensicons from '@components/Icon/Expensicons'; @@ -12,7 +11,6 @@ import useActiveWorkspace from '@hooks/useActiveWorkspace'; import useDebouncedState from '@hooks/useDebouncedState'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; -import getPlatform from '@libs/getPlatform'; import Navigation from '@libs/Navigation/Navigation'; import * as PolicyUtils from '@libs/PolicyUtils'; import {sortWorkspacesBySelected} from '@libs/PolicyUtils'; @@ -22,6 +20,7 @@ import type {BrickRoad} from '@libs/WorkspacesSettingsUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import switchPolicyAfterInteractions from './switchPolicyAfterInteractions'; import WorkspaceCardCreateAWorkspace from './WorkspaceCardCreateAWorkspace'; type WorkspaceListItem = { @@ -91,14 +90,7 @@ function WorkspaceSwitcherPage() { if (newPolicyID !== activeWorkspaceID) { // On native platforms, we will see a blank screen if we navigate to a new HomeScreen route while navigating back at the same time. // Therefore we delay switching the workspace until after back navigation, using the InteractionManager. - const platform = getPlatform(); - if (platform === CONST.PLATFORM.IOS || platform === CONST.PLATFORM.ANDROID) { - InteractionManager.runAfterInteractions(() => { - Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); - }); - } else { - Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); - } + switchPolicyAfterInteractions(newPolicyID); } }, [activeWorkspaceID, setActiveWorkspaceID, isFocused], diff --git a/src/pages/WorkspaceSwitcherPage/switchPolicyAfterInteractions/index.native.tsx b/src/pages/WorkspaceSwitcherPage/switchPolicyAfterInteractions/index.native.tsx new file mode 100644 index 000000000000..a3df127564b1 --- /dev/null +++ b/src/pages/WorkspaceSwitcherPage/switchPolicyAfterInteractions/index.native.tsx @@ -0,0 +1,10 @@ +import {InteractionManager} from 'react-native'; +import Navigation from '@libs/Navigation/Navigation'; + +function switchPolicyAfterInteractions(newPolicyID: string | undefined) { + InteractionManager.runAfterInteractions(() => { + Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); + }); +} + +export default switchPolicyAfterInteractions; diff --git a/src/pages/WorkspaceSwitcherPage/switchPolicyAfterInteractions/index.tsx b/src/pages/WorkspaceSwitcherPage/switchPolicyAfterInteractions/index.tsx new file mode 100644 index 000000000000..612759a8601c --- /dev/null +++ b/src/pages/WorkspaceSwitcherPage/switchPolicyAfterInteractions/index.tsx @@ -0,0 +1,7 @@ +import Navigation from '@libs/Navigation/Navigation'; + +function switchPolicyAfterInteractions(newPolicyID: string | undefined) { + Navigation.navigateWithSwitchPolicyID({policyID: newPolicyID}); +} + +export default switchPolicyAfterInteractions; From 55b7ab4dcd715a242f47b01037730002a363cc41 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Thu, 19 Dec 2024 11:45:28 +0100 Subject: [PATCH 14/14] fix: default-value-for-inexistent-IDs issues --- src/components/WorkspaceSwitcherButton.tsx | 2 +- src/libs/Navigation/AppNavigator/AuthScreens.tsx | 4 ++-- src/pages/WorkspaceSwitcherPage/index.tsx | 2 +- src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/WorkspaceSwitcherButton.tsx b/src/components/WorkspaceSwitcherButton.tsx index fa0080c9eff1..cc875c25d14e 100644 --- a/src/components/WorkspaceSwitcherButton.tsx +++ b/src/components/WorkspaceSwitcherButton.tsx @@ -36,7 +36,7 @@ function WorkspaceSwitcherButton({policy}: WorkspaceSwitcherButtonProps) { source: avatar, name: policy?.name ?? '', type: CONST.ICON_TYPE_WORKSPACE, - id: policy?.id ?? '-1', + id: policy?.id ?? CONST.DEFAULT_NUMBER_ID, }; }, [policy]); diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index b4a6f4f1129c..e3f34ea3bea3 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -148,7 +148,7 @@ Onyx.connect({ return; } - currentAccountID = value.accountID ?? -1; + currentAccountID = value.accountID ?? CONST.DEFAULT_NUMBER_ID; if (Navigation.isActiveRoute(ROUTES.SIGN_IN_MODAL)) { // This means sign in in RHP was successful, so we can subscribe to user events @@ -250,7 +250,7 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie } const initialReport = ReportUtils.findLastAccessedReport(!canUseDefaultRooms, shouldOpenOnAdminRoom(), activeWorkspaceID); - return initialReport?.reportID ?? ''; + return initialReport?.reportID; }); useEffect(() => { diff --git a/src/pages/WorkspaceSwitcherPage/index.tsx b/src/pages/WorkspaceSwitcherPage/index.tsx index 3e9301a96c42..cb52c52cb64c 100644 --- a/src/pages/WorkspaceSwitcherPage/index.tsx +++ b/src/pages/WorkspaceSwitcherPage/index.tsx @@ -105,7 +105,7 @@ function WorkspaceSwitcherPage() { .filter((policy) => PolicyUtils.shouldShowPolicy(policy, !!isOffline, currentUserLogin) && !policy?.isJoinRequestPending) .map((policy) => ({ text: policy?.name ?? '', - policyID: policy?.id ?? '-1', + policyID: policy?.id, brickRoadIndicator: getIndicatorTypeForPolicy(policy?.id), icons: [ { diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx index 0dcb1124ee3e..a1e4f0e4a22a 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx @@ -21,7 +21,7 @@ function BaseSidebarScreen() { const activeWorkspaceID = useActiveWorkspaceFromNavigationState(); const {translate} = useLocalize(); const {shouldUseNarrowLayout} = useResponsiveLayout(); - const [activeWorkspace] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? -1}`); + const [activeWorkspace] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID ?? CONST.DEFAULT_NUMBER_ID}`); useEffect(() => { Performance.markStart(CONST.TIMING.SIDEBAR_LOADED);