[macos] [NSViewController viewWillAppear] can be called multiple times (flutter/engine#34072)

Fixes https://github.com/flutter/flutter/issues/105963
This commit is contained in:
Matej Knopp
2022-06-16 22:52:19 +02:00
committed by GitHub
parent b69d05333b
commit 2c189a40f4
2 changed files with 20 additions and 1 deletions

View File

@@ -429,7 +429,11 @@ static void CommonInit(FlutterViewController* controller) {
// ViewController as a listener for a keyUp event before it's handled by NSApplication, and should
// NOT modify the event to avoid any unexpected behavior.
- (void)listenForMetaModifiedKeyUpEvents {
NSAssert(_keyUpMonitor == nil, @"_keyUpMonitor was already created");
if (_keyUpMonitor != nil) {
// It is possible for [NSViewController viewWillAppear] to be invoked multiple times
// in a row. https://github.com/flutter/flutter/issues/105963
return;
}
FlutterViewController* __weak weakSelf = self;
_keyUpMonitor = [NSEvent
addLocalMonitorForEventsMatchingMask:NSEventMaskKeyUp

View File

@@ -22,6 +22,7 @@
- (bool)testFlagsChangedEventsArePropagatedIfNotHandled;
- (bool)testKeyboardIsRestartedOnEngineRestart;
- (bool)testTrackpadGesturesAreSentToFramework;
- (bool)testViewWillAppearCalledMultipleTimes;
+ (void)respondFalseForSendEvent:(const FlutterKeyEvent&)event
callback:(nullable FlutterKeyEventCallback)callback
@@ -134,6 +135,10 @@ TEST(FlutterViewControllerTest, TestTrackpadGesturesAreSentToFramework) {
ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testTrackpadGesturesAreSentToFramework]);
}
TEST(FlutterViewControllerTest, testViewWillAppearCalledMultipleTimes) {
ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testViewWillAppearCalledMultipleTimes]);
}
} // namespace flutter::testing
@implementation FlutterViewControllerTestObjC
@@ -518,4 +523,14 @@ TEST(FlutterViewControllerTest, TestTrackpadGesturesAreSentToFramework) {
return true;
}
- (bool)testViewWillAppearCalledMultipleTimes {
id engineMock = OCMClassMock([FlutterEngine class]);
FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
nibName:@""
bundle:nil];
[viewController viewWillAppear];
[viewController viewWillAppear];
return true;
}
@end