fix: android layout reanimation null pointer exception (2959) #3162
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
ReactApplicationContext.getCurentContext sometimes return null. This causes a crash (NullPointerException) in reanimated due to not checking if context exists. As per react native's examples, we can only measure device metrics when current activity is not null (https://github.com/facebook/react-native/blob/8bd3edec88148d0ab1f225d2119435681fbbba33/ReactCommon/react/nativemodule/samples/platform/android/SampleTurboModule.java#L56)
Fixes #2959.
Changes
Check if current activity is not null before measuring the device.