diff --git a/native/components/nux-tips-context.react.js b/native/components/nux-tips-context.react.js --- a/native/components/nux-tips-context.react.js +++ b/native/components/nux-tips-context.react.js @@ -25,45 +25,39 @@ type NUXTipParams = { +nextTip: ?NUXTip, +tooltipLocation: 'below' | 'above' | 'absolute', - +nextRouteName: ?NUXTipRouteNames, + +routeName: NUXTipRouteNames, +exitingCallback?: ( navigation: AppNavigationProp, ) => void, }; -const firstNUXTipKey = 'firstTip'; -type NUXTipParamsKeys = NUXTip | 'firstTip'; +const firstNUXTipKey = nuxTip.INTRO; -const nuxTipParams: { +[NUXTipParamsKeys]: NUXTipParams } = { - [firstNUXTipKey]: { - nextTip: nuxTip.INTRO, - tooltipLocation: 'absolute', - nextRouteName: IntroTipRouteName, - }, +const nuxTipParams: { +[NUXTip]: NUXTipParams } = { [nuxTip.INTRO]: { nextTip: nuxTip.COMMUNITY_DRAWER, - tooltipLocation: 'below', - nextRouteName: CommunityDrawerTipRouteName, + tooltipLocation: 'absolute', + routeName: IntroTipRouteName, }, [nuxTip.COMMUNITY_DRAWER]: { nextTip: nuxTip.HOME, tooltipLocation: 'below', - nextRouteName: HomeTabTipRouteName, + routeName: CommunityDrawerTipRouteName, }, [nuxTip.HOME]: { nextTip: nuxTip.MUTED, tooltipLocation: 'below', - nextRouteName: MutedTabTipRouteName, + routeName: HomeTabTipRouteName, }, [nuxTip.MUTED]: { nextTip: undefined, - nextRouteName: undefined, + routeName: MutedTabTipRouteName, tooltipLocation: 'below', exitingCallback: navigation => navigation.goBack(), }, }; -function getNUXTipParams(currentTipKey: NUXTipParamsKeys): NUXTipParams { +function getNUXTipParams(currentTipKey: NUXTip): NUXTipParams { return nuxTipParams[currentTipKey]; } @@ -109,7 +103,7 @@ const tipsProps = React.useMemo(() => { const result: { [tip: NUXTip]: TipProps } = {}; for (const type of values(nuxTip)) { - if (type === nuxTip.INTRO) { + if (nuxTipParams[type].tooltipLocation === 'absolute') { continue; } if (!tipsPropsState[type]) { diff --git a/native/navigation/nux-tip-overlay-backdrop.react.js b/native/navigation/nux-tip-overlay-backdrop.react.js --- a/native/navigation/nux-tip-overlay-backdrop.react.js +++ b/native/navigation/nux-tip-overlay-backdrop.react.js @@ -64,17 +64,14 @@ }; }, [onExitFinish]); - const { nextTip, tooltipLocation, nextRouteName } = - getNUXTipParams(firstNUXTipKey); - invariant(nextRouteName && nextTip, 'first nux tip should be defined'); + const { routeName } = getNUXTipParams(firstNUXTipKey); React.useEffect( () => props.navigation.navigate({ - name: nextRouteName, + name: routeName, params: { - tipKey: nextTip, - tooltipLocation, + tipKey: firstNUXTipKey, }, }), // We want this effect to run exactly once, when this component is mounted diff --git a/native/tooltip/nux-tips-overlay.react.js b/native/tooltip/nux-tips-overlay.react.js --- a/native/tooltip/nux-tips-overlay.react.js +++ b/native/tooltip/nux-tips-overlay.react.js @@ -101,7 +101,6 @@ export type NUXTipsOverlayParams = { +tipKey: NUXTip, - +tooltipLocation: 'above' | 'below' | 'absolute', }; export type NUXTipsOverlayProps = { @@ -198,7 +197,8 @@ [dimensions.width, initialCoordinates, tipHorizontalOffset], ); - const { tooltipLocation } = route.params; + const tipParams = getNUXTipParams(route.params.tipKey); + const { tooltipLocation } = tipParams; const baseTipContainerStyle = React.useMemo(() => { const { y, x, height, width } = initialCoordinates; @@ -380,31 +380,25 @@ } const onPressOk = React.useCallback(() => { - const callbackParams = getNUXTipParams(route.params.tipKey); - - const { - nextTip, - tooltipLocation: nextLocation, - nextRouteName, - exitingCallback, - } = callbackParams; + const { nextTip, exitingCallback } = tipParams; goBackOnce(); if (exitingCallback) { exitingCallback?.(navigation); } - if (!nextTip || !nextRouteName) { + if (!nextTip) { return; } + const { routeName } = getNUXTipParams(nextTip); + navigation.navigate({ - name: nextRouteName, + name: routeName, params: { tipKey: nextTip, - tooltipLocation: nextLocation, }, }); - }, [goBackOnce, navigation, route.params.tipKey]); + }, [goBackOnce, navigation, tipParams]); const button = React.useMemo( () =>