Skip to content

Commit 35128f4

Browse files
mdvaccafacebook-github-bot
authored andcommitted
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
1 parent 23036b3 commit 35128f4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/BUCK

+2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ rn_android_library(
6969
"PUBLIC",
7070
],
7171
deps = [
72+
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
7273
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
7374
react_native_dep("third-party/android/androidx:annotation"),
7475
react_native_dep("third-party/java/jsr-305:jsr-305"),
7576
react_native_target("java/com/facebook/react/bridge:bridge"),
77+
react_native_target("java/com/facebook/react/common:common"),
7678
],
7779
)

ReactAndroid/src/main/java/com/facebook/react/uimanager/DisplayMetricsHolder.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
import android.view.Display;
1414
import android.view.WindowManager;
1515
import androidx.annotation.Nullable;
16+
import com.facebook.common.logging.FLog;
1617
import com.facebook.infer.annotation.Assertions;
1718
import com.facebook.react.bridge.WritableNativeMap;
19+
import com.facebook.react.common.ReactConstants;
1820
import java.lang.reflect.InvocationTargetException;
1921
import java.lang.reflect.Method;
2022
import java.util.HashMap;
@@ -80,7 +82,13 @@ public static void initDisplayMetrics(Context context) {
8082
screenDisplayMetrics.widthPixels = (Integer) mGetRawW.invoke(display);
8183
screenDisplayMetrics.heightPixels = (Integer) mGetRawH.invoke(display);
8284
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
83-
throw new RuntimeException("Error getting real dimensions for API level < 17", e);
85+
// this may not be 100% accurate, but it's all we've got
86+
screenDisplayMetrics.widthPixels = display.getWidth();
87+
screenDisplayMetrics.heightPixels = display.getHeight();
88+
FLog.e(
89+
ReactConstants.TAG,
90+
"Unable to access getRawHeight and getRawWidth to get real dimensions.",
91+
e);
8492
}
8593
}
8694
DisplayMetricsHolder.setScreenDisplayMetrics(screenDisplayMetrics);

0 commit comments

Comments
 (0)