Skip to content

Commit

Permalink
Adjust keyboard avoiding behavior (#943)
Browse files Browse the repository at this point in the history
* Adjust keyboard avoiding behavior

Stop adjusting `scrollView.contentOffset` and let the system natively scroll because of the `scrollView.contentInset` change

* Add CHANGELOG entry
  • Loading branch information
joeydong-stripe authored May 24, 2018
1 parent 3d696ab commit 85ebaa3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Adjusts scroll view content offset behavior when focusing on a text field [#943](https://github.com/stripe/stripe-ios/pull/943)

## 13.0.1 2018-05-17
* Fixes an issue in `STPRedirectContext` causing some redirecting sources to fail in livemode due to prematurely dismissing the `SFSafariViewController` during the initial redirects. [#937](https://github.com/stripe/stripe-ios/pull/937)

Expand Down
19 changes: 0 additions & 19 deletions Stripe/UIViewController+Stripe_KeyboardAvoiding.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ - (void)doKeyboardChangeAnimationWithNewFrame:(CGRect)keyboardFrame {
self.lastKeyboardFrame = keyboardFrame;

if (self.managedScrollView) {

UIScrollView *scrollView = self.managedScrollView;
UIView *scrollViewSuperView = self.managedScrollView.superview;
UIView *lastResponder = self.lastResponder;

UIEdgeInsets contentInsets = scrollView.contentInset;
UIEdgeInsets scrollIndicatorInsets = scrollView.scrollIndicatorInsets;
Expand All @@ -96,28 +94,11 @@ - (void)doKeyboardChangeAnimationWithNewFrame:(CGRect)keyboardFrame {
self.currentBottomInsetChange += bottomInsetDelta;
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = scrollIndicatorInsets;

if (!lastResponder || bottomIntersection.size.height <= 0) {
scrollView.contentOffset = CGPointMake(0, -scrollView.contentInset.top);
}
else {
// the keyboard is visible
CGRect responderFrame = [lastResponder convertRect:lastResponder.bounds toView:scrollView];
CGRect keyboardFrameInScrollViewCoords = [scrollView convertRect:keyboardFrame fromView:nil];
CGPoint offset = scrollView.contentOffset;

CGFloat topOfScreenOffset = CGRectGetMinY(responderFrame);
CGFloat topOfKeyboardOffset = CGRectGetMinY(responderFrame) - CGRectGetMinY(keyboardFrameInScrollViewCoords);
offset.y = ((topOfScreenOffset + topOfKeyboardOffset) / 2) - scrollView.contentInset.top;
offset.y = MAX(offset.y, -scrollView.contentInset.top);
scrollView.contentOffset = offset;
}
}

if (self.keyboardFrameBlock) {
self.keyboardFrameBlock(keyboardFrame, self.lastResponder);
}

}

@end
Expand Down

0 comments on commit 85ebaa3

Please sign in to comment.