Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[iOS] Ensure FlutterView's background color is not nil to avoid CAMetalLayer nextDrawable being time-consuming #39359

Merged
merged 3 commits into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ - (instancetype)initWithDelegate:(id<FlutterViewEngineDelegate>)delegate opaque:
if (self) {
_delegate = delegate;
self.layer.opaque = opaque;

// This line is necessary. CoreAnimation(or UIKit) may take this to do
// something to compute the final frame presented on screen, if we don't set this,
// it will make it take long time for us to take next CAMetalDrawable and will
// cause constant junk during rendering.
self.backgroundColor = UIColor.clearColor;
}

return self;
Expand Down
6 changes: 6 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ - (void)testFlutterViewEnableSemanticsWhenIsAccessibilityElementIsCalled {
XCTAssertTrue(delegate.callbackCalled);
}

- (void)testFlutterViewBackgroundColorIsNotNil {
FakeDelegate* delegate = [[FakeDelegate alloc] init];
FlutterView* view = [[FlutterView alloc] initWithDelegate:delegate opaque:NO];
XCTAssertNotNil(view.backgroundColor);
}

@end