Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Fix crash related to Android layout reanimation due to NullPointerException#15

Merged
fluiddot merged 4 commits intowp-forkfrom
fix-android-layout-reanimation-crash
May 4, 2022
Merged

Fix crash related to Android layout reanimation due to NullPointerException#15
fluiddot merged 4 commits intowp-forkfrom
fix-android-layout-reanimation-crash

Conversation

@fluiddot
Copy link
Copy Markdown

@fluiddot fluiddot commented May 3, 2022

In order to address wordpress-mobile/gutenberg-mobile#4801, this PR incorporates the fix from this upstream commit into the wp-fork branch.

How to test:

  1. Check out the branch rnmobile/fix/drag-and-drop-android-crash-when-closing-editor in the Gutenberg repository.
  2. Open the app and connect it to the Metro server.
  3. Start dragging a block.
  4. While moving the block around the screen, tap the back button with another finger to close the editor.
  5. Observe that the app doesn't crash.

…re-mansion#3162)

## 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 software-mansion#2959.

## Changes

Check if current activity is not null before measuring the device.
@fluiddot fluiddot self-assigned this May 3, 2022
@fluiddot fluiddot requested a review from geriux May 4, 2022 09:44
Copy link
Copy Markdown

@geriux geriux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I tested this using a Redmi Note 8T and the crash issue is no longer present 🎉 thanks for bringing those changes!

@fluiddot fluiddot merged commit e83e1f2 into wp-fork May 4, 2022
@fluiddot fluiddot deleted the fix-android-layout-reanimation-crash branch May 4, 2022 14:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants