-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathindex.tsx
210 lines (196 loc) · 9.35 KB
/
index.tsx
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import type {ForwardedRef} from 'react';
import React, {forwardRef, useEffect, useImperativeHandle, useMemo, useRef} from 'react';
// eslint-disable-next-line no-restricted-imports
import type {ScrollView as RNScrollView} from 'react-native';
import {View} from 'react-native';
import SignInGradient from '@assets/images/home-fade-gradient.svg';
import ImageSVG from '@components/ImageSVG';
import ScrollView from '@components/ScrollView';
import useLocalize from '@hooks/useLocalize';
import usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useSafeAreaInsets from '@hooks/useSafeAreaInsets';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as Browser from '@libs/Browser';
import DomUtils from '@libs/DomUtils';
import getPlatform from '@libs/getPlatform';
// eslint-disable-next-line no-restricted-imports
import themes from '@styles/theme';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import BackgroundImage from './BackgroundImage';
import Footer from './Footer';
import SignInPageContent from './SignInPageContent';
import SignInPageHero from './SignInPageHero';
import scrollViewContentContainerStyles from './signInPageStyles';
import type {SignInPageLayoutProps, SignInPageLayoutRef} from './types';
function SignInPageLayout(
{
customHeadline,
customHeroBody,
shouldShowWelcomeHeader = false,
welcomeHeader,
welcomeText = '',
shouldShowWelcomeText = false,
navigateFocus = () => {},
children,
}: SignInPageLayoutProps,
ref: ForwardedRef<SignInPageLayoutRef>,
) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {preferredLocale} = useLocalize();
const {top: topInsets, bottom: bottomInsets} = useSafeAreaInsets();
const scrollViewRef = useRef<RNScrollView>(null);
const prevPreferredLocale = usePrevious(preferredLocale);
const {windowHeight} = useWindowDimensions();
const {shouldUseNarrowLayout, isMediumScreenWidth, isLargeScreenWidth} = useResponsiveLayout();
const {containerStyles, contentContainerStyles} = useMemo(
() => ({
containerStyles: shouldUseNarrowLayout ? [styles.flex1] : [styles.flex1, styles.signInPageInner],
contentContainerStyles: [styles.flex1, shouldUseNarrowLayout ? styles.flexColumn : styles.flexRow],
}),
[shouldUseNarrowLayout, styles],
);
// To scroll on both mobile and web, we need to set the container height manually
const containerHeight = windowHeight - topInsets - bottomInsets;
const scrollPageToTop = (animated = false) => {
if (!scrollViewRef.current) {
return;
}
scrollViewRef.current.scrollTo({y: 0, animated});
};
useImperativeHandle(ref, () => ({
scrollPageToTop,
}));
useEffect(() => {
if (prevPreferredLocale !== preferredLocale) {
return;
}
scrollPageToTop();
}, [welcomeHeader, welcomeText, prevPreferredLocale, preferredLocale]);
const scrollViewStyles = useMemo(() => scrollViewContentContainerStyles(styles), [styles]);
const backgroundImageHeight = Math.max(variables.signInContentMinHeight, containerHeight);
/*
SignInPageLayout always has a dark theme regardless of the app theme. ThemeProvider sets auto-fill input styles globally so different ThemeProviders conflict and auto-fill input styles are incorrectly applied for this component.
Add a class to `body` when this component stays mounted and remove it when the component dismounts.
A new styleID is added with dark theme text with more specific css selector using this added cssClass.
*/
const cssClass = 'sign-in-page-layout';
DomUtils.addCSS(DomUtils.getAutofilledInputStyle(themes[CONST.THEME.DARK].text, `.${cssClass}`), 'sign-in-autofill-input');
useEffect(() => {
const isWeb = getPlatform() === CONST.PLATFORM.WEB;
const isDesktop = getPlatform() === CONST.PLATFORM.DESKTOP;
if (!isWeb && !isDesktop) {
return;
}
// add css class to body only for web and desktop
document.body.classList.add(cssClass);
return () => {
document.body.classList.remove(cssClass);
};
}, []);
return (
<View style={containerStyles}>
{!shouldUseNarrowLayout ? (
<View style={contentContainerStyles}>
<ScrollView
keyboardShouldPersistTaps="handled"
style={[styles.signInPageLeftContainerWide, styles.flex1]}
contentContainerStyle={[styles.flex1]}
>
<SignInPageContent
welcomeHeader={welcomeHeader}
welcomeText={welcomeText}
shouldShowWelcomeText={shouldShowWelcomeText}
shouldShowWelcomeHeader={shouldShowWelcomeHeader}
>
{children}
</SignInPageContent>
</ScrollView>
<ScrollView
style={[styles.flex1, StyleUtils.getBackgroundColorStyle(theme.signInPage)]}
contentContainerStyle={[styles.flex1]}
ref={scrollViewRef}
>
<View style={[styles.flex1]}>
<View style={styles.signInPageHeroCenter}>
<BackgroundImage
isSmallScreen={false}
pointerEvents="none"
width={variables.signInHeroBackgroundWidth}
transitionDuration={CONST.BACKGROUND_IMAGE_TRANSITION_DURATION}
/>
</View>
<View>
<View style={[styles.t0, styles.l0, styles.h100, styles.pAbsolute, styles.signInPageGradient]}>
<ImageSVG
src={SignInGradient}
height="100%"
preserveAspectRatio="none"
/>
</View>
<View
style={[
styles.alignSelfCenter,
StyleUtils.getMaximumWidth(variables.signInContentMaxWidth),
isMediumScreenWidth ? styles.ph10 : {},
isLargeScreenWidth ? styles.ph25 : {},
]}
>
<SignInPageHero
customHeadline={customHeadline}
customHeroBody={customHeroBody}
/>
<Footer navigateFocus={navigateFocus} />
</View>
</View>
</View>
</ScrollView>
</View>
) : (
<ScrollView
contentContainerStyle={scrollViewStyles}
keyboardShouldPersistTaps="handled"
ref={scrollViewRef}
>
<View
style={[
styles.flex1,
styles.flexColumn,
Browser.isMobileSafari() ? styles.overflowHidden : {},
StyleUtils.getMinimumHeight(backgroundImageHeight),
StyleUtils.getSignInBgStyles(theme),
]}
>
<View style={[styles.pAbsolute, styles.w100, StyleUtils.getHeight(backgroundImageHeight), StyleUtils.getBackgroundColorStyle(theme.highlightBG)]}>
<BackgroundImage
isSmallScreen
pointerEvents="none"
width={variables.signInHeroBackgroundWidthMobile}
transitionDuration={CONST.BACKGROUND_IMAGE_TRANSITION_DURATION}
/>
</View>
<SignInPageContent
welcomeHeader={welcomeHeader}
welcomeText={welcomeText}
shouldShowWelcomeText={shouldShowWelcomeText}
shouldShowWelcomeHeader={shouldShowWelcomeHeader}
>
{children}
</SignInPageContent>
</View>
<View style={[styles.flex0]}>
<Footer navigateFocus={navigateFocus} />
</View>
</ScrollView>
)}
</View>
);
}
SignInPageLayout.displayName = 'SignInPageLayout';
export default forwardRef(SignInPageLayout);