-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
get ripple drawables by id #28600
Conversation
Base commit: d7299e8 |
Base commit: d7299e8 |
There was a problem hiding this 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"); |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
0624448
to
c0215e3
Compare
There was a problem hiding this 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.
This pull request was successfully merged by @vonovak in c8ed2db. When will my fix make it into a release? | Upcoming Releases |
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 herereact-native/Libraries/Components/Touchable/TouchableNativeFeedback.js
Line 105 in 4a48b02
And passed to
context.getResources().getIdentifier()
inReactDrawableHelper
. 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