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

get ripple drawables by id #28600

Closed
wants to merge 2 commits into from

Conversation

vonovak
Copy link
Contributor

@vonovak vonovak commented Apr 12, 2020

Summary

While working on recent PRs regarding ripple radius in TouchableNativeFeedbaack and ripple support in Pressable I noticed ReactDrawableHelper uses a discouraged way to obtain resources.

The attribute names (strings) 'selectableItemBackground' and 'selectableItemBackgroundBorderless' are used here

And passed to context.getResources().getIdentifier() in ReactDrawableHelper. Since we know the attribute names beforehand I figured we can obtain the resources by id (fast) instead of by name (slow). I made it so that the slow code path is taken in case the attribute name does not match what is expected, as a fallback.

Note that I did not do any measurement of the effect of this, I'm just offering this as a PR. You'll notice that this PR relies on the fact that the string in JS is the same as the string in Java (it is duplicated). While I could export the strings from Java and use them in JS, I wasn't sure where to export them. But note that even before, the JS code depended on the 'selectableItemBackground' and 'selectableItemBackgroundBorderless' strings to exist on the native side, in the android SDK, I just made the dependency explicit.

Changelog

[Android] [Changed] - get ripple drawables by id

Test Plan

tested manually in RNTester

@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 Apr 12, 2020
@vonovak vonovak changed the title get ripple drawable by id get ripple drawables by id Apr 12, 2020
@react-native-bot react-native-bot added the Platform: Android Android applications. label Apr 12, 2020
@analysis-bot
Copy link

analysis-bot commented Apr 12, 2020

Platform Engine Arch Size (bytes) Diff
ios - universal 809,568 0

Base commit: d7299e8

@analysis-bot
Copy link

analysis-bot commented Apr 12, 2020

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 6,739,209 116
android hermes armeabi-v7a 6,404,263 133
android hermes x86 7,121,368 112
android hermes x86_64 7,011,924 115
android jsc arm64-v8a 8,907,549 109
android jsc armeabi-v7a 8,564,994 110
android jsc x86 8,732,834 127
android jsc x86_64 9,309,024 116

Base commit: d7299e8

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

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

} else if ("selectableItemBackgroundBorderless".equals(attr)) {
return android.R.attr.selectableItemBackgroundBorderless;
} else {
return context.getResources().getIdentifier(attr, "attr", "android");
Copy link
Contributor

Choose a reason for hiding this comment

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

what about if this return 0?
should we throw an exception as we did in the past?
(A comment from David Vacca @mdvacca.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mdvacca The output of this is fed into context.getTheme().resolveAttribute()on line 42 and if that returns false (which it would for 0), JSApplicationIllegalArgumentException is thrown, so it's the same behavior as before.

@vonovak vonovak requested a review from shergin May 17, 2020 16:21
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@shergin is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @vonovak in c8ed2db.

When will my fix make it into a release? | Upcoming Releases

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. Platform: Android Android applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants