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

fix:move input view based on delta to handle all embedding cases #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions SOMessaging/SOMessageInputView.m
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ - (void)adjustTextViewSize
if (frm.size.height < self.textMaxHeight) {
if (frm.size.height < self.textInitialHeight) {
frm.size.height = self.textInitialHeight;
frm.origin.y = self.superview.bounds.size.height - frm.size.height - keyboardFrame.size.height;
// adjust to global coordinates to compensate for the chat view being contained in a tab bar
// and navigation controller
CGRect globalFrame = [self.superview convertRect:frm toView:nil];
delta = (self.window.bounds.size.height - frm.size.height - keyboardFrame.size.height) - globalFrame.origin.y;
frm.origin.y += delta;
}

[UIView animateWithDuration:0.3 animations:^{
Expand Down Expand Up @@ -313,7 +317,10 @@ - (void)handleKeyboardWillShowNote:(NSNotification *)notification

CGRect frame = self.frame;
// calculate the absolute ending point (based on the window rather than superview, which could be contained in a tab bar or tool bar)
frame.origin.y = windowRect.size.height - frame.size.height - keyboardRect.size.height;
// adjust the y based on the change needed to handle any embedding
CGRect globalFrame = [self.superview convertRect:self.frame toView:nil];
CGFloat delta = (windowRect.size.height - frame.size.height - keyboardRect.size.height) - globalFrame.origin.y;
frame.origin.y += delta;
initialInputViewPosYWhenKeyboardIsShown = frame.origin.y;

[self adjustTableViewWithCurve:YES scrollsToBottom:YES];
Expand Down