-
Notifications
You must be signed in to change notification settings - Fork 6k
[iOS] Fix:Keyboard inset is not correct when presenting a native ViewController on FlutterViewController #29862
Conversation
…ewController on FlutterViewController
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
| } | ||
| if (finished) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this looks like a good change to me. This will be tricky to write a test for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will definitely be tricky to test. I don't love the partial mocks we use for this now since we're not really testing the behavior, but that the code is being executed in the right order
engine/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm
Lines 187 to 190 in 2962099
| id viewControllerMock = OCMPartialMock(viewController); | |
| [viewControllerMock viewDidDisappear:YES]; | |
| OCMVerify([viewControllerMock ensureViewportMetricsIsCorrect]); | |
| OCMVerify([viewControllerMock invalidateDisplayLink]); |
This doesn't really test that the change is fixed, but you could add an expectation/verification that the engine -updateViewportMetrics: is called after startKeyBoardAnimation.
| OCMVerify([viewControllerMock startKeyBoardAnimation:0.25]); |
| OCMVerify([mockEngine updateViewportMetrics:viewportMetrics]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test passed on this diff and fails on main:
}];
+
+ 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];There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took the liberty of pushing this test to your fork since this bug fix is blocking an internal release. Hope you don't mind. 🙂
gaaclarke
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo @jmagman's approval for a testing exception. I can't think of a good way to test. It would probably have to be a golden image test that we don't have a test harness for.
jmagman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM, I think we can add a verification that the viewPort metrics are updated after startKeyBoardAnimation.
| // Set end value. | ||
| [self keyboardAnimationView].frame = CGRectMake(0, self.targetViewInsetBottom, 0, 0); | ||
| } | ||
| completion:^(BOOL finished) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finished may be false here because the keyboardAnimationView with the animation was removed from the superView before the animation was completed? Not sure though.
| // 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // 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. | |
| // Indicates the displayLink captured by this block is the original one, which also | |
| // indicates the animation has not been interrupted. Moreover, indicates | |
| // the animation is over and there is no more to execute. |
| } | ||
| if (finished) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will definitely be tricky to test. I don't love the partial mocks we use for this now since we're not really testing the behavior, but that the code is being executed in the right order
engine/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm
Lines 187 to 190 in 2962099
| id viewControllerMock = OCMPartialMock(viewController); | |
| [viewControllerMock viewDidDisappear:YES]; | |
| OCMVerify([viewControllerMock ensureViewportMetricsIsCorrect]); | |
| OCMVerify([viewControllerMock invalidateDisplayLink]); |
This doesn't really test that the change is fixed, but you could add an expectation/verification that the engine -updateViewportMetrics: is called after startKeyBoardAnimation.
| OCMVerify([viewControllerMock startKeyBoardAnimation:0.25]); |
| OCMVerify([mockEngine updateViewportMetrics:viewportMetrics]); |
| @"UIKeyboardIsLocalUserInfoKey" : [NSNumber numberWithBool:isLocal] | ||
| }]; | ||
|
|
||
| XCTestExpectation* expectation = [self expectationWithDescription:@"update viewport"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaaclarke would you mind reviewing this test change? I just added it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
@luckysmg Thanks for fixing this so quickly. I'm going to merge this, if you have any code changes to the test I wrote please let me know and we can discuss in a follow-up commit. Merging. |
…ative ViewController on FlutterViewController (flutter/engine#29862)
…ative ViewController on FlutterViewController (flutter/engine#29862)
…ewController on FlutterViewController (flutter#29862)
…ewController on FlutterViewController (flutter#29862)
…ewController on FlutterViewController (#29862) (#30162) Co-authored-by: WenJingRui <[email protected]>
Before:
before.mov
After:
After.mov
List which issues are fixed by this PR. You must list at least one issue.
flutter/flutter#93944
Pre-launch Checklist
writing and running engine tests.
///).If you need help, consider asking for advice on the #hackers-new channel on [Discord].