From b4058bb0683ddee853948e40786e7bc958a1701c 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 (flutter/engine#29862) --- .../darwin/ios/framework/Source/FlutterViewController.mm | 5 +++-- .../ios/framework/Source/FlutterViewControllerTest.mm | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 4f7125f8248..7f5ebd1e819 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -1200,9 +1200,10 @@ static flutter::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch) } 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/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index 2c462e479c5..0bb83465728 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -173,9 +173,17 @@ typedef enum UIAccessibilityContrast : NSInteger { @"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 {