diff --git a/native/account/registration/avatar-selection.react.js b/native/account/registration/avatar-selection.react.js
--- a/native/account/registration/avatar-selection.react.js
+++ b/native/account/registration/avatar-selection.react.js
@@ -21,7 +21,14 @@
type UserAvatarSelection,
} from '../../avatars/edit-user-avatar-provider.react.js';
import EditUserAvatar from '../../avatars/edit-user-avatar.react.js';
-import type { NavigationRoute } from '../../navigation/route-names.js';
+import { useCurrentLeafRouteName } from '../../navigation/nav-selectors.js';
+import {
+ type NavigationRoute,
+ RegistrationTermsRouteName,
+ AvatarSelectionRouteName,
+ EmojiAvatarSelectionRouteName,
+ RegistrationUserAvatarCameraModalRouteName,
+} from '../../navigation/route-names.js';
import { useStyles } from '../../themes/colors.js';
export type AvatarSelectionParams = {
@@ -46,8 +53,7 @@
const registrationContext = React.useContext(RegistrationContext);
invariant(registrationContext, 'registrationContext should be set');
- const { cachedSelections, setCachedSelections, register } =
- registrationContext;
+ const { cachedSelections, setCachedSelections } = registrationContext;
const editUserAvatarContext = React.useContext(EditUserAvatarContext);
invariant(editUserAvatarContext, 'editUserAvatarContext should be set');
@@ -107,11 +113,13 @@
[setCachedSelections],
);
- const [registrationInProgress, setRegistrationInProgress] =
- React.useState(false);
-
+ const currentRouteName = useCurrentLeafRouteName();
+ const avatarSelectionHappening =
+ currentRouteName === AvatarSelectionRouteName ||
+ currentRouteName === EmojiAvatarSelectionRouteName ||
+ currentRouteName === RegistrationUserAvatarCameraModalRouteName;
React.useEffect(() => {
- if (registrationInProgress) {
+ if (!avatarSelectionHappening) {
return undefined;
}
setRegistrationMode({
@@ -122,22 +130,22 @@
setRegistrationMode({ registrationMode: 'off' });
};
}, [
- registrationInProgress,
+ avatarSelectionHappening,
setRegistrationMode,
setClientAvatarFromSelection,
]);
+ const { navigate } = props.navigation;
const onProceed = React.useCallback(async () => {
- setRegistrationInProgress(true);
- try {
- await register({
- ...userSelections,
- avatarData,
- });
- } finally {
- setRegistrationInProgress(false);
- }
- }, [register, userSelections, avatarData]);
+ const newUserSelections = {
+ ...userSelections,
+ avatarData,
+ };
+ navigate<'RegistrationTerms'>({
+ name: RegistrationTermsRouteName,
+ params: { userSelections: newUserSelections },
+ });
+ }, [userSelections, avatarData, navigate]);
const clientAvatar = avatarData?.clientAvatar;
const userInfoOverride = React.useMemo(
@@ -157,18 +165,13 @@
-
+
);
diff --git a/native/account/registration/registration-terms.react.js b/native/account/registration/registration-terms.react.js
--- a/native/account/registration/registration-terms.react.js
+++ b/native/account/registration/registration-terms.react.js
@@ -1,5 +1,6 @@
// @flow
+import invariant from 'invariant';
import * as React from 'react';
import { Text } from 'react-native';
@@ -7,6 +8,7 @@
import RegistrationButton from './registration-button.react.js';
import RegistrationContainer from './registration-container.react.js';
import RegistrationContentContainer from './registration-content-container.react.js';
+import { RegistrationContext } from './registration-context.js';
import type { RegistrationNavigationProp } from './registration-navigator.react.js';
import type {
CoolOrNerdMode,
@@ -29,9 +31,23 @@
+navigation: RegistrationNavigationProp<'RegistrationTerms'>,
+route: NavigationRoute<'RegistrationTerms'>,
};
-// eslint-disable-next-line no-unused-vars
function RegistrationTerms(props: Props): React.Node {
- const onProceed = React.useCallback(() => {}, []);
+ const registrationContext = React.useContext(RegistrationContext);
+ invariant(registrationContext, 'registrationContext should be set');
+ const { register } = registrationContext;
+
+ const [registrationInProgress, setRegistrationInProgress] =
+ React.useState(false);
+
+ const { userSelections } = props.route.params;
+ const onProceed = React.useCallback(async () => {
+ setRegistrationInProgress(true);
+ try {
+ await register(userSelections);
+ } finally {
+ setRegistrationInProgress(false);
+ }
+ }, [register, userSelections]);
const styles = useStyles(unboundStyles);
return (
@@ -43,7 +59,7 @@
diff --git a/native/navigation/nav-selectors.js b/native/navigation/nav-selectors.js
--- a/native/navigation/nav-selectors.js
+++ b/native/navigation/nav-selectors.js
@@ -15,6 +15,7 @@
import {
getStateFromNavigatorRoute,
getThreadIDFromRoute,
+ currentLeafRoute,
} from './navigation-utils.js';
import {
AppRouteName,
@@ -315,6 +316,16 @@
},
);
+function useCurrentLeafRouteName(): ?string {
+ const navContext = React.useContext(NavContext);
+ return React.useMemo(() => {
+ if (!navContext) {
+ return undefined;
+ }
+ return currentLeafRoute(navContext.state).name;
+ }, [navContext]);
+}
+
export {
createIsForegroundSelector,
useIsAppLoggedIn,
@@ -330,4 +341,5 @@
nonThreadCalendarQuery,
useCalendarQuery,
drawerSwipeEnabledSelector,
+ useCurrentLeafRouteName,
};