Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1200,9 +1200,10 @@ - (void)startKeyBoardAnimation:(NSTimeInterval)duration {
}
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.

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

[self invalidateDisplayLink];
}
if (finished) {
Comment on lines -1204 to -1205
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

[self removeKeyboardAnimationView];
[self ensureViewportMetricsIsCorrect];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,17 @@ - (void)testkeyboardWillChangeFrameWillStartKeyboardAnimation {
@"UIKeyboardAnimationDurationUserInfoKey" : [NSNumber numberWithDouble:0.25],
@"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

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 {
Expand Down