[Android] Remove overlay when platform views are removed from screen. (#162908)

When there are no more platform views, make sure the overlay layer is
hidden. When a platform view is added again, show the overlay. The
show/hide allows us to avoid continually recreating and destroying the
overlay surface + swapchain when a platform view slides in and out of
frame.

To further reduce memory usage, we could do a delayed de-allocation of
the overlay layer (say after 50 frames of no platform view, destroy it).
But I'm leaving this to a follow up.
This commit is contained in:
Jonah Williams
2025-02-10 18:29:07 -08:00
committed by GitHub
parent 2d39a739ea
commit 7cd9e0f640
14 changed files with 191 additions and 32 deletions

View File

@@ -41,6 +41,8 @@ void main() async {
});
tearDownAll(() async {
await flutterDriver.tap(find.byValueKey('AddOverlay'));
await nativeDriver.close();
await flutterDriver.close();
});
@@ -72,4 +74,16 @@ void main() async {
matchesGoldenFile('$goldenPrefix.platform_view_portait_rotated_back.png'),
);
}, timeout: Timeout.none);
// Note: this doesn't reset the app so if additional test cases are added
// make sure to press the button again.
test('should remove overlay when platform view is removed', () async {
await flutterDriver.tap(find.byValueKey('RemoveOverlay'));
await Future<void>.delayed(const Duration(seconds: 1));
await expectLater(
nativeDriver.screenshot(),
matchesGoldenFile('$goldenPrefix.removed_overlay.png'),
);
}, timeout: Timeout.none);
}