-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Make onboarding continue from last visited onboarding page #48137
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e6e271d
Make onboarding continue from last visited onboarding page
tsa321 b862e13
Fix onboarding navigation issues, briefly visible purpose and wrong g…
tsa321 514d56f
Fix lint errors
tsa321 d425363
Merge branch 'main' into makeOnboardContinue
tsa321 5eed809
Remove path parameter on work route
tsa321 16862d2
Merge main and resolve conflict
tsa321 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import {findFocusedRoute, getStateFromPath} from '@react-navigation/native'; | ||
import type {NavigationState, PartialState} from '@react-navigation/native'; | ||
import Onyx from 'react-native-onyx'; | ||
import linkingConfig from '@libs/Navigation/linkingConfig'; | ||
import getAdaptedStateFromPath from '@libs/Navigation/linkingConfig/getAdaptedStateFromPath'; | ||
import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; | ||
import type {NavigationPartialRoute, RootStackParamList} from '@libs/Navigation/types'; | ||
import CONST from '@src/CONST'; | ||
import NAVIGATORS from '@src/NAVIGATORS'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
import SCREENS from '@src/SCREENS'; | ||
|
||
let selectedPurpose: string | undefined = ''; | ||
Onyx.connect({ | ||
key: ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, | ||
callback: (value) => { | ||
selectedPurpose = value; | ||
}, | ||
}); | ||
|
||
let onboardingInitialPath = ''; | ||
const onboardingLastVisitedPathConnection = Onyx.connect({ | ||
key: ONYXKEYS.ONBOARDING_LAST_VISITED_PATH, | ||
callback: (value) => { | ||
if (value === undefined) { | ||
return; | ||
} | ||
onboardingInitialPath = value; | ||
Onyx.disconnect(onboardingLastVisitedPathConnection); | ||
}, | ||
}); | ||
|
||
/** | ||
* Build the correct stack order for `onboardingModalNavigator`, | ||
* based on onboarding data (currently from the selected purpose). | ||
* The correct stack order will ensure that navigation and | ||
* the `goBack` navigatoin work properly. | ||
*/ | ||
function adaptOnboardingRouteState() { | ||
const currentRoute: NavigationPartialRoute | undefined = navigationRef.getCurrentRoute(); | ||
if (!currentRoute || currentRoute?.name === SCREENS.ONBOARDING.PURPOSE) { | ||
return; | ||
} | ||
|
||
const rootState = navigationRef.getRootState(); | ||
const adaptedState = rootState; | ||
const lastRouteIndex = (adaptedState?.routes?.length ?? 0) - 1; | ||
const onBoardingModalNavigatorState = adaptedState?.routes[lastRouteIndex]?.state; | ||
if (!onBoardingModalNavigatorState || onBoardingModalNavigatorState?.routes?.length > 1) { | ||
return; | ||
} | ||
|
||
let adaptedOnboardingModalNavigatorState = {} as Readonly<PartialState<NavigationState>>; | ||
if (currentRoute?.name === SCREENS.ONBOARDING.PERSONAL_DETAILS && selectedPurpose === CONST.ONBOARDING_CHOICES.MANAGE_TEAM) { | ||
adaptedOnboardingModalNavigatorState = { | ||
index: 2, | ||
routes: [ | ||
{ | ||
name: SCREENS.ONBOARDING.PURPOSE, | ||
params: currentRoute?.params, | ||
}, | ||
{ | ||
name: SCREENS.ONBOARDING.WORK, | ||
params: currentRoute?.params, | ||
path: '/onboarding/works', | ||
}, | ||
{...currentRoute}, | ||
], | ||
} as Readonly<PartialState<NavigationState>>; | ||
} else { | ||
adaptedOnboardingModalNavigatorState = { | ||
index: 1, | ||
routes: [ | ||
{ | ||
name: SCREENS.ONBOARDING.PURPOSE, | ||
params: currentRoute?.params, | ||
}, | ||
{...currentRoute}, | ||
], | ||
} as Readonly<PartialState<NavigationState>>; | ||
} | ||
|
||
adaptedState.routes[lastRouteIndex].state = adaptedOnboardingModalNavigatorState; | ||
navigationRef.resetRoot(adaptedState); | ||
} | ||
|
||
/** | ||
* Start a new onboarding flow or continue from the last visited onboarding page. | ||
*/ | ||
function startOnboardingFlow() { | ||
const currentRoute = navigationRef.getCurrentRoute(); | ||
const {adaptedState} = getAdaptedStateFromPath(getOnboardingInitialPath(), linkingConfig.config, false); | ||
const focusedRoute = findFocusedRoute(adaptedState as PartialState<NavigationState<RootStackParamList>>); | ||
if (focusedRoute?.name === currentRoute?.name) { | ||
return; | ||
} | ||
navigationRef.resetRoot(adaptedState); | ||
} | ||
|
||
function getOnboardingInitialPath(): string { | ||
const state = getStateFromPath(onboardingInitialPath, linkingConfig.config); | ||
if (state?.routes?.at(-1)?.name !== NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR) { | ||
return `/${ROUTES.ONBOARDING_ROOT.route}`; | ||
} | ||
|
||
return onboardingInitialPath; | ||
} | ||
|
||
function clearInitialPath() { | ||
onboardingInitialPath = ''; | ||
} | ||
|
||
/** | ||
* Onboarding flow: Go back to the previous page. | ||
* Since there is no `initialRoute` for `onBoardingModalNavigator`, | ||
* firstly, adjust the current onboarding modal navigator to establish the correct stack order. | ||
* Then, navigate to the previous onboarding page using the usual `goBack` function. | ||
*/ | ||
function goBack() { | ||
adaptOnboardingRouteState(); | ||
Navigation.isNavigationReady().then(() => { | ||
Navigation.goBack(); | ||
}); | ||
} | ||
|
||
export {getOnboardingInitialPath, startOnboardingFlow, clearInitialPath, goBack}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import Navigation from '@libs/Navigation/Navigation'; | |
import * as ValidationUtils from '@libs/ValidationUtils'; | ||
import * as Policy from '@userActions/Policy/Policy'; | ||
import * as Welcome from '@userActions/Welcome'; | ||
import * as OnboardingFlow from '@userActions/Welcome/OnboardingFlow'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
|
@@ -81,7 +82,7 @@ function BaseOnboardingWork({shouldUseNativeStyles, onboardingPurposeSelected, o | |
<HeaderWithBackButton | ||
shouldShowBackButton | ||
progressBarPercentage={OPEN_WORK_PAGE_PURPOSES.includes(onboardingPurposeSelected ?? '') ? 50 : 75} | ||
onBackButtonPress={Navigation.goBack} | ||
onBackButtonPress={OnboardingFlow.goBack} | ||
/> | ||
<FormProvider | ||
style={[styles.flexGrow1, isMediumOrLargerScreenWidth && styles.mt5, isMediumOrLargerScreenWidth ? styles.mh8 : styles.mh5]} | ||
|
@@ -111,7 +112,6 @@ function BaseOnboardingWork({shouldUseNativeStyles, onboardingPurposeSelected, o | |
shouldSaveDraft | ||
maxLength={CONST.TITLE_CHARACTER_LIMIT} | ||
spellCheck={false} | ||
autoFocus | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am removing this line because the autofocus is handled by |
||
/> | ||
</View> | ||
</FormProvider> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path is
work
singular. I think it's better we usegetRoute()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mollfpr actually we don’t need the path field, I forgot to remove it.