[macos] [NSViewController viewWillAppear] can be called multiple times (flutter/engine#34072)
Fixes https://github.com/flutter/flutter/issues/105963
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user