fixes crash when sets mouseTrackingMode before view is loaded (flutter/engine#26576)

This commit is contained in:
chunhtai
2021-06-04 11:09:02 -07:00
committed by GitHub
parent 166cc98d99
commit 1d81ba27ca
2 changed files with 15 additions and 1 deletions

View File

@@ -396,7 +396,11 @@ static void CommonInit(FlutterViewController* controller) {
}
- (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;

View File

@@ -140,6 +140,16 @@ TEST(FlutterViewController, SetsFlutterViewFirstResponderWhenAccessibilityDisabl
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]);
}