-
Notifications
You must be signed in to change notification settings - Fork 6k
Move detection of cutouts in Android engine to onApplyWindowInsets
#55992
Changes from all commits
37b9534
e91ca73
7fe4077
9f8e7cc
c90fc86
6ed658c
4b821ba
0feba58
199d6da
764b169
a5dc460
bd36a1e
a6bd2e7
1d6fde5
078e796
2829a1a
e4c26bb
0578cae
3673fde
2992e23
4f57f90
5bf9b38
91f506d
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 |
---|---|---|
|
@@ -1157,6 +1157,13 @@ public void stopRenderingToSurface() { | |
} | ||
} | ||
|
||
private void translateFeatureBounds(int[] displayFeatureBounds, int offset, Rect bounds) { | ||
displayFeatureBounds[offset] = bounds.left; | ||
displayFeatureBounds[offset + 1] = bounds.top; | ||
displayFeatureBounds[offset + 2] = bounds.right; | ||
displayFeatureBounds[offset + 3] = bounds.bottom; | ||
} | ||
|
||
/** | ||
* Notifies Flutter that the viewport metrics, e.g. window height and width, have changed. | ||
* | ||
|
@@ -1207,20 +1214,31 @@ public void setViewportMetrics(@NonNull ViewportMetrics viewportMetrics) { | |
+ viewportMetrics.systemGestureInsetRight | ||
+ "\n" | ||
+ "Display Features: " | ||
+ viewportMetrics.displayFeatures.size()); | ||
|
||
int[] displayFeaturesBounds = new int[viewportMetrics.displayFeatures.size() * 4]; | ||
int[] displayFeaturesType = new int[viewportMetrics.displayFeatures.size()]; | ||
int[] displayFeaturesState = new int[viewportMetrics.displayFeatures.size()]; | ||
+ viewportMetrics.displayFeatures.size() | ||
+ "\n" | ||
+ "Display Cutouts: " | ||
+ viewportMetrics.displayCutouts.size()); | ||
|
||
int totalFeaturesAndCutouts = | ||
viewportMetrics.displayFeatures.size() + viewportMetrics.displayCutouts.size(); | ||
int[] displayFeaturesBounds = new int[totalFeaturesAndCutouts * 4]; | ||
int[] displayFeaturesType = new int[totalFeaturesAndCutouts]; | ||
int[] displayFeaturesState = new int[totalFeaturesAndCutouts]; | ||
for (int i = 0; i < viewportMetrics.displayFeatures.size(); i++) { | ||
DisplayFeature displayFeature = viewportMetrics.displayFeatures.get(i); | ||
displayFeaturesBounds[4 * i] = displayFeature.bounds.left; | ||
displayFeaturesBounds[4 * i + 1] = displayFeature.bounds.top; | ||
displayFeaturesBounds[4 * i + 2] = displayFeature.bounds.right; | ||
displayFeaturesBounds[4 * i + 3] = displayFeature.bounds.bottom; | ||
translateFeatureBounds(displayFeaturesBounds, 4 * i, displayFeature.bounds); | ||
displayFeaturesType[i] = displayFeature.type.encodedValue; | ||
displayFeaturesState[i] = displayFeature.state.encodedValue; | ||
} | ||
int cutoutOffset = viewportMetrics.displayFeatures.size() * 4; | ||
for (int i = 0; i < viewportMetrics.displayCutouts.size(); i++) { | ||
DisplayFeature displayCutout = viewportMetrics.displayCutouts.get(i); | ||
translateFeatureBounds(displayFeaturesBounds, cutoutOffset + 4 * i, displayCutout.bounds); | ||
displayFeaturesType[viewportMetrics.displayFeatures.size() + i] = | ||
displayCutout.type.encodedValue; | ||
displayFeaturesState[viewportMetrics.displayFeatures.size() + i] = | ||
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. It seems weird to intentionally be setting unknown here. It seems to be what were were doing before but should we have added a state enum value for these? 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 current doc-comment for 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. seems odd but out of scope for this pr. |
||
displayCutout.state.encodedValue; | ||
} | ||
|
||
flutterJNI.setViewportMetrics( | ||
viewportMetrics.devicePixelRatio, | ||
|
@@ -1335,7 +1353,29 @@ boolean validate() { | |
return width > 0 && height > 0 && devicePixelRatio > 0; | ||
} | ||
|
||
public List<DisplayFeature> displayFeatures = new ArrayList<>(); | ||
// Features | ||
private final List<DisplayFeature> displayFeatures = new ArrayList<>(); | ||
|
||
// Specifically display cutouts. | ||
private final List<DisplayFeature> displayCutouts = new ArrayList<>(); | ||
|
||
public List<DisplayFeature> getDisplayFeatures() { | ||
return displayFeatures; | ||
} | ||
|
||
public List<DisplayFeature> getDisplayCutouts() { | ||
return displayCutouts; | ||
} | ||
|
||
public void setDisplayFeatures(List<DisplayFeature> newFeatures) { | ||
displayFeatures.clear(); | ||
displayFeatures.addAll(newFeatures); | ||
} | ||
|
||
public void setDisplayCutouts(List<DisplayFeature> newCutouts) { | ||
displayCutouts.clear(); | ||
displayCutouts.addAll(newCutouts); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -1358,12 +1398,6 @@ public DisplayFeature(Rect bounds, DisplayFeatureType type, DisplayFeatureState | |
this.type = type; | ||
this.state = state; | ||
} | ||
|
||
public DisplayFeature(Rect bounds, DisplayFeatureType type) { | ||
this.bounds = bounds; | ||
this.type = type; | ||
this.state = DisplayFeatureState.UNKNOWN; | ||
} | ||
} | ||
|
||
/** | ||
|
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 dont understand why only the display cutout features need to be moved and not all the features in this method.
Unrelated to your change it is weird that this had a targetApi of 28 and still did an api check inside the method.
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.
My understanding is that this listener is triggered (only) on changes to
DisplayFeature
s, which include hinges and display folds but (from @yaakovschectman and my manual testing) not camera cutouts (or other top of device sensors).Those are instead reported as
WindowInsets
with a nonzero element reported byWindowInsets.getDisplayCutout()
(and underlying changes to them instead triggeronApplyWindowInsets
).Flutter was conflating both of these two distinct groups into a
List<FlutterRenderer.DisplayFeature>
, but the list would only get updated in the case of changes to the former group, because underlying updates to the latter didn't trigger the listener (and we didn't handle them appropriately in the listener that was triggered).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.
OK that makes sense thanks for the explanation.