Skip to content

Commit

Permalink
Fix NoSuchMethodException when calling DisplayMetricsHolder.initDispl…
Browse files Browse the repository at this point in the history
…ayMetrics in Android API level <= 16

Summary:
This diff fixex a NoSuchMethodException when calling DisplayMetricsHolder.initDisplayMetrics in Android API level <= 16.

changelog: [Android][Fixed] Fix NoSuchMethodException when calling DisplayMetricsHolder.initDisplayMetrics in Android API level <= 16

Reviewed By: fkgozali

Differential Revision: D22630603

fbshipit-source-id: d2a95445beb5745a89ee1eefdf0d24ce3e0b8893
  • Loading branch information
mdvacca authored and facebook-github-bot committed Jul 20, 2020
1 parent 23036b3 commit 35128f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ReactAndroid/src/main/java/com/facebook/react/uimanager/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ rn_android_library(
"PUBLIC",
],
deps = [
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
react_native_dep("third-party/android/androidx:annotation"),
react_native_dep("third-party/java/jsr-305:jsr-305"),
react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/common:common"),
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import android.view.Display;
import android.view.WindowManager;
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.common.ReactConstants;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
Expand Down Expand Up @@ -80,7 +82,13 @@ public static void initDisplayMetrics(Context context) {
screenDisplayMetrics.widthPixels = (Integer) mGetRawW.invoke(display);
screenDisplayMetrics.heightPixels = (Integer) mGetRawH.invoke(display);
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
throw new RuntimeException("Error getting real dimensions for API level < 17", e);
// this may not be 100% accurate, but it's all we've got
screenDisplayMetrics.widthPixels = display.getWidth();
screenDisplayMetrics.heightPixels = display.getHeight();
FLog.e(
ReactConstants.TAG,
"Unable to access getRawHeight and getRawWidth to get real dimensions.",
e);
}
}
DisplayMetricsHolder.setScreenDisplayMetrics(screenDisplayMetrics);
Expand Down

0 comments on commit 35128f4

Please sign in to comment.