Skip to content

Commit

Permalink
[macos] [NSViewController viewWillAppear] can be called multiple times (
Browse files Browse the repository at this point in the history
  • Loading branch information
knopp authored Jun 16, 2022
1 parent e698079 commit 5fb4a53
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ - (BOOL)launchEngine {
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ - (bool)testKeyEventsAreNotPropagatedIfHandled;
- (bool)testFlagsChangedEventsArePropagatedIfNotHandled;
- (bool)testKeyboardIsRestartedOnEngineRestart;
- (bool)testTrackpadGesturesAreSentToFramework;
- (bool)testViewWillAppearCalledMultipleTimes;

+ (void)respondFalseForSendEvent:(const FlutterKeyEvent&)event
callback:(nullable FlutterKeyEventCallback)callback
Expand Down Expand Up @@ -134,6 +135,10 @@ + (void)respondFalseForSendEvent:(const FlutterKeyEvent&)event
ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testTrackpadGesturesAreSentToFramework]);
}

TEST(FlutterViewControllerTest, testViewWillAppearCalledMultipleTimes) {
ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testViewWillAppearCalledMultipleTimes]);
}

} // namespace flutter::testing

@implementation FlutterViewControllerTestObjC
Expand Down Expand Up @@ -518,4 +523,14 @@ - (bool)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

0 comments on commit 5fb4a53

Please sign in to comment.