forked from firka/flutter
Pass Android Q insets.systemGestureInsets to Window (flutter/engine#10413)
* Pass Android Q system gesture inset information from insets.systemGestureInsets to Window.systemGestureInsets
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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),
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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 @@ public class FlutterView extends FrameLayout {
|
||||
@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 class FlutterView extends FrameLayout {
|
||||
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();
|
||||
|
||||
|
||||
@@ -356,7 +356,11 @@ public class FlutterJNI {
|
||||
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 class FlutterJNI {
|
||||
physicalViewInsetTop,
|
||||
physicalViewInsetRight,
|
||||
physicalViewInsetBottom,
|
||||
physicalViewInsetLeft
|
||||
physicalViewInsetLeft,
|
||||
systemGestureInsetTop,
|
||||
systemGestureInsetRight,
|
||||
systemGestureInsetBottom,
|
||||
systemGestureInsetLeft
|
||||
);
|
||||
}
|
||||
|
||||
@@ -388,7 +396,11 @@ public class FlutterJNI {
|
||||
int physicalViewInsetTop,
|
||||
int physicalViewInsetRight,
|
||||
int physicalViewInsetBottom,
|
||||
int physicalViewInsetLeft
|
||||
int physicalViewInsetLeft,
|
||||
int systemGestureInsetTop,
|
||||
int systemGestureInsetRight,
|
||||
int systemGestureInsetBottom,
|
||||
int systemGestureInsetLeft
|
||||
);
|
||||
//----- End Render Surface Support -----
|
||||
|
||||
|
||||
@@ -202,7 +202,9 @@ public class FlutterRenderer implements TextureRegistry {
|
||||
+ "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 class FlutterRenderer implements TextureRegistry {
|
||||
viewportMetrics.viewInsetTop,
|
||||
viewportMetrics.viewInsetRight,
|
||||
viewportMetrics.viewInsetBottom,
|
||||
viewportMetrics.viewInsetLeft
|
||||
viewportMetrics.viewInsetLeft,
|
||||
viewportMetrics.systemGestureInsetTop,
|
||||
viewportMetrics.systemGestureInsetRight,
|
||||
viewportMetrics.systemGestureInsetBottom,
|
||||
viewportMetrics.systemGestureInsetLeft
|
||||
);
|
||||
}
|
||||
|
||||
@@ -346,5 +352,9 @@ public class FlutterRenderer implements TextureRegistry {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 @@ public class FlutterView extends SurfaceView implements BinaryMessenger, Texture
|
||||
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 @@ public class FlutterView extends SurfaceView implements BinaryMessenger, Texture
|
||||
|
||||
// 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 class FlutterView extends SurfaceView implements BinaryMessenger, Texture
|
||||
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 class FlutterView extends SurfaceView implements BinaryMessenger, Texture
|
||||
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.
|
||||
|
||||
@@ -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<double>(devicePixelRatio),
|
||||
static_cast<double>(physicalWidth),
|
||||
@@ -274,6 +278,10 @@ static void SetViewportMetrics(JNIEnv* env,
|
||||
static_cast<double>(physicalViewInsetRight),
|
||||
static_cast<double>(physicalViewInsetBottom),
|
||||
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);
|
||||
@@ -541,7 +549,7 @@ bool RegisterApi(JNIEnv* env) {
|
||||
},
|
||||
{
|
||||
.name = "nativeSetViewportMetrics",
|
||||
.signature = "(JFIIIIIIIIII)V",
|
||||
.signature = "(JFIIIIIIIIIIIIII)V",
|
||||
.fnPtr = reinterpret_cast<void*>(&SetViewportMetrics),
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user