Skip to content

Commit

Permalink
Update onPress to onPointerDown
Browse files Browse the repository at this point in the history
  • Loading branch information
huult committed Nov 28, 2024
1 parent 8fe4bc1 commit de3437c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
18 changes: 9 additions & 9 deletions src/components/SignInButtons/AppleSignIn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ const getConfig = (config: NativeConfig, key: string, defaultValue: string) => (

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

type SingletonAppleSignInButtonProps = AppleSignInDivProps & {
isFocused: boolean;
onPress?: () => void;
};

type AppleSignInProps = WithNavigationFocusProps & {
isDesktopFlow?: boolean;
onPointerDown?: () => void;
// eslint-disable-next-line react/no-unused-prop-types
onPress?: () => void;
};
Expand Down Expand Up @@ -62,7 +62,7 @@ const failureListener = (event: AppleIDSignInOnFailureEvent) => {
/**
* Apple Sign In button for Web.
*/
function AppleSignInDiv({isDesktopFlow, onPress}: 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 @@ -90,7 +90,7 @@ function AppleSignInDiv({isDesktopFlow, onPress}: AppleSignInDivProps) {
data-width={CONST.SIGN_IN_FORM_WIDTH}
data-height="52"
style={{cursor: 'pointer'}}
onPointerDown={onPress}
onPointerDown={onPointerDown}
/>
) : (
<div
Expand All @@ -102,30 +102,30 @@ function AppleSignInDiv({isDesktopFlow, onPress}: AppleSignInDivProps) {
data-border-radius="50"
data-size="40"
style={{cursor: 'pointer'}}
onPointerDown={onPress}
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, onPress}: SingletonAppleSignInButtonProps) {
function SingletonAppleSignInButton({isFocused, isDesktopFlow, onPointerDown}: SingletonAppleSignInButtonProps) {
if (!isFocused) {
return null;
}
return (
<AppleSignInDiv
isDesktopFlow={isDesktopFlow}
onPress={onPress}
onPointerDown={onPointerDown}
/>
);
}

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

function AppleSignIn({isDesktopFlow = false, onPress}: AppleSignInProps) {
function AppleSignIn({isDesktopFlow = false, onPointerDown}: AppleSignInProps) {
const [scriptLoaded, setScriptLoaded] = useState(false);
useEffect(() => {
if (window.appleAuthScriptLoaded) {
Expand All @@ -148,7 +148,7 @@ function AppleSignIn({isDesktopFlow = false, onPress}: AppleSignInProps) {
return (
<SingletonAppleSignInButtonWithFocus
isDesktopFlow={isDesktopFlow}
onPress={onPress}
onPointerDown={onPointerDown}
/>
);
}
Expand Down
7 changes: 4 additions & 3 deletions 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, onPress}: GoogleSignInProps) {
function GoogleSignIn({isDesktopFlow = false, onPointerDown}: GoogleSignInProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const loadScript = useCallback(() => {
Expand Down Expand Up @@ -76,7 +77,7 @@ function GoogleSignIn({isDesktopFlow = false, onPress}: GoogleSignInProps) {
id={desktopId}
role={CONST.ROLE.BUTTON}
aria-label={translate('common.signInWithGoogle')}
onPointerDown={onPress}
onPointerDown={onPointerDown}
/>
</View>
) : (
Expand All @@ -85,7 +86,7 @@ function GoogleSignIn({isDesktopFlow = false, onPress}: GoogleSignInProps) {
id={mainId}
role={CONST.ROLE.BUTTON}
aria-label={translate('common.signInWithGoogle')}
onPointerDown={onPress}
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

0 comments on commit de3437c

Please sign in to comment.