diff --git a/lib/ui/hooks.dart b/lib/ui/hooks.dart index 6f0fa3a2d8adf..9c596c2e26008 100644 --- a/lib/ui/hooks.dart +++ b/lib/ui/hooks.dart @@ -18,18 +18,24 @@ dynamic _decodeJSON(String message) { @pragma('vm:entry-point') // ignore: unused_element -void _updateWindowMetrics(double devicePixelRatio, - double width, - double height, - double depth, - double viewPaddingTop, - double viewPaddingRight, - double viewPaddingBottom, - double viewPaddingLeft, - double viewInsetTop, - double viewInsetRight, - double viewInsetBottom, - double viewInsetLeft) { +void _updateWindowMetrics( + double devicePixelRatio, + double width, + double height, + double depth, + double viewPaddingTop, + double viewPaddingRight, + double viewPaddingBottom, + double viewPaddingLeft, + double viewInsetTop, + double viewInsetRight, + double viewInsetBottom, + double viewInsetLeft, + double systemGestureInsetTop, + double systemGestureInsetRight, + double systemGestureInsetBottom, + double systemGestureInsetLeft, +) { window .._devicePixelRatio = devicePixelRatio .._physicalSize = Size(width, height) @@ -48,7 +54,12 @@ void _updateWindowMetrics(double devicePixelRatio, top: math.max(0.0, viewPaddingTop - viewInsetTop), right: math.max(0.0, viewPaddingRight - viewInsetRight), bottom: math.max(0.0, viewPaddingBottom - viewInsetBottom), - left: math.max(0.0, viewPaddingLeft - viewInsetLeft)); + left: math.max(0.0, viewPaddingLeft - viewInsetLeft)) + .._systemGestureInsets = WindowPadding._( + top: math.max(0.0, systemGestureInsetTop), + right: math.max(0.0, systemGestureInsetRight), + bottom: math.max(0.0, systemGestureInsetBottom), + left: math.max(0.0, systemGestureInsetLeft)); _invoke(window.onMetricsChanged, window._onMetricsChangedZone); } diff --git a/lib/ui/window.dart b/lib/ui/window.dart index 2858b422a362d..a810551e38254 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -637,7 +637,7 @@ class Window { /// will likely place system UI, such as the keyboard, that fully obscures /// any content. /// - /// When this changes, [onMetricsChanged] is called. + /// When this property changes, [onMetricsChanged] is called. /// /// The relationship between this [Window.viewInsets], [Window.viewPadding], /// and [Window.padding] are described in more detail in the documentation for @@ -664,7 +664,7 @@ class Window { /// response to the soft keyboard being visible or hidden, whereas /// [Window.padding] will. /// - /// When this changes, [onMetricsChanged] is called. + /// When this property changes, [onMetricsChanged] is called. /// /// The relationship between this [Window.viewInsets], [Window.viewPadding], /// and [Window.padding] are described in more detail in the documentation for @@ -680,6 +680,24 @@ class Window { WindowPadding get viewPadding => _viewPadding; WindowPadding _viewPadding = WindowPadding.zero; + /// The number of physical pixels on each side of the display rectangle into + /// which the application can render, but where the operating system will + /// consume input gestures for the sake of system navigation. + /// + /// For example, an operating system might use the vertical edges of the + /// screen, where swiping inwards from the edges takes users backward + /// through the history of screens they previously visited. + /// + /// When this property changes, [onMetricsChanged] is called. + /// + /// See also: + /// + /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to + /// observe when this value changes. + /// * [MediaQuery.of], a simpler mechanism for the same. + WindowPadding get systemGestureInsets => _systemGestureInsets; + WindowPadding _systemGestureInsets = WindowPadding.zero; + /// The number of physical pixels on each side of the display rectangle into /// which the application can render, but which may be partially obscured by /// system UI (such as the system notification area), or or physical @@ -711,9 +729,10 @@ class Window { WindowPadding _padding = WindowPadding.zero; /// A callback that is invoked whenever the [devicePixelRatio], - /// [physicalSize], [padding], or [viewInsets] values change, for example - /// when the device is rotated or when the application is resized (e.g. when - /// showing applications side-by-side on Android). + /// [physicalSize], [padding], [viewInsets], or [systemGestureInsets] + /// values change, for example when the device is rotated or when the + /// application is resized (e.g. when showing applications side-by-side + /// on Android). /// /// The engine invokes this callback in the same zone in which the callback /// was set. diff --git a/lib/ui/window/viewport_metrics.cc b/lib/ui/window/viewport_metrics.cc index 3dabeeb1ed8c1..f18972992189a 100644 --- a/lib/ui/window/viewport_metrics.cc +++ b/lib/ui/window/viewport_metrics.cc @@ -17,7 +17,11 @@ ViewportMetrics::ViewportMetrics(double p_device_pixel_ratio, double p_physical_view_inset_top, double p_physical_view_inset_right, double p_physical_view_inset_bottom, - double p_physical_view_inset_left) + double p_physical_view_inset_left, + double p_physical_system_gesture_inset_top, + double p_physical_system_gesture_inset_right, + double p_physical_system_gesture_inset_bottom, + double p_physical_system_gesture_inset_left) : device_pixel_ratio(p_device_pixel_ratio), physical_width(p_physical_width), physical_height(p_physical_height), @@ -28,7 +32,14 @@ ViewportMetrics::ViewportMetrics(double p_device_pixel_ratio, physical_view_inset_top(p_physical_view_inset_top), physical_view_inset_right(p_physical_view_inset_right), physical_view_inset_bottom(p_physical_view_inset_bottom), - physical_view_inset_left(p_physical_view_inset_left) {} + physical_view_inset_left(p_physical_view_inset_left), + physical_system_gesture_inset_top(p_physical_system_gesture_inset_top), + physical_system_gesture_inset_right( + p_physical_system_gesture_inset_right), + physical_system_gesture_inset_bottom( + p_physical_system_gesture_inset_bottom), + physical_system_gesture_inset_left(p_physical_system_gesture_inset_left) { +} ViewportMetrics::ViewportMetrics(double p_device_pixel_ratio, double p_physical_width, diff --git a/lib/ui/window/viewport_metrics.h b/lib/ui/window/viewport_metrics.h index 578dbcf664972..5ca8b78eaa064 100644 --- a/lib/ui/window/viewport_metrics.h +++ b/lib/ui/window/viewport_metrics.h @@ -29,7 +29,11 @@ struct ViewportMetrics { double p_physical_view_inset_top, double p_physical_view_inset_right, double p_physical_view_inset_bottom, - double p_physical_view_inset_left); + double p_physical_view_inset_left, + double p_physical_system_gesture_inset_top, + double p_physical_system_gesture_inset_right, + double p_physical_system_gesture_inset_bottom, + double p_physical_system_gesture_inset_left); // Create a ViewportMetrics instance that contains z information. ViewportMetrics(double p_device_pixel_ratio, @@ -63,6 +67,10 @@ struct ViewportMetrics { double physical_view_inset_left = 0; double physical_view_inset_front = kUnsetDepth; double physical_view_inset_back = kUnsetDepth; + double physical_system_gesture_inset_top = 0; + double physical_system_gesture_inset_right = 0; + double physical_system_gesture_inset_bottom = 0; + double physical_system_gesture_inset_left = 0; }; struct LogicalSize { diff --git a/lib/ui/window/window.cc b/lib/ui/window/window.cc index 86c050f25e764..1c535906ea3b5 100644 --- a/lib/ui/window/window.cc +++ b/lib/ui/window/window.cc @@ -194,6 +194,10 @@ void Window::UpdateWindowMetrics(const ViewportMetrics& metrics) { tonic::ToDart(metrics.physical_view_inset_right), tonic::ToDart(metrics.physical_view_inset_bottom), tonic::ToDart(metrics.physical_view_inset_left), + tonic::ToDart(metrics.physical_system_gesture_inset_top), + tonic::ToDart(metrics.physical_system_gesture_inset_right), + tonic::ToDart(metrics.physical_system_gesture_inset_bottom), + tonic::ToDart(metrics.physical_system_gesture_inset_left), })); } diff --git a/lib/web_ui/lib/src/ui/window.dart b/lib/web_ui/lib/src/ui/window.dart index 64df7504c0d9a..e26cda47a05d0 100644 --- a/lib/web_ui/lib/src/ui/window.dart +++ b/lib/web_ui/lib/src/ui/window.dart @@ -573,6 +573,8 @@ abstract class Window { WindowPadding get viewPadding => WindowPadding.zero; + WindowPadding get systemGestureInsets => WindowPadding.zero; + /// The number of physical pixels on each side of the display rectangle into /// which the application can render, but which may be partially obscured by /// system UI (such as the system notification area), or or physical diff --git a/shell/common/shell_test.cc b/shell/common/shell_test.cc index e796916cb6fee..9230b83133439 100644 --- a/shell/common/shell_test.cc +++ b/shell/common/shell_test.cc @@ -108,7 +108,8 @@ void ShellTest::PumpOneFrame(Shell* shell) { fml::AutoResetWaitableEvent latch; shell->GetTaskRunners().GetUITaskRunner()->PostTask( [&latch, engine = shell->weak_engine_]() { - engine->SetViewportMetrics({1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}); + engine->SetViewportMetrics( + {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); engine->animator_->BeginFrame(fml::TimePoint::Now(), fml::TimePoint::Now()); latch.Signal(); diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index bccd52e3c66aa..d7c1473d70aca 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -638,7 +638,7 @@ TEST_F(ShellTest, SetResourceCacheSize) { fml::TaskRunner::RunNowOrPostTask( shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { shell->GetPlatformView()->SetViewportMetrics( - {1.0, 400, 200, 0, 0, 0, 0, 0, 0, 0, 0}); + {1.0, 400, 200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); }); PumpOneFrame(shell.get()); @@ -658,7 +658,7 @@ TEST_F(ShellTest, SetResourceCacheSize) { fml::TaskRunner::RunNowOrPostTask( shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { shell->GetPlatformView()->SetViewportMetrics( - {1.0, 800, 400, 0, 0, 0, 0, 0, 0, 0, 0}); + {1.0, 800, 400, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); }); PumpOneFrame(shell.get()); @@ -676,7 +676,7 @@ TEST_F(ShellTest, SetResourceCacheSizeEarly) { fml::TaskRunner::RunNowOrPostTask( shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { shell->GetPlatformView()->SetViewportMetrics( - {1.0, 400, 200, 0, 0, 0, 0, 0, 0, 0, 0}); + {1.0, 400, 200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); }); PumpOneFrame(shell.get()); @@ -704,7 +704,7 @@ TEST_F(ShellTest, SetResourceCacheSizeNotifiesDart) { fml::TaskRunner::RunNowOrPostTask( shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { shell->GetPlatformView()->SetViewportMetrics( - {1.0, 400, 200, 0, 0, 0, 0, 0, 0, 0, 0}); + {1.0, 400, 200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); }); PumpOneFrame(shell.get()); diff --git a/shell/platform/android/io/flutter/embedding/android/FlutterView.java b/shell/platform/android/io/flutter/embedding/android/FlutterView.java index 6a8d46fd67a42..1d007a35aee18 100644 --- a/shell/platform/android/io/flutter/embedding/android/FlutterView.java +++ b/shell/platform/android/io/flutter/embedding/android/FlutterView.java @@ -5,8 +5,10 @@ package io.flutter.embedding.android; import android.annotation.TargetApi; +import android.annotation.SuppressLint; import android.content.Context; import android.content.res.Configuration; +import android.graphics.Insets; import android.graphics.Rect; import android.os.Build; import android.os.LocaleList; @@ -296,6 +298,10 @@ protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) @Override @TargetApi(20) @RequiresApi(20) + // The annotations to suppress "InlinedApi" and "NewApi" lints prevent lint warnings + // caused by usage of Android Q APIs. These calls are safe because they are + // guarded. + @SuppressLint({"InlinedApi", "NewApi"}) @NonNull public final WindowInsets onApplyWindowInsets(@NonNull WindowInsets insets) { WindowInsets newInsets = super.onApplyWindowInsets(insets); @@ -312,11 +318,21 @@ public final WindowInsets onApplyWindowInsets(@NonNull WindowInsets insets) { viewportMetrics.viewInsetBottom = insets.getSystemWindowInsetBottom(); viewportMetrics.viewInsetLeft = 0; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + Insets systemGestureInsets = insets.getSystemGestureInsets(); + viewportMetrics.systemGestureInsetTop = systemGestureInsets.top; + viewportMetrics.systemGestureInsetRight = systemGestureInsets.right; + viewportMetrics.systemGestureInsetBottom = systemGestureInsets.bottom; + viewportMetrics.systemGestureInsetLeft = systemGestureInsets.left; + } + Log.v(TAG, "Updating window insets (onApplyWindowInsets()):\n" + "Status bar insets: Top: " + viewportMetrics.paddingTop + ", Left: " + viewportMetrics.paddingLeft + ", Right: " + viewportMetrics.paddingRight + "\n" + "Keyboard insets: Bottom: " + viewportMetrics.viewInsetBottom - + ", Left: " + viewportMetrics.viewInsetLeft + ", Right: " + viewportMetrics.viewInsetRight); + + ", Left: " + viewportMetrics.viewInsetLeft + ", Right: " + viewportMetrics.viewInsetRight + + "System Gesture Insets - Left: " + viewportMetrics.systemGestureInsetLeft + ", Top: " + viewportMetrics.systemGestureInsetTop + + ", Right: " + viewportMetrics.systemGestureInsetRight + ", Bottom: " + viewportMetrics.viewInsetBottom); sendViewportMetricsToFlutter(); diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index c478cea46ab0a..fbd63888c19d1 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -356,7 +356,11 @@ public void setViewportMetrics( int physicalViewInsetTop, int physicalViewInsetRight, int physicalViewInsetBottom, - int physicalViewInsetLeft + int physicalViewInsetLeft, + int systemGestureInsetTop, + int systemGestureInsetRight, + int systemGestureInsetBottom, + int systemGestureInsetLeft ) { ensureRunningOnMainThread(); ensureAttachedToNative(); @@ -372,7 +376,11 @@ public void setViewportMetrics( physicalViewInsetTop, physicalViewInsetRight, physicalViewInsetBottom, - physicalViewInsetLeft + physicalViewInsetLeft, + systemGestureInsetTop, + systemGestureInsetRight, + systemGestureInsetBottom, + systemGestureInsetLeft ); } @@ -388,7 +396,11 @@ private native void nativeSetViewportMetrics( int physicalViewInsetTop, int physicalViewInsetRight, int physicalViewInsetBottom, - int physicalViewInsetLeft + int physicalViewInsetLeft, + int systemGestureInsetTop, + int systemGestureInsetRight, + int systemGestureInsetBottom, + int systemGestureInsetLeft ); //----- End Render Surface Support ----- diff --git a/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java b/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java index 260bd8912c834..bac9132df255f 100644 --- a/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java +++ b/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java @@ -202,7 +202,9 @@ public void setViewportMetrics(@NonNull ViewportMetrics viewportMetrics) { + "Padding - L: " + viewportMetrics.paddingLeft + ", T: " + viewportMetrics.paddingTop + ", R: " + viewportMetrics.paddingRight + ", B: " + viewportMetrics.paddingBottom + "\n" + "Insets - L: " + viewportMetrics.viewInsetLeft + ", T: " + viewportMetrics.viewInsetTop - + ", R: " + viewportMetrics.viewInsetRight + ", B: " + viewportMetrics.viewInsetBottom); + + ", R: " + viewportMetrics.viewInsetRight + ", B: " + viewportMetrics.viewInsetBottom + "\n" + + "System Gesture Insets - L: " + viewportMetrics.systemGestureInsetLeft + ", T: " + viewportMetrics.systemGestureInsetTop + + ", R: " + viewportMetrics.systemGestureInsetRight + ", B: " + viewportMetrics.viewInsetBottom); flutterJNI.setViewportMetrics( viewportMetrics.devicePixelRatio, @@ -215,7 +217,11 @@ public void setViewportMetrics(@NonNull ViewportMetrics viewportMetrics) { viewportMetrics.viewInsetTop, viewportMetrics.viewInsetRight, viewportMetrics.viewInsetBottom, - viewportMetrics.viewInsetLeft + viewportMetrics.viewInsetLeft, + viewportMetrics.systemGestureInsetTop, + viewportMetrics.systemGestureInsetRight, + viewportMetrics.systemGestureInsetBottom, + viewportMetrics.systemGestureInsetLeft ); } @@ -346,5 +352,9 @@ public static final class ViewportMetrics { public int viewInsetRight = 0; public int viewInsetBottom = 0; public int viewInsetLeft = 0; + public int systemGestureInsetTop = 0; + public int systemGestureInsetRight = 0; + public int systemGestureInsetBottom = 0; + public int systemGestureInsetLeft = 0; } } diff --git a/shell/platform/android/io/flutter/view/FlutterView.java b/shell/platform/android/io/flutter/view/FlutterView.java index 6f327d7e4a98f..f10a72414fafa 100644 --- a/shell/platform/android/io/flutter/view/FlutterView.java +++ b/shell/platform/android/io/flutter/view/FlutterView.java @@ -5,11 +5,13 @@ package io.flutter.view; import android.annotation.TargetApi; +import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.ContextWrapper; import android.content.res.Configuration; import android.graphics.Bitmap; +import android.graphics.Insets; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.SurfaceTexture; @@ -100,6 +102,10 @@ static final class ViewportMetrics { int physicalViewInsetRight = 0; int physicalViewInsetBottom = 0; int physicalViewInsetLeft = 0; + int systemGestureInsetTop = 0; + int systemGestureInsetRight = 0; + int systemGestureInsetBottom = 0; + int systemGestureInsetLeft = 0; } private final DartExecutor dartExecutor; @@ -542,9 +548,13 @@ int calculateBottomKeyboardInset(WindowInsets insets) { // This callback is not present in API < 20, which means lower API devices will see // the wider than expected padding when the status and navigation bars are hidden. + // The annotations to suppress "InlinedApi" and "NewApi" lints prevent lint warnings + // caused by usage of Android Q APIs. These calls are safe because they are + // guarded. @Override @TargetApi(20) @RequiresApi(20) + @SuppressLint({"InlinedApi", "NewApi"}) public final WindowInsets onApplyWindowInsets(WindowInsets insets) { boolean statusBarHidden = (SYSTEM_UI_FLAG_FULLSCREEN & getWindowSystemUiVisibility()) != 0; @@ -574,6 +584,14 @@ public final WindowInsets onApplyWindowInsets(WindowInsets insets) { mMetrics.physicalViewInsetBottom = navigationBarHidden ? calculateBottomKeyboardInset(insets) : insets.getSystemWindowInsetBottom(); mMetrics.physicalViewInsetLeft = 0; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + Insets systemGestureInsets = insets.getSystemGestureInsets(); + mMetrics.systemGestureInsetTop = systemGestureInsets.top; + mMetrics.systemGestureInsetRight = systemGestureInsets.right; + mMetrics.systemGestureInsetBottom = systemGestureInsets.bottom; + mMetrics.systemGestureInsetLeft = systemGestureInsets.left; + } updateViewportMetrics(); return super.onApplyWindowInsets(insets); } @@ -642,10 +660,23 @@ public Bitmap getBitmap() { private void updateViewportMetrics() { if (!isAttached()) return; - mNativeView.getFlutterJNI().setViewportMetrics(mMetrics.devicePixelRatio, mMetrics.physicalWidth, - mMetrics.physicalHeight, mMetrics.physicalPaddingTop, mMetrics.physicalPaddingRight, - mMetrics.physicalPaddingBottom, mMetrics.physicalPaddingLeft, mMetrics.physicalViewInsetTop, - mMetrics.physicalViewInsetRight, mMetrics.physicalViewInsetBottom, mMetrics.physicalViewInsetLeft); + mNativeView.getFlutterJNI().setViewportMetrics( + mMetrics.devicePixelRatio, + mMetrics.physicalWidth, + mMetrics.physicalHeight, + mMetrics.physicalPaddingTop, + mMetrics.physicalPaddingRight, + mMetrics.physicalPaddingBottom, + mMetrics.physicalPaddingLeft, + mMetrics.physicalViewInsetTop, + mMetrics.physicalViewInsetRight, + mMetrics.physicalViewInsetBottom, + mMetrics.physicalViewInsetLeft, + mMetrics.systemGestureInsetTop, + mMetrics.systemGestureInsetRight, + mMetrics.systemGestureInsetBottom, + mMetrics.systemGestureInsetLeft + ); } // Called by native to update the semantics/accessibility tree. diff --git a/shell/platform/android/platform_view_android_jni.cc b/shell/platform/android/platform_view_android_jni.cc index f25ddefb9becc..f2d17dd13fbe1 100644 --- a/shell/platform/android/platform_view_android_jni.cc +++ b/shell/platform/android/platform_view_android_jni.cc @@ -261,7 +261,11 @@ static void SetViewportMetrics(JNIEnv* env, jint physicalViewInsetTop, jint physicalViewInsetRight, jint physicalViewInsetBottom, - jint physicalViewInsetLeft) { + jint physicalViewInsetLeft, + jint systemGestureInsetTop, + jint systemGestureInsetRight, + jint systemGestureInsetBottom, + jint systemGestureInsetLeft) { const flutter::ViewportMetrics metrics{ static_cast(devicePixelRatio), static_cast(physicalWidth), @@ -274,6 +278,10 @@ static void SetViewportMetrics(JNIEnv* env, static_cast(physicalViewInsetRight), static_cast(physicalViewInsetBottom), static_cast(physicalViewInsetLeft), + static_cast(systemGestureInsetTop), + static_cast(systemGestureInsetRight), + static_cast(systemGestureInsetBottom), + static_cast(systemGestureInsetLeft), }; ANDROID_SHELL_HOLDER->GetPlatformView()->SetViewportMetrics(metrics); @@ -541,7 +549,7 @@ bool RegisterApi(JNIEnv* env) { }, { .name = "nativeSetViewportMetrics", - .signature = "(JFIIIIIIIIII)V", + .signature = "(JFIIIIIIIIIIIIII)V", .fnPtr = reinterpret_cast(&SetViewportMetrics), }, { diff --git a/testing/dart/window_hooks_integration_test.dart b/testing/dart/window_hooks_integration_test.dart index 25812fad244e4..22ee978fc3cc3 100644 --- a/testing/dart/window_hooks_integration_test.dart +++ b/testing/dart/window_hooks_integration_test.dart @@ -48,6 +48,7 @@ void main() { double oldDepth; WindowPadding oldPadding; WindowPadding oldInsets; + WindowPadding oldSystemGestureInsets; setUp(() { oldDPR = window.devicePixelRatio; @@ -55,6 +56,7 @@ void main() { oldDepth = window.physicalDepth; oldPadding = window.viewPadding; oldInsets = window.viewInsets; + oldSystemGestureInsets = window.systemGestureInsets; originalOnMetricsChanged = window.onMetricsChanged; originalOnLocaleChanged = window.onLocaleChanged; @@ -70,18 +72,22 @@ void main() { tearDown(() { _updateWindowMetrics( - oldDPR, // DPR - oldSize.width, // width - oldSize.height, // height - oldDepth, // depth - oldPadding.top, // padding top - oldPadding.right, // padding right - oldPadding.bottom, // padding bottom - oldPadding.left, // padding left - oldInsets.top, // inset top - oldInsets.right, // inset right - oldInsets.bottom, // inset bottom - oldInsets.left, // inset left + oldDPR, // DPR + oldSize.width, // width + oldSize.height, // height + oldDepth, // depth + oldPadding.top, // padding top + oldPadding.right, // padding right + oldPadding.bottom, // padding bottom + oldPadding.left, // padding left + oldInsets.top, // inset top + oldInsets.right, // inset right + oldInsets.bottom, // inset bottom + oldInsets.left, // inset left + oldSystemGestureInsets.top, // system gesture inset top + oldSystemGestureInsets.right, // system gesture inset right + oldSystemGestureInsets.bottom, // system gesture inset bottom + oldSystemGestureInsets.left, // system gesture inset left ); window.onMetricsChanged = originalOnMetricsChanged; window.onLocaleChanged = originalOnLocaleChanged; @@ -115,7 +121,24 @@ void main() { }); window.onMetricsChanged(); - _updateWindowMetrics(0.1234, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + _updateWindowMetrics( + 0.1234, // DPR + 0.0, // width + 0.0, // height + 0.0, // depth + 0.0, // padding top + 0.0, // padding right + 0.0, // padding bottom + 0.0, // padding left + 0.0, // inset top + 0.0, // inset right + 0.0, // inset bottom + 0.0, // inset left + 0.0, // system gesture inset top + 0.0, // system gesture inset right + 0.0, // system gesture inset bottom + 0.0, // system gesture inset left + ); expect(runZone, isNotNull); expect(runZone, same(innerZone)); expect(devicePixelRatio, equals(0.1234)); @@ -314,8 +337,14 @@ void main() { expect(platformBrightness, equals(Brightness.dark)); }); + test('Window padding/insets/viewPadding/systemGestureInsets', () { + final double oldDPR = window.devicePixelRatio; + final Size oldSize = window.physicalSize; + final double oldPhysicalDepth = window.physicalDepth; + final WindowPadding oldPadding = window.viewPadding; + final WindowPadding oldInsets = window.viewInsets; + final WindowPadding oldSystemGestureInsets = window.systemGestureInsets; - test('Window padding/insets/viewPadding', () { _updateWindowMetrics( 1.0, // DPR 800.0, // width @@ -329,12 +358,17 @@ void main() { 0.0, // inset right 0.0, // inset bottom 0.0, // inset left + 0.0, // system gesture inset top + 0.0, // system gesture inset right + 0.0, // system gesture inset bottom + 0.0, // system gesture inset left ); expect(window.viewInsets.bottom, 0.0); expect(window.viewPadding.bottom, 40.0); expect(window.padding.bottom, 40.0); expect(window.physicalDepth, 100.0); + expect(window.systemGestureInsets.bottom, 0.0); _updateWindowMetrics( 1.0, // DPR @@ -349,12 +383,17 @@ void main() { 0.0, // inset right 400.0, // inset bottom 0.0, // inset left + 0.0, // system gesture insets top + 0.0, // system gesture insets right + 44.0, // system gesture insets bottom + 0.0, // system gesture insets left ); expect(window.viewInsets.bottom, 400.0); expect(window.viewPadding.bottom, 40.0); expect(window.padding.bottom, 0.0); expect(window.physicalDepth, 100.0); + expect(window.systemGestureInsets.bottom, 44.0); }); }); }