Skip to content

Commit 75476d2

Browse files
luckysmgxster
authored andcommitted
[iOS] Fix:Keyboard inset is not correct when presenting and native ViewController on FlutterViewController (flutter#29862)
1 parent 202caa0 commit 75476d2

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

shell/platform/darwin/ios/framework/Source/FlutterViewController.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,9 +1193,10 @@ - (void)startKeyBoardAnimation:(NSTimeInterval)duration {
11931193
}
11941194
completion:^(BOOL finished) {
11951195
if (self.displayLink == currentDisplayLink) {
1196+
// Indicates the displaylink captured by this block is the original one,which also
1197+
// indicates the animation has not been interrupted from its beginning. Moreover,indicates
1198+
// the animation is over and there is no more animation about to exectute.
11961199
[self invalidateDisplayLink];
1197-
}
1198-
if (finished) {
11991200
[self removeKeyboardAnimationView];
12001201
[self ensureViewportMetricsIsCorrect];
12011202
}

shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,17 @@ - (void)testkeyboardWillChangeFrameWillStartKeyboardAnimation {
173173
@"UIKeyboardAnimationDurationUserInfoKey" : [NSNumber numberWithDouble:0.25],
174174
@"UIKeyboardIsLocalUserInfoKey" : [NSNumber numberWithBool:isLocal]
175175
}];
176+
177+
XCTestExpectation* expectation = [self expectationWithDescription:@"update viewport"];
178+
OCMStub([mockEngine updateViewportMetrics:flutter::ViewportMetrics()])
179+
.ignoringNonObjectArgs()
180+
.andDo(^(NSInvocation* invocation) {
181+
[expectation fulfill];
182+
});
176183
id viewControllerMock = OCMPartialMock(viewController);
177184
[viewControllerMock keyboardWillChangeFrame:notification];
178185
OCMVerify([viewControllerMock startKeyBoardAnimation:0.25]);
186+
[self waitForExpectationsWithTimeout:5.0 handler:nil];
179187
}
180188

181189
- (void)testEnsureViewportMetricsWillInvokeAndDisplayLinkWillInvalidateInViewDidDisappear {

0 commit comments

Comments
 (0)