mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fixes UI freezes when multiple Flutter VC shared one engine (#18816)
Co-authored-by: Aaron Clarke <aaclarke@google.com>
This commit is contained in:
parent
b1a08f2abd
commit
0e8f89cd71
@ -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];
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user