Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust keyboard avoiding behavior #943

Merged
merged 2 commits into from
May 24, 2018
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
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