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] Fix explanation modal #45092

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
28 changes: 28 additions & 0 deletions src/components/HybridAppMiddleware.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import {useNavigation} from '@react-navigation/native';
import type {StackNavigationProp} from '@react-navigation/stack';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {NativeModules} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import useSplashScreen from '@hooks/useSplashScreen';
import BootSplash from '@libs/BootSplash';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import type {RootStackParamList} from '@libs/Navigation/types';
import * as Welcome from '@userActions/Welcome';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import type {TryNewDot} from '@src/types/onyx';

type HybridAppMiddlewareProps = {
children: React.ReactNode;
Expand All @@ -24,6 +28,16 @@ const HybridAppMiddlewareContext = React.createContext<HybridAppMiddlewareContex
showSplashScreenOnNextStart: () => {},
});

const onboardingStatusSelector = (tryNewDot: OnyxEntry<TryNewDot>) => {
let completedHybridAppOnboarding = tryNewDot?.classicRedirect?.completedHybridAppOnboarding;

if (typeof completedHybridAppOnboarding === 'string') {
completedHybridAppOnboarding = completedHybridAppOnboarding === 'true';
}

return completedHybridAppOnboarding;
};

/*
* HybridAppMiddleware is responsible for handling BootSplash visibility correctly.
* It is crucial to make transitions between OldDot and NewDot look smooth.
Expand All @@ -33,6 +47,20 @@ function HybridAppMiddleware(props: HybridAppMiddlewareProps) {
const [startedTransition, setStartedTransition] = useState(false);
const [finishedTransition, setFinishedTransition] = useState(false);
const navigation = useNavigation<StackNavigationProp<RootStackParamList>>();
const [completedHybridAppOnboarding] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT, {selector: onboardingStatusSelector});

/**
* This useEffect tracks changes of `nvp_tryNewDot` value.
* We propagate it from OldDot to NewDot with native method due to limitations of old app.
*/
useEffect(() => {
if (completedHybridAppOnboarding === undefined) {
return;
}

Log.info(`[HybridApp] Onboarding status has changed. Propagating new value to OldDot`, true, {completedHybridAppOnboarding});
NativeModules.HybridAppModule.completeOnboarding(completedHybridAppOnboarding);
}, [completedHybridAppOnboarding]);

/*
* Handles navigation during transition from OldDot. For ordinary NewDot app it is just pure navigation.
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Welcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function handleHybridAppOnboarding() {
isOnboardingFlowCompleted({
onNotCompleted: () =>
setTimeout(() => {
Navigation.navigate(ROUTES.EXPLANATION_MODAL_ROOT);
Navigation.navigate(ROUTES.ONBOARDING_ROOT);
}, variables.explanationModalDelay),
}),
});
Expand Down
1 change: 1 addition & 0 deletions src/types/modules/react-native.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type StartupTimer from '@libs/StartupTimer/types';

type HybridAppModule = {
closeReactNativeApp: () => void;
completeOnboarding: (status: boolean) => void;
exitApp: () => void;
};

Expand Down
Loading