Skip to content

Commit

Permalink
replace usages of shouldShowSmallScreen and isInModal props in compon…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
rayane-djouah committed Jan 19, 2024
1 parent fbff2d3 commit e299ff5
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 55 deletions.
8 changes: 3 additions & 5 deletions src/pages/signin/LoginForm/BaseLoginForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import withToggleVisibilityView from '@components/withToggleVisibilityView';
import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions';
import usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus';
import compose from '@libs/compose';
Expand Down Expand Up @@ -70,9 +71,6 @@ const propTypes = {
/** Props to detect online status */
network: networkPropTypes.isRequired,

/** Whether or not the sign in page is being rendered in the RHP modal */
isInModal: PropTypes.bool,

isVisible: PropTypes.bool.isRequired,

...windowDimensionsPropTypes,
Expand All @@ -88,7 +86,6 @@ const defaultProps = {
closeAccount: {},
blurOnSubmit: false,
innerRef: () => {},
isInModal: false,
};

function LoginForm(props) {
Expand All @@ -100,6 +97,7 @@ function LoginForm(props) {
const firstBlurred = useRef(false);
const isFocused = useIsFocused();
const isLoading = useRef(false);
const {shouldUseNarrowLayout} = useResponsiveLayout();

const {translate} = props;

Expand Down Expand Up @@ -213,7 +211,7 @@ function LoginForm(props) {
return;
}
let focusTimeout;
if (props.isInModal) {
if (shouldUseNarrowLayout) {
focusTimeout = setTimeout(() => input.current.focus(), CONST.ANIMATED_TRANSITION);
} else {
input.current.focus();
Expand Down
10 changes: 3 additions & 7 deletions src/pages/signin/SignInHeroImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@ import React from 'react';
import Lottie from '@components/Lottie';
import LottieAnimations from '@components/LottieAnimations';
import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';

const propTypes = {
...windowDimensionsPropTypes,

shouldShowSmallScreen: PropTypes.bool,
};

const defaultProps = {
shouldShowSmallScreen: false,
};

function SignInHeroImage(props) {
const styles = useThemeStyles();
const {shouldUseNarrowLayout} = useResponsiveLayout();
let imageSize;
if (props.isSmallScreenWidth || props.shouldShowSmallScreen) {
if (shouldUseNarrowLayout) {
imageSize = {
height: variables.signInHeroImageMobileHeight,
width: variables.signInHeroImageMobileWidth,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/signin/SignInModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function SignInModal() {
testID={SignInModal.displayName}
>
<HeaderWithBackButton />
<SignInPage isInModal />
<SignInPage />
</ScreenWrapper>
);
}
Expand Down
32 changes: 13 additions & 19 deletions src/pages/signin/SignInPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import CustomStatusBarAndBackground from '@components/CustomStatusBarAndBackgrou
import ThemeProvider from '@components/ThemeProvider';
import ThemeStylesProvider from '@components/ThemeStylesProvider';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useSafeAreaInsets from '@hooks/useSafeAreaInsets';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -71,17 +72,13 @@ const propTypes = {
/** Active Clients connected to ONYX Database */
activeClients: PropTypes.arrayOf(PropTypes.string),

/** Whether or not the sign in page is being rendered in the RHP modal */
isInModal: PropTypes.bool,

/** The user's preferred locale */
preferredLocale: PropTypes.string,
};

const defaultProps = {
account: {},
credentials: {},
isInModal: false,
activeClients: [],
preferredLocale: '',
};
Expand Down Expand Up @@ -132,12 +129,11 @@ function getRenderOptions({hasLogin, hasValidateCode, account, isPrimaryLogin, i
};
}

function SignInPageInner({credentials, account, isInModal, activeClients, preferredLocale}) {
function SignInPageInner({credentials, account, activeClients, preferredLocale}) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate, formatPhoneNumber} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();
const shouldShowSmallScreen = isSmallScreenWidth || isInModal;
const {shouldUseNarrowLayout} = useResponsiveLayout();
const safeAreaInsets = useSafeAreaInsets();
const signInPageLayoutRef = useRef();
const loginFormRef = useRef();
Expand Down Expand Up @@ -208,32 +204,32 @@ function SignInPageInner({credentials, account, isInModal, activeClients, prefer
welcomeHeader = translate('welcomeText.anotherLoginPageIsOpen');
welcomeText = translate('welcomeText.anotherLoginPageIsOpenExplanation');
} else if (shouldShowLoginForm) {
welcomeHeader = isSmallScreenWidth ? headerText : translate('welcomeText.getStarted');
welcomeText = isSmallScreenWidth ? translate('welcomeText.getStarted') : '';
welcomeHeader = shouldUseNarrowLayout ? headerText : translate('welcomeText.getStarted');
welcomeText = shouldUseNarrowLayout ? translate('welcomeText.getStarted') : '';
} else if (shouldShowValidateCodeForm) {
if (account.requiresTwoFactorAuth) {
// We will only know this after a user signs in successfully, without their 2FA code
welcomeHeader = isSmallScreenWidth ? '' : translate('welcomeText.welcomeBack');
welcomeHeader = shouldUseNarrowLayout ? '' : translate('welcomeText.welcomeBack');
welcomeText = isUsingRecoveryCode ? translate('validateCodeForm.enterRecoveryCode') : translate('validateCodeForm.enterAuthenticatorCode');
} else {
const userLogin = Str.removeSMSDomain(credentials.login || '');

// replacing spaces with "hard spaces" to prevent breaking the number
const userLoginToDisplay = Str.isSMSLogin(userLogin) ? formatPhoneNumber(userLogin).replace(/ /g, '\u00A0') : userLogin;
if (account.validated) {
welcomeHeader = shouldShowSmallScreen ? '' : translate('welcomeText.welcomeBack');
welcomeText = shouldShowSmallScreen
welcomeHeader = shouldUseNarrowLayout ? '' : translate('welcomeText.welcomeBack');
welcomeText = shouldUseNarrowLayout
? `${translate('welcomeText.welcomeBack')} ${translate('welcomeText.welcomeEnterMagicCode', {login: userLoginToDisplay})}`
: translate('welcomeText.welcomeEnterMagicCode', {login: userLoginToDisplay});
} else {
welcomeHeader = shouldShowSmallScreen ? '' : translate('welcomeText.welcome');
welcomeText = shouldShowSmallScreen
welcomeHeader = shouldUseNarrowLayout ? '' : translate('welcomeText.welcome');
welcomeText = shouldUseNarrowLayout
? `${translate('welcomeText.welcome')} ${translate('welcomeText.newFaceEnterMagicCode', {login: userLoginToDisplay})}`
: translate('welcomeText.newFaceEnterMagicCode', {login: userLoginToDisplay});
}
}
} else if (shouldShowUnlinkLoginForm || shouldShowEmailDeliveryFailurePage || shouldShowChooseSSOOrMagicCode) {
welcomeHeader = shouldShowSmallScreen ? headerText : translate('welcomeText.welcomeBack');
welcomeHeader = shouldUseNarrowLayout ? headerText : translate('welcomeText.welcomeBack');

// Don't show any welcome text if we're showing the user the email delivery failed view
if (shouldShowEmailDeliveryFailurePage || shouldShowChooseSSOOrMagicCode) {
Expand All @@ -251,21 +247,19 @@ function SignInPageInner({credentials, account, isInModal, activeClients, prefer
return (
// Bottom SafeAreaView is removed so that login screen svg displays correctly on mobile.
// The SVG should flow under the Home Indicator on iOS.
<View style={[styles.signInPage, StyleUtils.getSafeAreaPadding({...safeAreaInsets, bottom: 0, top: isInModal ? 0 : safeAreaInsets.top}, 1)]}>
<View style={[styles.signInPage, StyleUtils.getSafeAreaPadding({...safeAreaInsets, bottom: 0, top: shouldUseNarrowLayout ? 0 : safeAreaInsets.top}, 1)]}>
<SignInPageLayout
welcomeHeader={welcomeHeader}
welcomeText={welcomeText}
shouldShowWelcomeHeader={shouldShowWelcomeHeader || !isSmallScreenWidth || !isInModal}
shouldShowWelcomeHeader={shouldShowWelcomeHeader || !shouldUseNarrowLayout}
shouldShowWelcomeText={shouldShowWelcomeText}
ref={signInPageLayoutRef}
shouldShowSmallScreen={shouldShowSmallScreen}
navigateFocus={navigateFocus}
>
{/* LoginForm must use the isVisible prop. This keeps it mounted, but visually hidden
so that password managers can access the values. Conditionally rendering this component will break this feature. */}
<LoginForm
ref={loginFormRef}
isInModal={isInModal}
isVisible={shouldShowLoginForm}
blurOnSubmit={account.validated === false}
scrollPageToTop={signInPageLayoutRef.current && signInPageLayoutRef.current.scrollPageToTop}
Expand Down
9 changes: 3 additions & 6 deletions src/pages/signin/SignInPageLayout/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ImageSVG from '@components/ImageSVG';
import Text from '@components/Text';
import TextLink from '@components/TextLink';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand All @@ -20,11 +21,6 @@ import CONST from '@src/CONST';
const propTypes = {
...withLocalizePropTypes,
navigateFocus: PropTypes.func.isRequired,
shouldShowSmallScreen: PropTypes.bool,
};

const defaultProps = {
shouldShowSmallScreen: false,
};

const columns = ({navigateFocus}) => [
Expand Down Expand Up @@ -142,7 +138,8 @@ function Footer(props) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const isVertical = props.shouldShowSmallScreen;
const {shouldUseNarrowLayout} = useResponsiveLayout();
const isVertical = shouldUseNarrowLayout;
const imageDirection = isVertical ? styles.flexRow : styles.flexColumn;
const imageStyle = isVertical ? styles.pr0 : styles.alignSelfCenter;
const columnDirection = isVertical ? styles.flexColumn : styles.flexRow;
Expand Down
9 changes: 4 additions & 5 deletions src/pages/signin/SignInPageLayout/SignInPageContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import OfflineIndicator from '@components/OfflineIndicator';
import SignInPageForm from '@components/SignInPageForm';
import Text from '@components/Text';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
Expand All @@ -32,14 +33,12 @@ const propTypes = {
/** Whether to show welcome header on a particular page */
shouldShowWelcomeHeader: PropTypes.bool.isRequired,

/** Whether to show signIn hero image on a particular page */
shouldShowSmallScreen: PropTypes.bool.isRequired,

...withLocalizePropTypes,
};

function SignInPageContent(props) {
const {isSmallScreenWidth} = useWindowDimensions();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();

Expand Down Expand Up @@ -77,9 +76,9 @@ function SignInPageContent(props) {
<View style={[styles.mb8, styles.signInPageWelcomeTextContainer, styles.alignSelfCenter]}>
<OfflineIndicator style={[styles.m0, styles.pl0, styles.alignItemsStart]} />
</View>
{props.shouldShowSmallScreen ? (
{shouldUseNarrowLayout ? (
<View style={[styles.mt8]}>
<SignInHeroImage shouldShowSmallScreen />
<SignInHeroImage />
</View>
) : null}
</View>
Expand Down
17 changes: 5 additions & 12 deletions src/pages/signin/SignInPageLayout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import SignInGradient from '@assets/images/home-fade-gradient.svg';
import ImageSVG from '@components/ImageSVG';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -39,9 +40,6 @@ const propTypes = {
/** A reference so we can expose scrollPageToTop */
innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),

/** Whether or not the sign in page is being rendered in the RHP modal */
shouldShowSmallScreen: PropTypes.bool,

/** Override the green headline copy */
customHeadline: PropTypes.string,

Expand All @@ -53,7 +51,6 @@ const propTypes = {

const defaultProps = {
innerRef: () => {},
shouldShowSmallScreen: false,
customHeadline: '',
customHeroBody: '',
};
Expand All @@ -67,11 +64,12 @@ function SignInPageLayout(props) {
let containerStyles = [styles.flex1, styles.signInPageInner];
let contentContainerStyles = [styles.flex1, styles.flexRow];
const {windowHeight} = useWindowDimensions();
const {shouldUseNarrowLayout} = useResponsiveLayout();

// To scroll on both mobile and web, we need to set the container height manually
const containerHeight = windowHeight - props.insets.top - props.insets.bottom;

if (props.shouldShowSmallScreen) {
if (shouldUseNarrowLayout) {
containerStyles = [styles.flex1];
contentContainerStyles = [styles.flex1, styles.flexColumn];
}
Expand Down Expand Up @@ -99,7 +97,7 @@ function SignInPageLayout(props) {

return (
<View style={containerStyles}>
{!props.shouldShowSmallScreen ? (
{!shouldUseNarrowLayout ? (
<View style={contentContainerStyles}>
<ScrollView
keyboardShouldPersistTaps="handled"
Expand All @@ -111,7 +109,6 @@ function SignInPageLayout(props) {
welcomeText={props.welcomeText}
shouldShowWelcomeText={props.shouldShowWelcomeText}
shouldShowWelcomeHeader={props.shouldShowWelcomeHeader}
shouldShowSmallScreen={props.shouldShowSmallScreen}
>
{props.children}
</SignInPageContent>
Expand Down Expand Up @@ -172,16 +169,12 @@ function SignInPageLayout(props) {
welcomeText={props.welcomeText}
shouldShowWelcomeText={props.shouldShowWelcomeText}
shouldShowWelcomeHeader={props.shouldShowWelcomeHeader}
shouldShowSmallScreen={props.shouldShowSmallScreen}
>
{props.children}
</SignInPageContent>
</View>
<View style={[styles.flex0]}>
<Footer
navigateFocus={props.navigateFocus}
shouldShowSmallScreen
/>
<Footer navigateFocus={props.navigateFocus} />
</View>
</ScrollView>
)}
Expand Down

0 comments on commit e299ff5

Please sign in to comment.