Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@luckysmg
Copy link
Contributor

@luckysmg luckysmg commented Nov 20, 2021

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

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on [Discord].

@flutter-dashboard
Copy link

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.

@google-cla google-cla bot added the cla: yes label Nov 20, 2021
@luckysmg luckysmg changed the title [iOS] Fix keyboard inset is not correct when presenting and native ViewController on FlutterViewController [iOS] Fix:Keyboard inset is not correct when presenting and native ViewController on FlutterViewController Nov 20, 2021
Comment on lines -1204 to -1205
}
if (finished) {
Copy link
Member

@gaaclarke gaaclarke Nov 22, 2021

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.

Copy link
Member

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

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]);

Copy link
Member

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];

Copy link
Member

@jmagman jmagman Nov 22, 2021

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. 🙂

ac4fa44

Copy link
Member

@gaaclarke gaaclarke left a 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.

Copy link
Member

@jmagman jmagman left a 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) {
Copy link
Member

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.

Comment on lines +1203 to +1205
// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.

Comment on lines -1204 to -1205
}
if (finished) {
Copy link
Member

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

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"];
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jmagman
Copy link
Member

jmagman commented Nov 22, 2021

@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.
Engine tree is actually green, see flutter/flutter#93872.

Merging.

@jmagman jmagman merged commit ec4f72b into flutter:main Nov 22, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 23, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 23, 2021
@luckysmg luckysmg changed the title [iOS] Fix:Keyboard inset is not correct when presenting and native ViewController on FlutterViewController [iOS] Fix:Keyboard inset is not correct when presenting a native ViewController on FlutterViewController Nov 23, 2021
xster pushed a commit to xster/engine that referenced this pull request Nov 23, 2021
xster added a commit that referenced this pull request Nov 23, 2021
@luckysmg luckysmg deleted the keyboard_anim_fix branch November 25, 2021 08:14
@luckysmg luckysmg restored the keyboard_anim_fix branch November 25, 2021 08:14
@luckysmg luckysmg deleted the keyboard_anim_fix branch November 25, 2021 08:14
xster pushed a commit to xster/engine that referenced this pull request Dec 6, 2021
xster added a commit that referenced this pull request Dec 7, 2021
…ewController on FlutterViewController (#29862) (#30162)

Co-authored-by: WenJingRui <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants