未验证 提交 014ab76a 编写于 作者: S Shi-Hao Hong 提交者: GitHub

Pass Android Q insets.systemGestureInsets to Window (#10413)

* Pass Android Q system gesture inset information from insets.systemGestureInsets to Window.systemGestureInsets
上级 e5f9132b
...@@ -18,18 +18,24 @@ dynamic _decodeJSON(String message) { ...@@ -18,18 +18,24 @@ dynamic _decodeJSON(String message) {
@pragma('vm:entry-point') @pragma('vm:entry-point')
// ignore: unused_element // ignore: unused_element
void _updateWindowMetrics(double devicePixelRatio, void _updateWindowMetrics(
double width, double devicePixelRatio,
double height, double width,
double depth, double height,
double viewPaddingTop, double depth,
double viewPaddingRight, double viewPaddingTop,
double viewPaddingBottom, double viewPaddingRight,
double viewPaddingLeft, double viewPaddingBottom,
double viewInsetTop, double viewPaddingLeft,
double viewInsetRight, double viewInsetTop,
double viewInsetBottom, double viewInsetRight,
double viewInsetLeft) { double viewInsetBottom,
double viewInsetLeft,
double systemGestureInsetTop,
double systemGestureInsetRight,
double systemGestureInsetBottom,
double systemGestureInsetLeft,
) {
window window
.._devicePixelRatio = devicePixelRatio .._devicePixelRatio = devicePixelRatio
.._physicalSize = Size(width, height) .._physicalSize = Size(width, height)
...@@ -48,7 +54,12 @@ void _updateWindowMetrics(double devicePixelRatio, ...@@ -48,7 +54,12 @@ void _updateWindowMetrics(double devicePixelRatio,
top: math.max(0.0, viewPaddingTop - viewInsetTop), top: math.max(0.0, viewPaddingTop - viewInsetTop),
right: math.max(0.0, viewPaddingRight - viewInsetRight), right: math.max(0.0, viewPaddingRight - viewInsetRight),
bottom: math.max(0.0, viewPaddingBottom - viewInsetBottom), 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); _invoke(window.onMetricsChanged, window._onMetricsChangedZone);
} }
......
...@@ -637,7 +637,7 @@ class Window { ...@@ -637,7 +637,7 @@ class Window {
/// will likely place system UI, such as the keyboard, that fully obscures /// will likely place system UI, such as the keyboard, that fully obscures
/// any content. /// any content.
/// ///
/// When this changes, [onMetricsChanged] is called. /// When this property changes, [onMetricsChanged] is called.
/// ///
/// The relationship between this [Window.viewInsets], [Window.viewPadding], /// The relationship between this [Window.viewInsets], [Window.viewPadding],
/// and [Window.padding] are described in more detail in the documentation for /// and [Window.padding] are described in more detail in the documentation for
...@@ -664,7 +664,7 @@ class Window { ...@@ -664,7 +664,7 @@ class Window {
/// response to the soft keyboard being visible or hidden, whereas /// response to the soft keyboard being visible or hidden, whereas
/// [Window.padding] will. /// [Window.padding] will.
/// ///
/// When this changes, [onMetricsChanged] is called. /// When this property changes, [onMetricsChanged] is called.
/// ///
/// The relationship between this [Window.viewInsets], [Window.viewPadding], /// The relationship between this [Window.viewInsets], [Window.viewPadding],
/// and [Window.padding] are described in more detail in the documentation for /// and [Window.padding] are described in more detail in the documentation for
...@@ -680,6 +680,24 @@ class Window { ...@@ -680,6 +680,24 @@ class Window {
WindowPadding get viewPadding => _viewPadding; WindowPadding get viewPadding => _viewPadding;
WindowPadding _viewPadding = WindowPadding.zero; 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 /// 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 /// which the application can render, but which may be partially obscured by
/// system UI (such as the system notification area), or or physical /// system UI (such as the system notification area), or or physical
...@@ -711,9 +729,10 @@ class Window { ...@@ -711,9 +729,10 @@ class Window {
WindowPadding _padding = WindowPadding.zero; WindowPadding _padding = WindowPadding.zero;
/// A callback that is invoked whenever the [devicePixelRatio], /// A callback that is invoked whenever the [devicePixelRatio],
/// [physicalSize], [padding], or [viewInsets] values change, for example /// [physicalSize], [padding], [viewInsets], or [systemGestureInsets]
/// when the device is rotated or when the application is resized (e.g. when /// values change, for example when the device is rotated or when the
/// showing applications side-by-side on Android). /// 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 /// The engine invokes this callback in the same zone in which the callback
/// was set. /// was set.
......
...@@ -17,7 +17,11 @@ ViewportMetrics::ViewportMetrics(double p_device_pixel_ratio, ...@@ -17,7 +17,11 @@ ViewportMetrics::ViewportMetrics(double p_device_pixel_ratio,
double p_physical_view_inset_top, double p_physical_view_inset_top,
double p_physical_view_inset_right, double p_physical_view_inset_right,
double p_physical_view_inset_bottom, 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), : device_pixel_ratio(p_device_pixel_ratio),
physical_width(p_physical_width), physical_width(p_physical_width),
physical_height(p_physical_height), physical_height(p_physical_height),
...@@ -28,7 +32,14 @@ ViewportMetrics::ViewportMetrics(double p_device_pixel_ratio, ...@@ -28,7 +32,14 @@ ViewportMetrics::ViewportMetrics(double p_device_pixel_ratio,
physical_view_inset_top(p_physical_view_inset_top), physical_view_inset_top(p_physical_view_inset_top),
physical_view_inset_right(p_physical_view_inset_right), physical_view_inset_right(p_physical_view_inset_right),
physical_view_inset_bottom(p_physical_view_inset_bottom), 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, ViewportMetrics::ViewportMetrics(double p_device_pixel_ratio,
double p_physical_width, double p_physical_width,
......
...@@ -29,7 +29,11 @@ struct ViewportMetrics { ...@@ -29,7 +29,11 @@ struct ViewportMetrics {
double p_physical_view_inset_top, double p_physical_view_inset_top,
double p_physical_view_inset_right, double p_physical_view_inset_right,
double p_physical_view_inset_bottom, 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. // Create a ViewportMetrics instance that contains z information.
ViewportMetrics(double p_device_pixel_ratio, ViewportMetrics(double p_device_pixel_ratio,
...@@ -63,6 +67,10 @@ struct ViewportMetrics { ...@@ -63,6 +67,10 @@ struct ViewportMetrics {
double physical_view_inset_left = 0; double physical_view_inset_left = 0;
double physical_view_inset_front = kUnsetDepth; double physical_view_inset_front = kUnsetDepth;
double physical_view_inset_back = 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 { struct LogicalSize {
......
...@@ -194,6 +194,10 @@ void Window::UpdateWindowMetrics(const ViewportMetrics& metrics) { ...@@ -194,6 +194,10 @@ void Window::UpdateWindowMetrics(const ViewportMetrics& metrics) {
tonic::ToDart(metrics.physical_view_inset_right), tonic::ToDart(metrics.physical_view_inset_right),
tonic::ToDart(metrics.physical_view_inset_bottom), tonic::ToDart(metrics.physical_view_inset_bottom),
tonic::ToDart(metrics.physical_view_inset_left), 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),
})); }));
} }
......
...@@ -573,6 +573,8 @@ abstract class Window { ...@@ -573,6 +573,8 @@ abstract class Window {
WindowPadding get viewPadding => WindowPadding.zero; WindowPadding get viewPadding => WindowPadding.zero;
WindowPadding get systemGestureInsets => WindowPadding.zero;
/// The number of physical pixels on each side of the display rectangle into /// 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 /// which the application can render, but which may be partially obscured by
/// system UI (such as the system notification area), or or physical /// system UI (such as the system notification area), or or physical
......
...@@ -108,7 +108,8 @@ void ShellTest::PumpOneFrame(Shell* shell) { ...@@ -108,7 +108,8 @@ void ShellTest::PumpOneFrame(Shell* shell) {
fml::AutoResetWaitableEvent latch; fml::AutoResetWaitableEvent latch;
shell->GetTaskRunners().GetUITaskRunner()->PostTask( shell->GetTaskRunners().GetUITaskRunner()->PostTask(
[&latch, engine = shell->weak_engine_]() { [&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(), engine->animator_->BeginFrame(fml::TimePoint::Now(),
fml::TimePoint::Now()); fml::TimePoint::Now());
latch.Signal(); latch.Signal();
......
...@@ -638,7 +638,7 @@ TEST_F(ShellTest, SetResourceCacheSize) { ...@@ -638,7 +638,7 @@ TEST_F(ShellTest, SetResourceCacheSize) {
fml::TaskRunner::RunNowOrPostTask( fml::TaskRunner::RunNowOrPostTask(
shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
shell->GetPlatformView()->SetViewportMetrics( 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()); PumpOneFrame(shell.get());
...@@ -658,7 +658,7 @@ TEST_F(ShellTest, SetResourceCacheSize) { ...@@ -658,7 +658,7 @@ TEST_F(ShellTest, SetResourceCacheSize) {
fml::TaskRunner::RunNowOrPostTask( fml::TaskRunner::RunNowOrPostTask(
shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
shell->GetPlatformView()->SetViewportMetrics( 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()); PumpOneFrame(shell.get());
...@@ -676,7 +676,7 @@ TEST_F(ShellTest, SetResourceCacheSizeEarly) { ...@@ -676,7 +676,7 @@ TEST_F(ShellTest, SetResourceCacheSizeEarly) {
fml::TaskRunner::RunNowOrPostTask( fml::TaskRunner::RunNowOrPostTask(
shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
shell->GetPlatformView()->SetViewportMetrics( 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()); PumpOneFrame(shell.get());
...@@ -704,7 +704,7 @@ TEST_F(ShellTest, SetResourceCacheSizeNotifiesDart) { ...@@ -704,7 +704,7 @@ TEST_F(ShellTest, SetResourceCacheSizeNotifiesDart) {
fml::TaskRunner::RunNowOrPostTask( fml::TaskRunner::RunNowOrPostTask(
shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
shell->GetPlatformView()->SetViewportMetrics( 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()); PumpOneFrame(shell.get());
......
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
package io.flutter.embedding.android; package io.flutter.embedding.android;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Insets;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Build; import android.os.Build;
import android.os.LocaleList; import android.os.LocaleList;
...@@ -296,6 +298,10 @@ public class FlutterView extends FrameLayout { ...@@ -296,6 +298,10 @@ public class FlutterView extends FrameLayout {
@Override @Override
@TargetApi(20) @TargetApi(20)
@RequiresApi(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 @NonNull
public final WindowInsets onApplyWindowInsets(@NonNull WindowInsets insets) { public final WindowInsets onApplyWindowInsets(@NonNull WindowInsets insets) {
WindowInsets newInsets = super.onApplyWindowInsets(insets); WindowInsets newInsets = super.onApplyWindowInsets(insets);
...@@ -312,11 +318,21 @@ public class FlutterView extends FrameLayout { ...@@ -312,11 +318,21 @@ public class FlutterView extends FrameLayout {
viewportMetrics.viewInsetBottom = insets.getSystemWindowInsetBottom(); viewportMetrics.viewInsetBottom = insets.getSystemWindowInsetBottom();
viewportMetrics.viewInsetLeft = 0; 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" Log.v(TAG, "Updating window insets (onApplyWindowInsets()):\n"
+ "Status bar insets: Top: " + viewportMetrics.paddingTop + "Status bar insets: Top: " + viewportMetrics.paddingTop
+ ", Left: " + viewportMetrics.paddingLeft + ", Right: " + viewportMetrics.paddingRight + "\n" + ", Left: " + viewportMetrics.paddingLeft + ", Right: " + viewportMetrics.paddingRight + "\n"
+ "Keyboard insets: Bottom: " + viewportMetrics.viewInsetBottom + "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(); sendViewportMetricsToFlutter();
......
...@@ -356,7 +356,11 @@ public class FlutterJNI { ...@@ -356,7 +356,11 @@ public class FlutterJNI {
int physicalViewInsetTop, int physicalViewInsetTop,
int physicalViewInsetRight, int physicalViewInsetRight,
int physicalViewInsetBottom, int physicalViewInsetBottom,
int physicalViewInsetLeft int physicalViewInsetLeft,
int systemGestureInsetTop,
int systemGestureInsetRight,
int systemGestureInsetBottom,
int systemGestureInsetLeft
) { ) {
ensureRunningOnMainThread(); ensureRunningOnMainThread();
ensureAttachedToNative(); ensureAttachedToNative();
...@@ -372,7 +376,11 @@ public class FlutterJNI { ...@@ -372,7 +376,11 @@ public class FlutterJNI {
physicalViewInsetTop, physicalViewInsetTop,
physicalViewInsetRight, physicalViewInsetRight,
physicalViewInsetBottom, physicalViewInsetBottom,
physicalViewInsetLeft physicalViewInsetLeft,
systemGestureInsetTop,
systemGestureInsetRight,
systemGestureInsetBottom,
systemGestureInsetLeft
); );
} }
...@@ -388,7 +396,11 @@ public class FlutterJNI { ...@@ -388,7 +396,11 @@ public class FlutterJNI {
int physicalViewInsetTop, int physicalViewInsetTop,
int physicalViewInsetRight, int physicalViewInsetRight,
int physicalViewInsetBottom, int physicalViewInsetBottom,
int physicalViewInsetLeft int physicalViewInsetLeft,
int systemGestureInsetTop,
int systemGestureInsetRight,
int systemGestureInsetBottom,
int systemGestureInsetLeft
); );
//----- End Render Surface Support ----- //----- End Render Surface Support -----
......
...@@ -202,7 +202,9 @@ public class FlutterRenderer implements TextureRegistry { ...@@ -202,7 +202,9 @@ public class FlutterRenderer implements TextureRegistry {
+ "Padding - L: " + viewportMetrics.paddingLeft + ", T: " + viewportMetrics.paddingTop + "Padding - L: " + viewportMetrics.paddingLeft + ", T: " + viewportMetrics.paddingTop
+ ", R: " + viewportMetrics.paddingRight + ", B: " + viewportMetrics.paddingBottom + "\n" + ", R: " + viewportMetrics.paddingRight + ", B: " + viewportMetrics.paddingBottom + "\n"
+ "Insets - L: " + viewportMetrics.viewInsetLeft + ", T: " + viewportMetrics.viewInsetTop + "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( flutterJNI.setViewportMetrics(
viewportMetrics.devicePixelRatio, viewportMetrics.devicePixelRatio,
...@@ -215,7 +217,11 @@ public class FlutterRenderer implements TextureRegistry { ...@@ -215,7 +217,11 @@ public class FlutterRenderer implements TextureRegistry {
viewportMetrics.viewInsetTop, viewportMetrics.viewInsetTop,
viewportMetrics.viewInsetRight, viewportMetrics.viewInsetRight,
viewportMetrics.viewInsetBottom, viewportMetrics.viewInsetBottom,
viewportMetrics.viewInsetLeft viewportMetrics.viewInsetLeft,
viewportMetrics.systemGestureInsetTop,
viewportMetrics.systemGestureInsetRight,
viewportMetrics.systemGestureInsetBottom,
viewportMetrics.systemGestureInsetLeft
); );
} }
...@@ -346,5 +352,9 @@ public class FlutterRenderer implements TextureRegistry { ...@@ -346,5 +352,9 @@ public class FlutterRenderer implements TextureRegistry {
public int viewInsetRight = 0; public int viewInsetRight = 0;
public int viewInsetBottom = 0; public int viewInsetBottom = 0;
public int viewInsetLeft = 0; public int viewInsetLeft = 0;
public int systemGestureInsetTop = 0;
public int systemGestureInsetRight = 0;
public int systemGestureInsetBottom = 0;
public int systemGestureInsetLeft = 0;
} }
} }
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
package io.flutter.view; package io.flutter.view;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.ContextWrapper; import android.content.ContextWrapper;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Insets;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.SurfaceTexture; import android.graphics.SurfaceTexture;
...@@ -100,6 +102,10 @@ public class FlutterView extends SurfaceView implements BinaryMessenger, Texture ...@@ -100,6 +102,10 @@ public class FlutterView extends SurfaceView implements BinaryMessenger, Texture
int physicalViewInsetRight = 0; int physicalViewInsetRight = 0;
int physicalViewInsetBottom = 0; int physicalViewInsetBottom = 0;
int physicalViewInsetLeft = 0; int physicalViewInsetLeft = 0;
int systemGestureInsetTop = 0;
int systemGestureInsetRight = 0;
int systemGestureInsetBottom = 0;
int systemGestureInsetLeft = 0;
} }
private final DartExecutor dartExecutor; private final DartExecutor dartExecutor;
...@@ -542,9 +548,13 @@ public class FlutterView extends SurfaceView implements BinaryMessenger, Texture ...@@ -542,9 +548,13 @@ public class FlutterView extends SurfaceView implements BinaryMessenger, Texture
// This callback is not present in API < 20, which means lower API devices will see // 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 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 @Override
@TargetApi(20) @TargetApi(20)
@RequiresApi(20) @RequiresApi(20)
@SuppressLint({"InlinedApi", "NewApi"})
public final WindowInsets onApplyWindowInsets(WindowInsets insets) { public final WindowInsets onApplyWindowInsets(WindowInsets insets) {
boolean statusBarHidden = boolean statusBarHidden =
(SYSTEM_UI_FLAG_FULLSCREEN & getWindowSystemUiVisibility()) != 0; (SYSTEM_UI_FLAG_FULLSCREEN & getWindowSystemUiVisibility()) != 0;
...@@ -574,6 +584,14 @@ public class FlutterView extends SurfaceView implements BinaryMessenger, Texture ...@@ -574,6 +584,14 @@ public class FlutterView extends SurfaceView implements BinaryMessenger, Texture
mMetrics.physicalViewInsetBottom = mMetrics.physicalViewInsetBottom =
navigationBarHidden ? calculateBottomKeyboardInset(insets) : insets.getSystemWindowInsetBottom(); navigationBarHidden ? calculateBottomKeyboardInset(insets) : insets.getSystemWindowInsetBottom();
mMetrics.physicalViewInsetLeft = 0; 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(); updateViewportMetrics();
return super.onApplyWindowInsets(insets); return super.onApplyWindowInsets(insets);
} }
...@@ -642,10 +660,23 @@ public class FlutterView extends SurfaceView implements BinaryMessenger, Texture ...@@ -642,10 +660,23 @@ public class FlutterView extends SurfaceView implements BinaryMessenger, Texture
private void updateViewportMetrics() { private void updateViewportMetrics() {
if (!isAttached()) if (!isAttached())
return; return;
mNativeView.getFlutterJNI().setViewportMetrics(mMetrics.devicePixelRatio, mMetrics.physicalWidth, mNativeView.getFlutterJNI().setViewportMetrics(
mMetrics.physicalHeight, mMetrics.physicalPaddingTop, mMetrics.physicalPaddingRight, mMetrics.devicePixelRatio,
mMetrics.physicalPaddingBottom, mMetrics.physicalPaddingLeft, mMetrics.physicalViewInsetTop, mMetrics.physicalWidth,
mMetrics.physicalViewInsetRight, mMetrics.physicalViewInsetBottom, mMetrics.physicalViewInsetLeft); 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. // Called by native to update the semantics/accessibility tree.
......
...@@ -261,7 +261,11 @@ static void SetViewportMetrics(JNIEnv* env, ...@@ -261,7 +261,11 @@ static void SetViewportMetrics(JNIEnv* env,
jint physicalViewInsetTop, jint physicalViewInsetTop,
jint physicalViewInsetRight, jint physicalViewInsetRight,
jint physicalViewInsetBottom, jint physicalViewInsetBottom,
jint physicalViewInsetLeft) { jint physicalViewInsetLeft,
jint systemGestureInsetTop,
jint systemGestureInsetRight,
jint systemGestureInsetBottom,
jint systemGestureInsetLeft) {
const flutter::ViewportMetrics metrics{ const flutter::ViewportMetrics metrics{
static_cast<double>(devicePixelRatio), static_cast<double>(devicePixelRatio),
static_cast<double>(physicalWidth), static_cast<double>(physicalWidth),
...@@ -274,6 +278,10 @@ static void SetViewportMetrics(JNIEnv* env, ...@@ -274,6 +278,10 @@ static void SetViewportMetrics(JNIEnv* env,
static_cast<double>(physicalViewInsetRight), static_cast<double>(physicalViewInsetRight),
static_cast<double>(physicalViewInsetBottom), static_cast<double>(physicalViewInsetBottom),
static_cast<double>(physicalViewInsetLeft), static_cast<double>(physicalViewInsetLeft),
static_cast<double>(systemGestureInsetTop),
static_cast<double>(systemGestureInsetRight),
static_cast<double>(systemGestureInsetBottom),
static_cast<double>(systemGestureInsetLeft),
}; };
ANDROID_SHELL_HOLDER->GetPlatformView()->SetViewportMetrics(metrics); ANDROID_SHELL_HOLDER->GetPlatformView()->SetViewportMetrics(metrics);
...@@ -541,7 +549,7 @@ bool RegisterApi(JNIEnv* env) { ...@@ -541,7 +549,7 @@ bool RegisterApi(JNIEnv* env) {
}, },
{ {
.name = "nativeSetViewportMetrics", .name = "nativeSetViewportMetrics",
.signature = "(JFIIIIIIIIII)V", .signature = "(JFIIIIIIIIIIIIII)V",
.fnPtr = reinterpret_cast<void*>(&SetViewportMetrics), .fnPtr = reinterpret_cast<void*>(&SetViewportMetrics),
}, },
{ {
......
...@@ -48,6 +48,7 @@ void main() { ...@@ -48,6 +48,7 @@ void main() {
double oldDepth; double oldDepth;
WindowPadding oldPadding; WindowPadding oldPadding;
WindowPadding oldInsets; WindowPadding oldInsets;
WindowPadding oldSystemGestureInsets;
setUp(() { setUp(() {
oldDPR = window.devicePixelRatio; oldDPR = window.devicePixelRatio;
...@@ -55,6 +56,7 @@ void main() { ...@@ -55,6 +56,7 @@ void main() {
oldDepth = window.physicalDepth; oldDepth = window.physicalDepth;
oldPadding = window.viewPadding; oldPadding = window.viewPadding;
oldInsets = window.viewInsets; oldInsets = window.viewInsets;
oldSystemGestureInsets = window.systemGestureInsets;
originalOnMetricsChanged = window.onMetricsChanged; originalOnMetricsChanged = window.onMetricsChanged;
originalOnLocaleChanged = window.onLocaleChanged; originalOnLocaleChanged = window.onLocaleChanged;
...@@ -70,18 +72,22 @@ void main() { ...@@ -70,18 +72,22 @@ void main() {
tearDown(() { tearDown(() {
_updateWindowMetrics( _updateWindowMetrics(
oldDPR, // DPR oldDPR, // DPR
oldSize.width, // width oldSize.width, // width
oldSize.height, // height oldSize.height, // height
oldDepth, // depth oldDepth, // depth
oldPadding.top, // padding top oldPadding.top, // padding top
oldPadding.right, // padding right oldPadding.right, // padding right
oldPadding.bottom, // padding bottom oldPadding.bottom, // padding bottom
oldPadding.left, // padding left oldPadding.left, // padding left
oldInsets.top, // inset top oldInsets.top, // inset top
oldInsets.right, // inset right oldInsets.right, // inset right
oldInsets.bottom, // inset bottom oldInsets.bottom, // inset bottom
oldInsets.left, // inset left 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.onMetricsChanged = originalOnMetricsChanged;
window.onLocaleChanged = originalOnLocaleChanged; window.onLocaleChanged = originalOnLocaleChanged;
...@@ -115,7 +121,24 @@ void main() { ...@@ -115,7 +121,24 @@ void main() {
}); });
window.onMetricsChanged(); 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, isNotNull);
expect(runZone, same(innerZone)); expect(runZone, same(innerZone));
expect(devicePixelRatio, equals(0.1234)); expect(devicePixelRatio, equals(0.1234));
...@@ -314,8 +337,14 @@ void main() { ...@@ -314,8 +337,14 @@ void main() {
expect(platformBrightness, equals(Brightness.dark)); 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( _updateWindowMetrics(
1.0, // DPR 1.0, // DPR
800.0, // width 800.0, // width
...@@ -329,12 +358,17 @@ void main() { ...@@ -329,12 +358,17 @@ void main() {
0.0, // inset right 0.0, // inset right
0.0, // inset bottom 0.0, // inset bottom
0.0, // inset left 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.viewInsets.bottom, 0.0);
expect(window.viewPadding.bottom, 40.0); expect(window.viewPadding.bottom, 40.0);
expect(window.padding.bottom, 40.0); expect(window.padding.bottom, 40.0);
expect(window.physicalDepth, 100.0); expect(window.physicalDepth, 100.0);
expect(window.systemGestureInsets.bottom, 0.0);
_updateWindowMetrics( _updateWindowMetrics(
1.0, // DPR 1.0, // DPR
...@@ -349,12 +383,17 @@ void main() { ...@@ -349,12 +383,17 @@ void main() {
0.0, // inset right 0.0, // inset right
400.0, // inset bottom 400.0, // inset bottom
0.0, // inset left 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.viewInsets.bottom, 400.0);
expect(window.viewPadding.bottom, 40.0); expect(window.viewPadding.bottom, 40.0);
expect(window.padding.bottom, 0.0); expect(window.padding.bottom, 0.0);
expect(window.physicalDepth, 100.0); expect(window.physicalDepth, 100.0);
expect(window.systemGestureInsets.bottom, 44.0);
}); });
}); });
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册