react-native icon indicating copy to clipboard operation
react-native copied to clipboard

fix: foreground ripple crash on api < 23

Open vonovak opened this issue 2 years ago • 5 comments

Summary:

The Pressable component supports the foreground option for ripple. However, using it on old android api levels (e.g. android 5) crashes with

Error while updating property
nativeForegroundAndroid' of a view managed by:
RCTView
null
No virtual method setForeground(Landroid/ graphics/drawable/Drawable;)V in class Lcom/ facebook/react/views/view/ReactViewGroup; or its super classes

TouchableNativeFeedback.js has a check to make sure this does not happen as seen here

I also want to point out that this PR can be closed https://github.com/facebook/react-native/pull/30466 as it's already implemented

Changelog:

Test Plan:

tested locally on another project because I wasn't able to get RN tester running

vonovak avatar Jun 14 '23 22:06 vonovak

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,757,695 +25
android hermes armeabi-v7a 8,070,268 +32
android hermes x86 9,250,290 +26
android hermes x86_64 9,099,434 +29
android jsc arm64-v8a 9,318,885 +14
android jsc armeabi-v7a 8,508,785 +13
android jsc x86 9,382,367 +4
android jsc x86_64 9,635,612 +6

Base commit: b0485bed0945061becace5af924fa60b17ab295f Branch: main

analysis-bot avatar Jun 14 '23 22:06 analysis-bot

I think this works, but we could also fix on the native side so that any usage of the prop no-ops without adding a check on the JS side. https://github.com/facebook/react-native/blob/b0485bed0945061becace5af924fa60b17ab295f/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java#L201

NickGerleman avatar Jun 14 '23 23:06 NickGerleman

I think this works, but we could also fix on the native side so that any usage of the prop no-ops without adding a check on the JS side. https://github.com/facebook/react-native/blob/b0485bed0945061becace5af924fa60b17ab295f/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java#L201

I can do that, but it probably shouldn't be a noop - if foreground is not supported, it should fall back to using background ripple?

vonovak avatar Jun 14 '23 23:06 vonovak

Oh, yes, I missed that the JS was changing to a specific fallback behavior. JS side solution makes sense to me then.

NickGerleman avatar Jun 14 '23 23:06 NickGerleman

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

facebook-github-bot avatar Jun 14 '23 23:06 facebook-github-bot

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

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

github-actions[bot] avatar Jun 15 '23 22:06 github-actions[bot]