Skip to content

Commit b53858c

Browse files
committed
Running setSafeAreaInsets() on main thread
webView.evaluateJavascript methods should be run on the main thread
1 parent f22dfe7 commit b53858c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/WebViewManager.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,15 @@ private int pageRectToViewHeight(final @NonNull Activity activity, @NonNull JSON
321321
}
322322

323323
private void updateSafeAreaInsets() {
324-
int[] insets = OSViewUtils.getCutoutAndStatusBarInsets(activity);
325-
String safeAreaInsetsObject = String.format(OSJavaScriptInterface.SAFE_AREA_JS_OBJECT, insets[0], insets[1], insets[2], insets[3]);
326-
String safeAreaInsetsFunction = String.format(OSJavaScriptInterface.SET_SAFE_AREA_INSETS_JS_FUNCTION, safeAreaInsetsObject);
327-
webView.evaluateJavascript(safeAreaInsetsFunction, null);
324+
OSUtils.runOnMainUIThread(new Runnable() {
325+
@Override
326+
public void run() {
327+
int[] insets = OSViewUtils.getCutoutAndStatusBarInsets(activity);
328+
String safeAreaInsetsObject = String.format(OSJavaScriptInterface.SAFE_AREA_JS_OBJECT, insets[0], insets[1], insets[2], insets[3]);
329+
String safeAreaInsetsFunction = String.format(OSJavaScriptInterface.SET_SAFE_AREA_INSETS_JS_FUNCTION, safeAreaInsetsObject);
330+
webView.evaluateJavascript(safeAreaInsetsFunction, null);
331+
}
332+
});
328333
}
329334

330335
// Every time an Activity is shown we update the height of the WebView since the available
@@ -513,8 +518,6 @@ private static void enableWebViewRemoteDebugging() {
513518
private int getWebViewMaxSizeX(Activity activity) {
514519
if (messageContent.isFullBleed()) {
515520
return getFullbleedWindowWidth(activity);
516-
} else {
517-
518521
}
519522
int margin = (MARGIN_PX_SIZE * 2);
520523
return OSViewUtils.getWindowWidth(activity) - margin;

0 commit comments

Comments
 (0)