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

Commit 64ab675

Browse files
author
a-wallen
committed
Add black background default to FlutterView root layer
1 parent 041dfa4 commit 64ab675

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

shell/platform/darwin/macos/framework/Source/FlutterView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
@interface FlutterView : NSView
2424

25+
@property(weak, nonatomic) NSColor* __nullable backgroundColor;
26+
2527
/**
2628
* Initialize a FlutterView that will be rendered to using Metal rendering apis.
2729
*/

shell/platform/darwin/macos/framework/Source/FlutterView.mm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ - (instancetype)initWithMTLDevice:(id<MTLDevice>)device
2828
self = [super initWithFrame:NSZeroRect];
2929
if (self) {
3030
[self setWantsLayer:YES];
31+
[self paintContainingLayerBackgroundColor];
3132
[self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawDuringViewResize];
3233
_reshapeListener = reshapeListener;
3334
_resizableBackingStoreProvider =
@@ -51,6 +52,7 @@ - (instancetype)initWithFrame:(NSRect)frame
5152
self = [super initWithFrame:frame];
5253
if (self) {
5354
[self setWantsLayer:YES];
55+
[self paintContainingLayerBackgroundColor];
5456
_reshapeListener = reshapeListener;
5557
_resizableBackingStoreProvider =
5658
[[FlutterOpenGLResizableBackingStoreProvider alloc] initWithMainContext:mainContext
@@ -84,6 +86,17 @@ - (void)reshaped {
8486
}];
8587
}
8688

89+
- (NSColor*)backgroundColor {
90+
return _backgroundColor ? _backgroundColor : [NSColor blackColor];
91+
}
92+
93+
- (void)paintContainingLayerBackgroundColor {
94+
if (self) {
95+
[self setWantsLayer:YES];
96+
self.layer.backgroundColor = self.backgroundColor.CGColor;
97+
}
98+
}
99+
87100
#pragma mark - NSView overrides
88101

89102
- (void)setFrameSize:(NSSize)newSize {

0 commit comments

Comments
 (0)