Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[macos] [NSViewController viewWillAppear] can be called multiple times #34072

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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