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

Commit c5426e8

Browse files
authored
fixes crash when sets mouseTrackingMode before view is loaded (#26576)
1 parent 9e44c7f commit c5426e8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,11 @@ - (void)listenForMetaModifiedKeyUpEvents {
396396
}
397397

398398
- (void)configureTrackingArea {
399-
NSAssert(self.viewLoaded, @"View must be loaded before setting tracking area");
399+
if (!self.viewLoaded) {
400+
// The viewDidLoad will call configureTrackingArea again when
401+
// the view is actually loaded.
402+
return;
403+
}
400404
if (_mouseTrackingMode != FlutterMouseTrackingModeNone && self.flutterView) {
401405
NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved |
402406
NSTrackingInVisibleRect | NSTrackingEnabledDuringMouseDrag;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ + (void)respondFalseForSendEvent:(const FlutterKeyEvent&)event
140140
EXPECT_EQ([window firstResponder], viewController.flutterView);
141141
}
142142

143+
TEST(FlutterViewController, CanSetMouseTrackingModeBeforeViewLoaded) {
144+
NSString* fixtures = @(testing::GetFixturesPath());
145+
FlutterDartProject* project = [[FlutterDartProject alloc]
146+
initWithAssetsPath:fixtures
147+
ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
148+
FlutterViewController* viewController = [[FlutterViewController alloc] initWithProject:project];
149+
viewController.mouseTrackingMode = FlutterMouseTrackingModeInActiveApp;
150+
ASSERT_EQ(viewController.mouseTrackingMode, FlutterMouseTrackingModeInActiveApp);
151+
}
152+
143153
TEST(FlutterViewControllerTest, TestKeyEventsAreSentToFramework) {
144154
ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testKeyEventsAreSentToFramework]);
145155
}

0 commit comments

Comments
 (0)