forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSignInModal.tsx
More file actions
66 lines (60 loc) · 2.88 KB
/
Copy pathSignInModal.tsx
File metadata and controls
66 lines (60 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React, {useEffect, useRef} from 'react';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import {useSession} from '@components/OnyxListItemProvider';
import ScreenWrapper from '@components/ScreenWrapper';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import {openApp} from '@libs/actions/App';
import {isMobileSafari} from '@libs/Browser';
import Navigation from '@libs/Navigation/Navigation';
import {waitForIdle} from '@libs/Network/SequentialQueue';
import CONST from '@src/CONST';
import SCREENS from '@src/SCREENS';
import SignInPageWrapped, {SignInPage} from './SignInPage';
import type {SignInPageRef} from './SignInPage';
function SignInModal() {
const theme = useTheme();
const StyleUtils = useStyleUtils();
const signinPageRef = useRef<SignInPageRef | null>(null);
const session = useSession();
// Use of SignInPageWrapped (with shouldEnableMaxHeight prop in SignInPageWrapper) is a workaround for Safari not supporting interactive-widget=resizes-content.
// This allows better scrolling experience after keyboard shows for modals with input, that are larger than remaining screen height.
// More info https://github.com/Expensify/App/pull/62799#issuecomment-2943136220.
const SignInPageBase = isMobileSafari() ? SignInPageWrapped : SignInPage;
useEffect(() => {
const isAnonymousUser = session?.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS;
if (!isAnonymousUser) {
// Signing in RHP is only for anonymous users
Navigation.isNavigationReady().then(() => {
Navigation.dismissModal();
});
// To prevent deadlock when OpenReport and OpenApp overlap, wait for the queue to be idle before calling openApp.
// This ensures that any communication gaps between the client and server during OpenReport processing do not cause the queue to pause,
// which would prevent us from processing or clearing the queue.
waitForIdle().then(() => {
openApp(true);
});
}
}, [session?.authTokenType]);
return (
<ScreenWrapper
style={[StyleUtils.getBackgroundColorStyle(theme.PAGE_THEMES[SCREENS.RIGHT_MODAL.SIGN_IN].backgroundColor)]}
includeSafeAreaPaddingBottom={false}
shouldShowOfflineIndicator={false}
testID={SignInModal.displayName}
>
<HeaderWithBackButton
onBackButtonPress={() => {
if (!signinPageRef.current) {
Navigation.goBack();
return;
}
signinPageRef.current?.navigateBack();
}}
/>
<SignInPageBase ref={signinPageRef} />
</ScreenWrapper>
);
}
SignInModal.displayName = 'SignInModal';
export default SignInModal;