From f72695af6bd5027dbc70fb7f628977fb1e30843c Mon Sep 17 00:00:00 2001 From: luckysmg <2539699336@qq.com> Date: Sat, 20 Nov 2021 14:26:25 +0800 Subject: [PATCH 1/2] [iOS] Fix keyboard inset is not correct when presenting and native ViewController on FlutterViewController --- .../darwin/ios/framework/Source/FlutterViewController.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 4f7125f8248dc..7f5ebd1e81932 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]; } From ac4fa44a9d96f0acc2acd17f01e8cb85875852a6 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Mon, 22 Nov 2021 11:11:20 -0800 Subject: [PATCH 2/2] Add viewport update unit test --- .../ios/framework/Source/FlutterViewControllerTest.mm | 8 ++++++++ 1 file changed, 8 insertions(+) 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 {