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

Error possibly caused by SystemNavigationBarModule.setNavigationColor #18

Closed nickmcmillan closed 2 years ago

nickmcmillan commented 2 years ago

My React Native (not Expo) app is reporting several crashes (via Firebase Crashlytics) which appear related to this module (1.0.2):

Fatal Exception: java.lang.NullPointerException
Attempt to invoke virtual method 'android.view.Window android.app.Activity.getWindow()' on a null object reference

com.reactnativesystemnavigationbar.SystemNavigationBarModule.setNavigationColor (SystemNavigationBarModule.java:105)

This error never occurred before using this module. It's happening across Android versions 10, 11, 12.

From reading that error log it kind of sounds like setNavigationColor is being called too soon? I'm calling it like SystemNavigationBar.setNavigationColor("#FDF7F5", false) from inside a useEffect where I'd assume it should be fine to do so.

kadiraydinli commented 2 years ago

Hi @nickmcmillan , this issue should be resolved, can you check again in the latest version(1.0.4)? https://github.com/kadiraydinli/react-native-system-navigation-bar/releases/tag/v1.0.3

nickmcmillan commented 2 years ago

Ah brilliant, I didn't see that PR. I'll upgrade to 1.0.4, thanks.

Shaddix commented 2 years ago

Happened for me on 1.0.4 (received logs via Sentry).

Seems like getCurrentActivity() could return null as well. According to the logs it seems that the user started the app and quite quickly minimized it (e.g. by pressing Home button on the phone). Though, I wasn't able to reproduce it

Attempt to invoke virtual method 'android.view.Window android.app.Activity.getWindow()' on a null object reference

com.reactnativesystemnavigationbar.SystemNavigationBarModule in setNavigationColor at line 123
java.lang.reflect.Method in invoke
com.facebook.react.bridge.JavaMethodWrapper in invoke at line 372
com.facebook.react.bridge.JavaModuleWrapper in invoke at line 188
com.facebook.react.bridge.queue.NativeRunnable in run
android.os.Handler in handleCallback at line 938
android.os.Handler in dispatchMessage at line 99
com.facebook.react.bridge.queue.MessageQueueThreadHandler in dispatchMessage at line 27
android.os.Looper in loop at line 246
com.facebook.react.bridge.queue.MessageQueueThreadImpl$4 in run at line 226
java.lang.Thread in run at line 9233