Skip to content
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

Fix RHP slide animation when opening sign in modal #43985

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/FocusTrap/FocusTrapForScreen/index.web.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import {useFocusEffect, useIsFocused, useRoute} from '@react-navigation/native';
import FocusTrap from 'focus-trap-react';
import React, {useCallback, useMemo} from 'react';
import {useOnyx} from 'react-native-onyx';
import BOTTOM_TAB_SCREENS from '@components/FocusTrap/BOTTOM_TAB_SCREENS';
import SCREENS_WITH_AUTOFOCUS from '@components/FocusTrap/SCREENS_WITH_AUTOFOCUS';
import getScreenWithAutofocus from '@components/FocusTrap/SCREENS_WITH_AUTOFOCUS';
import sharedTrapStack from '@components/FocusTrap/sharedTrapStack';
import TOP_TAB_SCREENS from '@components/FocusTrap/TOP_TAB_SCREENS';
import WIDE_LAYOUT_INACTIVE_SCREENS from '@components/FocusTrap/WIDE_LAYOUT_INACTIVE_SCREENS';
import useWindowDimensions from '@hooks/useWindowDimensions';
import ONYXKEYS from '@src/ONYXKEYS';
import type FocusTrapProps from './FocusTrapProps';

let activeRouteName = '';
function FocusTrapForScreen({children}: FocusTrapProps) {
const isFocused = useIsFocused();
const route = useRoute();
const {isSmallScreenWidth} = useWindowDimensions();
const [isAuthenticated] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => !!session?.authToken});
const screensWithAutofocus = useMemo(() => getScreenWithAutofocus(!!isAuthenticated), [isAuthenticated]);

const isActive = useMemo(() => {
// Focus trap can't be active on bottom tab screens because it would block access to the tab bar.
Expand Down Expand Up @@ -49,13 +53,13 @@ function FocusTrapForScreen({children}: FocusTrapProps) {
fallbackFocus: document.body,
// We don't want to ovverride autofocus on these screens.
initialFocus: () => {
if (SCREENS_WITH_AUTOFOCUS.includes(activeRouteName)) {
if (screensWithAutofocus.includes(activeRouteName)) {
return false;
}
return undefined;
},
setReturnFocus: (element) => {
if (SCREENS_WITH_AUTOFOCUS.includes(activeRouteName)) {
if (screensWithAutofocus.includes(activeRouteName)) {
return false;
}
return element;
Expand Down
11 changes: 10 additions & 1 deletion src/components/FocusTrap/SCREENS_WITH_AUTOFOCUS.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {CENTRAL_PANE_WORKSPACE_SCREENS} from '@libs/Navigation/AppNavigator/Navigators/FullScreenNavigator';
import NAVIGATORS from '@src/NAVIGATORS';
import SCREENS from '@src/SCREENS';

const SCREENS_WITH_AUTOFOCUS: string[] = [
Expand All @@ -10,6 +11,14 @@ const SCREENS_WITH_AUTOFOCUS: string[] = [
SCREENS.SETTINGS.PROFILE.PRONOUNS,
SCREENS.NEW_TASK.DETAILS,
SCREENS.MONEY_REQUEST.CREATE,
SCREENS.SIGN_IN_ROOT,
];

export default SCREENS_WITH_AUTOFOCUS;
function getScreenWithAutofocus(isAuthenticated: boolean) {
if (!isAuthenticated) {
return [...SCREENS_WITH_AUTOFOCUS, NAVIGATORS.BOTTOM_TAB_NAVIGATOR];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sign in page route name is NAVIGATORS.BOTTOM_TAB_NAVIGATOR, but auth screen also has NAVIGATORS.BOTTOM_TAB_NAVIGATOR, so I conditionally added it only if we are not authenticated.

}
return SCREENS_WITH_AUTOFOCUS;
}

export default getScreenWithAutofocus;
1 change: 0 additions & 1 deletion src/pages/signin/LoginForm/BaseLoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ function BaseLoginForm({account, credentials, closeAccount, blurOnSubmit = false
onSubmitEditing={validateAndSubmitForm}
autoCapitalize="none"
autoCorrect={false}
autoFocus
inputMode={CONST.INPUT_MODE.EMAIL}
errorText={formError}
hasError={shouldShowServerError}
Expand Down
Loading