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

Foreground ripple support in Pressable #31632

Conversation

intergalacticspacehighway
Copy link
Contributor

Summary

This PR aims to enable support for foreground ripple in Pressable. This makes it possible to show ripple on top of custom child components like Image as shown in the below example.

Changelog

[Android] [Added] - Support for foreground ripple in Pressable

Test Plan

  • Pass property useForeground: true in android_ripple config to verify the changes.
Screen.Recording.2021-05-30.at.9.37.48.PM.mov

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 30, 2021
@analysis-bot
Copy link

analysis-bot commented May 30, 2021

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: c774f9e

@elicwhite
Copy link
Member

Looks like the JavaScript tests are failing due to a missing dep in the useMemo array.

@analysis-bot
Copy link

analysis-bot commented Jun 6, 2021

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 9,240,214 +421
android hermes armeabi-v7a 8,750,141 +416
android hermes x86 9,702,519 +420
android hermes x86_64 9,667,737 +411
android jsc arm64-v8a 10,887,043 +240
android jsc armeabi-v7a 9,788,266 +236
android jsc x86 10,944,763 +234
android jsc x86_64 11,551,504 +234

Base commit: c774f9e

Copy link
Contributor

@yungsters yungsters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provided some minor feedback.

@@ -180,15 +180,28 @@ function Pressable(props: Props, forwardedRef): React.Node {
? {...props.accessibilityState, disabled}
: props.accessibilityState;

const restPropsWithDefaults: React.ElementConfig<typeof View> = {
let restPropsWithDefaults: React.ElementConfig<typeof View> = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep this as const and instead create a new const local variable that contains the ripple props (or remains undefined) that you spread in here?

It's a minor code reorganization, but it helps keep the code slightly more readable in the long-term the more you can have const variables that — as you read the declaration — you know will not be reassigned later.

@@ -27,6 +27,7 @@ export type RippleConfig = {|
color?: ColorValue,
borderless?: boolean,
radius?: number,
useForeground?: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just name this foreground? Even though it is a property name and not a variable name, avoiding the "use" prefix is just better in the current world with hooks.

@@ -58,16 +61,23 @@ export default function useAndroidRippleForView(
'Unexpected color given for Ripple color',
);

let viewProps = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar feedback as above about making this const. You can also instantiating this after backgroundValue:

const viewProps = foreground === true
  ? {nativeForegroundAndroid: backgroundValue}
  : {nativeBackgroundAndroid: backgroundValue};

Could even return this to line 80 as a ternary property initialization in the return statement.

@@ -98,5 +108,5 @@ export default function useAndroidRippleForView(
};
}
return null;
}, [color, borderless, radius, viewRef]);
}, [color, borderless, radius, viewRef, useForeground]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Alphabetize (after renaming to foreground).

@facebook-github-bot
Copy link
Contributor

@yungsters has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@yungsters merged this pull request in 0823f29.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Needs: React Native Team Attention
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants