Skip to content

Commit

Permalink
Merge pull request #45092 from software-mansion-labs/fix-explanation-…
Browse files Browse the repository at this point in the history
…modal

[HybridApp] Fix explanation modal
  • Loading branch information
AndrewGable authored Jul 12, 2024
2 parents 58e2575 + e5f8073 commit 491d8dd
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/components/HybridAppMiddleware/index.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {useContext, useEffect, useState} from 'react';
import {NativeEventEmitter, NativeModules} from 'react-native';
import type {NativeModule} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import {InitialURLContext} from '@components/InitialURLContextProvider';
import useExitTo from '@hooks/useExitTo';
import useSplashScreen from '@hooks/useSplashScreen';
Expand All @@ -14,12 +15,23 @@ import * as Welcome from '@userActions/Welcome';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {HybridAppRoute, Route} from '@src/ROUTES';
import type {TryNewDot} from '@src/types/onyx';

type HybridAppMiddlewareProps = {
authenticated: boolean;
children: React.ReactNode;
};

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 @@ -36,6 +48,20 @@ function HybridAppMiddleware({children, authenticated}: HybridAppMiddlewareProps

const [isAccountLoading] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => account?.isLoading ?? false});
const [sessionEmail] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.email});
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]);

// In iOS, the HybridApp defines the `onReturnToOldDot` event.
// If we frequently transition from OldDot to NewDot during a single app lifecycle,
Expand Down
26 changes: 26 additions & 0 deletions src/components/HybridAppMiddleware/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type React from 'react';
import {useContext, useEffect, useState} from 'react';
import {NativeModules} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import {InitialURLContext} from '@components/InitialURLContextProvider';
import useExitTo from '@hooks/useExitTo';
import useSplashScreen from '@hooks/useSplashScreen';
Expand All @@ -13,12 +14,23 @@ import * as Welcome from '@userActions/Welcome';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {HybridAppRoute, Route} from '@src/ROUTES';
import type {TryNewDot} from '@src/types/onyx';

type HybridAppMiddlewareProps = {
authenticated: boolean;
children: React.ReactNode;
};

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 @@ -35,6 +47,20 @@ function HybridAppMiddleware({children, authenticated}: HybridAppMiddlewareProps

const [isAccountLoading] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => account?.isLoading ?? false});
const [sessionEmail] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.email});
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]);

// Save `exitTo` when we reach /transition route.
// `exitTo` should always exist during OldDot -> NewDot transitions.
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

0 comments on commit 491d8dd

Please sign in to comment.