-
Notifications
You must be signed in to change notification settings - Fork 6k
Pass Android Q insets.systemGestureInsets to Window #10413
Changes from all commits
0c1252d
32a6ee7
59c39b5
e908f71
0577e2e
f8c3715
a26d365
db78d67
eef5685
ebe1348
ab80439
0ce87cc
6a37a63
d420f27
8d78d2a
01282b6
d32f014
ab83eac
33b6ea0
e560333
0a465b7
ff27613
bc72f98
98cd1f2
a1f6cbf
7dac454
3f4af17
a8b17b4
8309143
7f50a08
ab8f418
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any implications of defining gesture insets in such a central location? I'm guessing that this definition of viewport metrics is used for all platforms, right? If so, would gesture insets ever make sense on Windows, Linux, Mac, and other non-touch surfaces?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main reason I decided to define gesture insets this way is that I could foresee other platforms using system gesture navigations as well. I'll need to see how iOS currently handles this, but I know that swiping up from the bottom of the screen on later iPhones is analogous to pressing the home button on older models of the phone. |
||
| double physical_system_gesture_inset_right = 0; | ||
| double physical_system_gesture_inset_bottom = 0; | ||
| double physical_system_gesture_inset_left = 0; | ||
| }; | ||
|
|
||
| struct LogicalSize { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think it be worth it to still add a test for the non Q case in this PR where these are set to zero? It would just basically be verifying the current behavior and making sure that these lines were guarded and didn't cause problems on lower SDK versions. So some but not a huge amount of value from them.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know the root cause of the problem, but I believe that because the TargetApi is set to 20 and the tests only use up to SDK 16 at runtime, the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, right. The entire method here requires at least API 20, and our setup only includes API 16 right now. If you wanted to test just the non-Q parts of this method, you should be able to bring in API 21 without any trouble. Robolectric has supported it since 3.0 (we're on 3.8). It's 29/Q specifically that required upgrading to 4.3 and is currently blocked. But doing this has some extra overhead where it would require bringing in another robolectric android package for the right SDK (like robolectric.android-all:5.0.0_r2-robolectric-0) and adding it to CIPD as described here. So at that point I'm not sure if it's worth the hassle. There may be some unknown unknowns that cause it to take extra time. |
||
| 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(); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary for this PR, but can we follow up with a diagram of the various paddings and insets and put it on the wiki, or on the website, and then maybe link to it from here?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created an issue (flutter/flutter#38649). some work already exists in the MediaQueryData API docs, we could elaborate on the new insets there and add links to this particular resource once everything has been solidified.