masked-view: [bug/crash] MaskedView makes application crash on Android
Hi,
I’m experiencing an app crash on Android devices when using MaskedView. It occurs when leaving the screen (react navigation) with rendered MaskedView component and started happening after upgrading to RN 0.64.0.
Deps: “@react-native-masked-view/masked-view”: “0.2.3”, “react-native”: “0.64.0”,
P.s. iOS is working fine.
Logcat fragment:
021-04-13 12:31:49.611 15339-15339/[app] E/unknown:ReactNative: Exception thrown when executing ReactViewGroup.dispatchDraw method on ReactViewGroup[2999]
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setVisibility(int)' on a null object reference
at org.reactnative.maskedview.RNCMaskedView.updateBitmapMask(RNCMaskedView.java:81)
at org.reactnative.maskedview.RNCMaskedView.dispatchDraw(RNCMaskedView.java:35)
at android.view.View.buildDrawingCacheImpl(View.java:20689)
at android.view.View.buildDrawingCache(View.java:20555)
at android.view.View.draw(View.java:21145)
at android.view.ViewGroup.drawChild(ViewGroup.java:4388)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4173)
at com.facebook.react.views.view.ReactViewGroup.dispatchDraw(ReactViewGroup.java:710)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 17 (2 by maintainers)
@DanielMarkiel I looked into this and it seems like MaskedView is trying to “modify” elements that no longer exist due to RN removing them from memory (by switching screens). So a quick fix for this is to check for null object on the view inside RNCMaskedView.java. You can try this by replacing the following functions by this code.
this solves the crashing, but perhaps someone from the MaskedView team could look further into it because I am not 100% sure this is a clean solution. Could someone more experienced also look into this? @Naturalclar @FonDorn
The fix has been released here: https://github.com/react-native-masked-view/masked-view/releases/tag/v0.2.5
@friedolinfoerder thanks for also looking into it, def need someone more experienced with Android to have a look at this, at least we know whats going wrong. I’ll look deeper into it as well and will share my thoughts here.
@k-ibr Thanks for the fix. I have another problem related to this issue Now when I go back from a screen, the MaskedView shows children for a short time (instead of masked view, or nothing)
https://user-images.githubusercontent.com/23259418/147493919-0971a1e1-1170-419b-94f8-d0ec2b44d101.mov
should close issue if it’s fixed
I created PR. Thanks @k-ibr for this solution.