Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,20 @@ private void initWindowInsetsListener() {

View view = getActivity().getWindow().getDecorView();

ViewCompat.setOnApplyWindowInsetsListener(view, (v, insets) -> {
ViewCompat.setOnApplyWindowInsetsListener(view, (v, windowInsets) -> {
// A listener replaces the DecorView's own onApplyWindowInsets, which is what draws the system bar
// backgrounds and the 3-button navigation bar scrim. Let it run, and continue with the insets it
// leaves, so the space it already reserves for the system bars is not padded a second time.
WindowInsetsCompat insets = WindowInsetsCompat.toWindowInsetsCompat(v.onApplyWindowInsets(windowInsets.toWindowInsets()), v);
// Pad the WebView's parent rather than the DecorView: the DecorView also holds the system bar
// background views, and padding it would move them away from the screen edges into the content.
View content = (View) getBridge().getWebView().getParent();
if (content == null) {
// The WebView is not attached (e.g. a Fragment-hosted bridge whose view was destroyed),
// so there is nothing to pad.
return insets;
}

boolean shouldPassthroughInsets = getWebViewMajorVersion() >= WEBVIEW_VERSION_WITH_SAFE_AREA_FIX && hasViewportCover;

Insets systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
Expand All @@ -202,7 +215,7 @@ private void initWindowInsetsListener() {

if (shouldPassthroughInsets) {
// We need to correct for a possible shown IME
v.setPadding(0, 0, 0, keyboardVisible ? imeInsets.bottom : 0);
content.setPadding(0, 0, 0, keyboardVisible ? imeInsets.bottom : 0);

WindowInsetsCompat newInsets = withoutOverlayingKeyboard(
new WindowInsetsCompat.Builder(insets).setInsets(
Expand All @@ -223,7 +236,7 @@ private void initWindowInsetsListener() {
}

// We need to correct for a possible shown IME
v.setPadding(
content.setPadding(
systemBarsInsets.left,
systemBarsInsets.top,
systemBarsInsets.right,
Expand Down