Repository navigation
Raise test tools and the offline banner above required 2FA. #102955
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
Open
neerajbachani
wants to merge
10
commits into
Expensify:main
Choose a base branch
from
neerajbachani:fix/102574-test-tools-above-required-2fa
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+976
−71
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6628003
Raise test tools and the offline banner above required 2FA.
neerajbachani d758d63
Merge expensify/main into fix/102574-test-tools-above-required-2fa.
neerajbachani e82b687
Drop the unused Require2FAFocusedScreen export that knip flags.
neerajbachani d02b8d9
Address the required-2FA review notes.
neerajbachani 28b3eb6
Keep native test tools in the modal and show the full offline label.
neerajbachani 4c82172
Reword the portal comments so spellcheck accepts them.
neerajbachani 4f36638
Lift Android test tools above required 2FA and mute its Enter shortcu…
neerajbachani a7f5f9f
Drop the overlay comments the reviewer asked to remove.
neerajbachani b6b66b8
Merge upstream/main into fix/102574-test-tools-above-required-2fa.
neerajbachani a38cf47
Open test tools over required 2FA from a four-finger tap, and dim the…
neerajbachani 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 hidden or 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 hidden or 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,68 @@ | ||
| import {getDeepestFocusedScreen, isTwoFactorSetupScreen} from '@libs/Navigation/Navigation'; | ||
|
|
||
| import NAVIGATORS from '@src/NAVIGATORS'; | ||
| import SCREENS from '@src/SCREENS'; | ||
|
|
||
| import {useNavigation} from '@react-navigation/core'; | ||
|
|
||
| import useRootNavigationState from './useRootNavigationState'; | ||
| import useShouldShowRequire2FAPage from './useShouldShowRequire2FAPage'; | ||
|
|
||
| /** | ||
| * Portal host rendered above the required-2FA overlay. | ||
| * Test tools render here only while that overlay is covering the root stack. | ||
| */ | ||
| const REQUIRE_2FA_ABOVE_PORTAL_HOST = 'require2FAAbove'; | ||
|
|
||
| const REQUIRE_2FA_FOCUSED_SCREEN = { | ||
| OTHER: 0, | ||
| TWO_FACTOR_SETUP: 1, | ||
| TEST_TOOLS: 2, | ||
| } as const; | ||
|
|
||
| type Require2FAFocusedScreen = (typeof REQUIRE_2FA_FOCUSED_SCREEN)[keyof typeof REQUIRE_2FA_FOCUSED_SCREEN]; | ||
|
|
||
| const TEST_TOOLS_SCREENS = new Set<string>([NAVIGATORS.TEST_TOOLS_MODAL_NAVIGATOR, SCREENS.TEST_TOOLS_MODAL.ROOT, SCREENS.TEST_TOOLS_MODAL.SERVER]); | ||
|
|
||
| /** | ||
| * Classifies the focused screen for the required-2FA overlay. | ||
| * Returns a primitive so navigation listeners can skip unchanged values. | ||
| */ | ||
| function getRequire2FAFocusedScreen(screenName: string | undefined): Require2FAFocusedScreen { | ||
| if (isTwoFactorSetupScreen(screenName)) { | ||
| return REQUIRE_2FA_FOCUSED_SCREEN.TWO_FACTOR_SETUP; | ||
| } | ||
| if (screenName && TEST_TOOLS_SCREENS.has(screenName)) { | ||
| return REQUIRE_2FA_FOCUSED_SCREEN.TEST_TOOLS; | ||
| } | ||
| return REQUIRE_2FA_FOCUSED_SCREEN.OTHER; | ||
| } | ||
|
|
||
| type Require2FAOverlayVisibility = { | ||
| /** The blocking required-2FA screen is mounted over the app. */ | ||
| isRequire2FAOverlayVisible: boolean; | ||
| /** Test tools are the focused route, so they must sit above the overlay and take input. */ | ||
| isTestToolsRouteFocused: boolean; | ||
| }; | ||
|
|
||
| /** | ||
| * Shared by the required-2FA overlay and the test-tools navigator. | ||
| * Test tools move above the overlay only while the overlay is covering the root stack. | ||
| */ | ||
| function useRequire2FAOverlayVisibility(): Require2FAOverlayVisibility { | ||
| const navigation = useNavigation(); | ||
| const shouldShowRequire2FAPage = useShouldShowRequire2FAPage(); | ||
| const focusedScreen = useRootNavigationState((state) => { | ||
| // When navigation is not ready yet, use the navigation state from the navigation hook. | ||
| const screenName = getDeepestFocusedScreen(state ?? navigation.getState())?.name; | ||
| return getRequire2FAFocusedScreen(screenName); | ||
| }); | ||
|
|
||
| return { | ||
| isRequire2FAOverlayVisible: shouldShowRequire2FAPage && focusedScreen !== REQUIRE_2FA_FOCUSED_SCREEN.TWO_FACTOR_SETUP, | ||
| isTestToolsRouteFocused: focusedScreen === REQUIRE_2FA_FOCUSED_SCREEN.TEST_TOOLS, | ||
| }; | ||
| } | ||
|
|
||
| export default useRequire2FAOverlayVisibility; | ||
| export {REQUIRE_2FA_ABOVE_PORTAL_HOST, REQUIRE_2FA_FOCUSED_SCREEN, getRequire2FAFocusedScreen}; | ||
This file contains hidden or 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,21 @@ | ||
| import toggleTestToolsModal from '@userActions/TestTool'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
|
|
||
| import {useState} from 'react'; | ||
| import {PanResponder} from 'react-native'; | ||
|
|
||
| /** Four-finger tap that opens test tools. Shared by screen wrappers and the required-2FA overlay, which sits above those screens. */ | ||
| function useTestToolsTapResponder() { | ||
| const [panHandlers] = useState( | ||
| () => | ||
| PanResponder.create({ | ||
| onStartShouldSetPanResponderCapture: (_event, gestureState) => gestureState.numberActiveTouches === CONST.TEST_TOOL.NUMBER_OF_TAPS, | ||
| onPanResponderRelease: toggleTestToolsModal, | ||
| }).panHandlers, | ||
| ); | ||
|
|
||
| return panHandlers; | ||
| } | ||
|
|
||
| export default useTestToolsTapResponder; |
This file contains hidden or 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
19 changes: 19 additions & 0 deletions
19
src/libs/Navigation/AppNavigator/Navigators/TestToolsLiftContext.ts
This file contains hidden or 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,19 @@ | ||
| import type {CardAnimationContext} from '@react-navigation/stack'; | ||
| import type {ContextType} from 'react'; | ||
|
|
||
| import {createContext} from 'react'; | ||
|
|
||
| type TestToolsLift = { | ||
| /** Move the focused screen into the portal host above the required-2FA overlay. */ | ||
| shouldLift: boolean; | ||
|
|
||
| /** Card animation of the root test-tools modal, captured before the nested stack replaces it. */ | ||
| cardAnimation: ContextType<typeof CardAnimationContext>; | ||
| }; | ||
|
|
||
| const TestToolsLiftContext = createContext<TestToolsLift>({ | ||
| shouldLift: false, | ||
| cardAnimation: undefined, | ||
| }); | ||
|
|
||
| export default TestToolsLiftContext; |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.