From 26af31dd215de6f053c501fd990634249fc25008 Mon Sep 17 00:00:00 2001 From: WenJingRui <2539699336@qq.com> Date: Tue, 23 Nov 2021 07:27:56 +0800 Subject: [PATCH] [iOS] Fix:Keyboard inset is not correct when presenting and native ViewController on FlutterViewController (#29862) --- .../darwin/ios/framework/Source/FlutterViewController.mm | 5 +++-- .../ios/framework/Source/FlutterViewControllerTest.mm | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index a89ae9cd12cc2..ff70c4748a2bb 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -1200,9 +1200,10 @@ - (void)startKeyBoardAnimation:(NSTimeInterval)duration { } completion:^(BOOL finished) { if (self.displayLink == currentDisplayLink) { + // Indicates the displaylink captured by this block is the original one,which also + // indicates the animation has not been interrupted from its beginning. Moreover,indicates + // the animation is over and there is no more animation about to exectute. [self invalidateDisplayLink]; - } - if (finished) { [self removeKeyboardAnimationView]; [self ensureViewportMetricsIsCorrect]; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index 2c462e479c56d..0bb8346572891 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -173,9 +173,17 @@ - (void)testkeyboardWillChangeFrameWillStartKeyboardAnimation { @"UIKeyboardAnimationDurationUserInfoKey" : [NSNumber numberWithDouble:0.25], @"UIKeyboardIsLocalUserInfoKey" : [NSNumber numberWithBool:isLocal] }]; + + XCTestExpectation* expectation = [self expectationWithDescription:@"update viewport"]; + OCMStub([mockEngine updateViewportMetrics:flutter::ViewportMetrics()]) + .ignoringNonObjectArgs() + .andDo(^(NSInvocation* invocation) { + [expectation fulfill]; + }); id viewControllerMock = OCMPartialMock(viewController); [viewControllerMock keyboardWillChangeFrame:notification]; OCMVerify([viewControllerMock startKeyBoardAnimation:0.25]); + [self waitForExpectationsWithTimeout:5.0 handler:nil]; } - (void)testEnsureViewportMetricsWillInvokeAndDisplayLinkWillInvalidateInViewDidDisappear {