th3rdwave / react-native-safe-area-context

A flexible way to handle safe area insets in JS. Also works on Android and Web!
MIT License
2.08k stars 191 forks source link

Prevent from crashing with null cannot be cast to non-null type `kotlin.Any` #489

Closed lukmccall closed 2 months ago

lukmccall commented 2 months ago

Summary

It's possible for the getInitialWindowMetrics method to return null, which can cause crashes if we force cast it to Any. I faced issues with reloading the app, resulting in errors:

ERROR  Error: Exception in HostObject::get for prop 'RNCSafeAreaContext': java.lang.NullPointerException: null cannot be cast to non-null type kotlin.Any, js engine: hermes

I'm unsure of the expected behavior when getInitialWindowMetrics returns null, but the current exception doesn't provide enough information.

Test Plan

janicduplessis commented 2 months ago

Looks good, thanks!