kadiraydinli / react-native-system-navigation-bar

React Native lets you customize the navigation bar for Android.
https://www.npmjs.com/package/react-native-system-navigation-bar
MIT License
270 stars 19 forks source link

fix(set-navigation-color): call promise callback only once #31

Closed zolbooo closed 1 year ago

zolbooo commented 1 year ago

Hello there. We are experiencing rare native crashes in setNavigationColor function:

java.lang.RuntimeException: Illegal callback invocation from native module. This callback type only permits a single invocation from native code.
    at com.facebook.react.bridge.CallbackImpl.invoke(CallbackImpl.java:4)
    at com.facebook.react.bridge.PromiseImpl.resolve(PromiseImpl.java:2)
    at com.reactnativesystemnavigationbar.SystemNavigationBarModule.lambda$setModeStyle$4(SystemNavigationBarModule.java:10)
    at com.reactnativesystemnavigationbar.SystemNavigationBarModule.c
    at aa.e.run
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:226)
    at android.app.ActivityThread.main(ActivityThread.java:7224)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:500)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:913)

This is probably caused by the setModeStyle internal call, because it accepts promise, so that when parent function has finished it calls promise.resolve second time. This is fixed by overloading setModeStyle without promise, so that we can call it from UI thread directly.

kadiraydinli commented 1 year ago

Thanks for PR.