diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm b/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm index 942ab17461ea0..d969d556cc4e7 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm @@ -396,7 +396,11 @@ - (void)listenForMetaModifiedKeyUpEvents { } - (void)configureTrackingArea { - NSAssert(self.viewLoaded, @"View must be loaded before setting tracking area"); + if (!self.viewLoaded) { + // The viewDidLoad will call configureTrackingArea again when + // the view is actually loaded. + return; + } if (_mouseTrackingMode != FlutterMouseTrackingModeNone && self.flutterView) { NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingInVisibleRect | NSTrackingEnabledDuringMouseDrag; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm index c0cd3ce4f8100..9ba946617816b 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm @@ -140,6 +140,16 @@ + (void)respondFalseForSendEvent:(const FlutterKeyEvent&)event EXPECT_EQ([window firstResponder], viewController.flutterView); } +TEST(FlutterViewController, CanSetMouseTrackingModeBeforeViewLoaded) { + NSString* fixtures = @(testing::GetFixturesPath()); + FlutterDartProject* project = [[FlutterDartProject alloc] + initWithAssetsPath:fixtures + ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]]; + FlutterViewController* viewController = [[FlutterViewController alloc] initWithProject:project]; + viewController.mouseTrackingMode = FlutterMouseTrackingModeInActiveApp; + ASSERT_EQ(viewController.mouseTrackingMode, FlutterMouseTrackingModeInActiveApp); +} + TEST(FlutterViewControllerTest, TestKeyEventsAreSentToFramework) { ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testKeyEventsAreSentToFramework]); }