Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HybridApp] Allow classic experience users to use NewDot travel page #49602

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/components/ScreenWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {useIsFocused, useNavigation} from '@react-navigation/native';
import {UNSTABLE_usePreventRemove, useIsFocused, useNavigation, useRoute} from '@react-navigation/native';
import type {StackNavigationProp} from '@react-navigation/stack';
import type {ForwardedRef, ReactNode} from 'react';
import React, {createContext, forwardRef, useEffect, useMemo, useRef, useState} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {Keyboard, PanResponder, View} from 'react-native';
import {Keyboard, NativeModules, PanResponder, View} from 'react-native';
import {PickerAvoidingView} from 'react-native-picker-select';
import type {EdgeInsets} from 'react-native-safe-area-context';
import useEnvironment from '@hooks/useEnvironment';
Expand All @@ -15,6 +15,7 @@ import useTackInputFocus from '@hooks/useTackInputFocus';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as Browser from '@libs/Browser';
import Navigation from '@libs/Navigation/Navigation';
import type {AuthScreensParamList, RootStackParamList} from '@libs/Navigation/types';
import toggleTestToolsModal from '@userActions/TestTool';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -160,6 +161,16 @@ function ScreenWrapper(

isKeyboardShownRef.current = keyboardState?.isKeyboardShown ?? false;

const route = useRoute();
const shouldReturnToOldDot = useMemo(() => {
return !!(route?.params && 'singleNewDotEntry' in route.params && route?.params?.singleNewDotEntry === 'true');
}, [route]);

UNSTABLE_usePreventRemove(shouldReturnToOldDot, () => {
Navigation.setParams({singleNewDotEntry: undefined});
NativeModules.HybridAppModule.closeReactNativeApp(false, false);
});

const panResponder = useRef(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify for reviewers, it is stable 😄 The same code is present in the react-navigation v7 just without UNSTABLE prefix.

However, this is an argument for considering upgrading to v7. We see other use cases where features from v7 would also be useful.

PanResponder.create({
onStartShouldSetPanResponderCapture: (_e, gestureState) => gestureState.numberActiveTouches === CONST.TEST_TOOL.NUMBER_OF_TAPS,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ function signInAfterTransitionFromOldDot(transitionURL: string) {
Log.hmmm('[HybridApp] Initialization of HybridApp has failed. Forcing transition', {error});
})
.finally(() => {
resolve(route as Route);
resolve(`${route}?singleNewDotEntry=${shouldReturnToOldDotAfterBooking}` as Route);
});
});

Expand Down
18 changes: 1 addition & 17 deletions src/pages/Travel/MyTripsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
import React, {useCallback} from 'react';
import {NativeModules} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import React from 'react';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import useLocalize from '@hooks/useLocalize';
import usePermissions from '@hooks/usePermissions';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import ONYXKEYS from '@src/ONYXKEYS';
import ManageTrips from './ManageTrips';

function MyTripsPage() {
const {translate} = useLocalize();
const {canUseSpotnanaTravel} = usePermissions();
const [shouldReturnToOldDotAfterBooking] = useOnyx(ONYXKEYS.SHOULD_RETURN_TO_OLD_DOT_AFTER_BOOKING);

const onBackButtonPress = useCallback(() => {
if (NativeModules.HybridAppModule && shouldReturnToOldDotAfterBooking) {
Log.info('[HybridApp] Returning to OldDot after closing MyTripsPage');
NativeModules.HybridAppModule.closeReactNativeApp(false, false);
return;
}
Navigation.goBack();
}, [shouldReturnToOldDotAfterBooking]);

return (
<ScreenWrapper
Expand All @@ -40,7 +25,6 @@ function MyTripsPage() {
<HeaderWithBackButton
title={translate('travel.header')}
shouldShowBackButton
onBackButtonPress={onBackButtonPress}
/>
<ManageTrips />
</FullPageNotFoundView>
Expand Down
Loading