Fixes UI freezes when multiple Flutter VC shared one engine (#18816)

Co-authored-by: Aaron Clarke <aaclarke@google.com>
This commit is contained in:
Wu Zhong 2020-06-11 01:22:38 +08:00 committed by GitHub
parent b1a08f2abd
commit 0e8f89cd71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 3 deletions

View File

@ -553,9 +553,11 @@ static void sendFakeTouchEvent(FlutterEngine* engine,
- (void)viewDidDisappear:(BOOL)animated {
TRACE_EVENT0("flutter", "viewDidDisappear");
[self surfaceUpdated:NO];
[[_engine.get() lifecycleChannel] sendMessage:@"AppLifecycleState.paused"];
[self flushOngoingTouches];
if ([_engine.get() viewController] == self) {
[self surfaceUpdated:NO];
[[_engine.get() lifecycleChannel] sendMessage:@"AppLifecycleState.paused"];
[self flushOngoingTouches];
}
[super viewDidDisappear:animated];
}

View File

@ -54,11 +54,45 @@ typedef enum UIAccessibilityContrast : NSInteger {
#endif
@interface FlutterViewController (Tests)
- (void)surfaceUpdated:(BOOL)appeared;
- (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences;
@end
@implementation FlutterViewControllerTest
- (void)testViewDidDisappearDoesntPauseEngine {
id engine = OCMClassMock([FlutterEngine class]);
id lifecycleChannel = OCMClassMock([FlutterBasicMessageChannel class]);
OCMStub([engine lifecycleChannel]).andReturn(lifecycleChannel);
FlutterViewController* viewControllerA = [[FlutterViewController alloc] initWithEngine:engine
nibName:nil
bundle:nil];
FlutterViewController* viewControllerB = [[FlutterViewController alloc] initWithEngine:engine
nibName:nil
bundle:nil];
id viewControllerMock = OCMPartialMock(viewControllerA);
OCMStub([viewControllerMock surfaceUpdated:NO]);
OCMStub([engine viewController]).andReturn(viewControllerB);
[viewControllerA viewDidDisappear:NO];
OCMReject([lifecycleChannel sendMessage:@"AppLifecycleState.paused"]);
OCMReject([viewControllerMock surfaceUpdated:[OCMArg any]]);
}
- (void)testViewDidDisappearDoesPauseEngine {
id engine = OCMClassMock([FlutterEngine class]);
id lifecycleChannel = OCMClassMock([FlutterBasicMessageChannel class]);
OCMStub([engine lifecycleChannel]).andReturn(lifecycleChannel);
FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
nibName:nil
bundle:nil];
id viewControllerMock = OCMPartialMock(viewController);
OCMStub([viewControllerMock surfaceUpdated:NO]);
OCMStub([engine viewController]).andReturn(viewController);
[viewController viewDidDisappear:NO];
OCMVerify([lifecycleChannel sendMessage:@"AppLifecycleState.paused"]);
OCMVerify([viewControllerMock surfaceUpdated:NO]);
}
- (void)testBinaryMessenger {
id engine = OCMClassMock([FlutterEngine class]);
FlutterViewController* vc = [[FlutterViewController alloc] initWithEngine:engine