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 resolve email field error after signing in with Apple or Gmai #53109

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
24 changes: 19 additions & 5 deletions src/components/SignInButtons/AppleSignIn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const getConfig = (config: NativeConfig, key: string, defaultValue: string) => (

type AppleSignInDivProps = {
isDesktopFlow: boolean;
onPointerDown?: () => void;
};

type SingletonAppleSignInButtonProps = AppleSignInDivProps & {
Expand All @@ -24,6 +25,7 @@ type SingletonAppleSignInButtonProps = AppleSignInDivProps & {

type AppleSignInProps = WithNavigationFocusProps & {
isDesktopFlow?: boolean;
onPointerDown?: () => void;
// eslint-disable-next-line react/no-unused-prop-types
onPress?: () => void;
};
Expand Down Expand Up @@ -60,7 +62,7 @@ const failureListener = (event: AppleIDSignInOnFailureEvent) => {
/**
* Apple Sign In button for Web.
*/
function AppleSignInDiv({isDesktopFlow}: AppleSignInDivProps) {
function AppleSignInDiv({isDesktopFlow, onPointerDown}: AppleSignInDivProps) {
useEffect(() => {
// `init` renders the button, so it must be called after the div is
// first mounted.
Expand Down Expand Up @@ -88,6 +90,7 @@ function AppleSignInDiv({isDesktopFlow}: AppleSignInDivProps) {
data-width={CONST.SIGN_IN_FORM_WIDTH}
data-height="52"
style={{cursor: 'pointer'}}
onPointerDown={onPointerDown}
/>
) : (
<div
Expand All @@ -99,24 +102,30 @@ function AppleSignInDiv({isDesktopFlow}: AppleSignInDivProps) {
data-border-radius="50"
data-size="40"
style={{cursor: 'pointer'}}
onPointerDown={onPointerDown}
/>
);
}

// The Sign in with Apple script may fail to render button if there are multiple
// of these divs present in the app, as it matches based on div id. So we'll
// only mount the div when it should be visible.
function SingletonAppleSignInButton({isFocused, isDesktopFlow}: SingletonAppleSignInButtonProps) {
function SingletonAppleSignInButton({isFocused, isDesktopFlow, onPointerDown}: SingletonAppleSignInButtonProps) {
if (!isFocused) {
return null;
}
return <AppleSignInDiv isDesktopFlow={isDesktopFlow} />;
return (
<AppleSignInDiv
isDesktopFlow={isDesktopFlow}
onPointerDown={onPointerDown}
/>
);
}

// withNavigationFocus is used to only render the button when it is visible.
const SingletonAppleSignInButtonWithFocus = withNavigationFocus(SingletonAppleSignInButton);

function AppleSignIn({isDesktopFlow = false}: AppleSignInProps) {
function AppleSignIn({isDesktopFlow = false, onPointerDown}: AppleSignInProps) {
const [scriptLoaded, setScriptLoaded] = useState(false);
useEffect(() => {
if (window.appleAuthScriptLoaded) {
Expand All @@ -136,7 +145,12 @@ function AppleSignIn({isDesktopFlow = false}: AppleSignInProps) {
return null;
}

return <SingletonAppleSignInButtonWithFocus isDesktopFlow={isDesktopFlow} />;
return (
<SingletonAppleSignInButtonWithFocus
isDesktopFlow={isDesktopFlow}
onPointerDown={onPointerDown}
/>
);
}

AppleSignIn.displayName = 'AppleSignIn';
Expand Down
5 changes: 4 additions & 1 deletion src/components/SignInButtons/GoogleSignIn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type GoogleSignInProps = {
isDesktopFlow?: boolean;
// eslint-disable-next-line react/no-unused-prop-types
onPress?: () => void;
onPointerDown?: () => void;
};

/** Div IDs for styling the two different Google Sign-In buttons. */
Expand All @@ -27,7 +28,7 @@ const signIn = (response: Response) => {
* @returns {React.Component}
*/

function GoogleSignIn({isDesktopFlow = false}: GoogleSignInProps) {
function GoogleSignIn({isDesktopFlow = false, onPointerDown}: GoogleSignInProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const loadScript = useCallback(() => {
Expand Down Expand Up @@ -76,6 +77,7 @@ function GoogleSignIn({isDesktopFlow = false}: GoogleSignInProps) {
id={desktopId}
role={CONST.ROLE.BUTTON}
aria-label={translate('common.signInWithGoogle')}
onPointerDown={onPointerDown}
/>
</View>
) : (
Expand All @@ -84,6 +86,7 @@ function GoogleSignIn({isDesktopFlow = false}: GoogleSignInProps) {
id={mainId}
role={CONST.ROLE.BUTTON}
aria-label={translate('common.signInWithGoogle')}
onPointerDown={onPointerDown}
/>
</View>
);
Expand Down
12 changes: 10 additions & 2 deletions src/pages/signin/LoginForm/BaseLoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ function BaseLoginForm({login, onLoginChanged, blurOnSubmit = false, isVisible}:
});
}, []);

const handleSignIn = () => setIsSigningWithAppleOrGoogle(true);

return (
<>
<View
Expand Down Expand Up @@ -305,10 +307,16 @@ function BaseLoginForm({login, onLoginChanged, blurOnSubmit = false, isVisible}:

<View style={shouldUseNarrowLayout ? styles.loginButtonRowSmallScreen : styles.loginButtonRow}>
<View>
<AppleSignIn onPress={() => setIsSigningWithAppleOrGoogle(true)} />
<AppleSignIn
onPress={handleSignIn}
onPointerDown={handleSignIn}
/>
</View>
<View>
<GoogleSignIn onPress={() => setIsSigningWithAppleOrGoogle(true)} />
<GoogleSignIn
onPress={handleSignIn}
onPointerDown={handleSignIn}
/>
</View>
</View>
</View>
Expand Down