Skip to content

Commit

Permalink
Merge pull request #15 from wordpress-mobile/fix-android-layout-reani…
Browse files Browse the repository at this point in the history
…mation-crash

Fix crash related to Android layout reanimation due to `NullPointerException`
  • Loading branch information
fluiddot authored May 4, 2022
2 parents f575b73 + 9e63336 commit e83e1f2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
Binary file modified android-npm/react-native-reanimated-66-hermes.aar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.swmansion.reanimated.layoutReanimation;

import android.app.Activity;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
Expand Down Expand Up @@ -364,12 +365,18 @@ public HashMap<String, Float> prepareDataForAnimationWorklet(
preparedValues.put(key, PixelUtil.toDIPFromPixel((int) values.get(key)));
}

DisplayMetrics displaymetrics = new DisplayMetrics();
mContext.getCurrentActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
preparedValues.put("windowWidth", PixelUtil.toDIPFromPixel(width));
preparedValues.put("windowHeight", PixelUtil.toDIPFromPixel(height));
DisplayMetrics displayMetrics = new DisplayMetrics();
Activity currentActivity = mContext.getCurrentActivity();
if (currentActivity != null) {
currentActivity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
preparedValues.put("windowWidth", PixelUtil.toDIPFromPixel(width));
preparedValues.put("windowHeight", PixelUtil.toDIPFromPixel(height));
} else {
preparedValues.put("windowWidth", PixelUtil.toDIPFromPixel(0));
preparedValues.put("windowHeight", PixelUtil.toDIPFromPixel(0));
}
return preparedValues;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-reanimated",
"version": "2.4.1-wp-1",
"version": "2.4.1-wp-2",
"description": "More powerful alternative to Animated library for React Native.",
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
Expand Down
Binary file removed react-native-reanimated-2.4.1-wp-1.tgz
Binary file not shown.
Binary file added react-native-reanimated-2.4.1-wp-2.tgz
Binary file not shown.

0 comments on commit e83e1f2

Please sign in to comment.