mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix NoSuchMethodException when calling DisplayMetricsHolder.initDisplayMetrics 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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
23036b38bc
commit
35128f45d1
@@ -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"),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -13,8 +13,10 @@ import android.util.DisplayMetrics;
|
||||
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;
|
||||
@@ -80,7 +82,13 @@ public class DisplayMetricsHolder {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user