Skip to content

Commit

Permalink
fix ios 11 safearea support
Browse files Browse the repository at this point in the history
  • Loading branch information
fans3210 committed Sep 25, 2017
1 parent 5640112 commit 4e3d83d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
50 changes: 26 additions & 24 deletions Examples/Messenger-Shared/MessageViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -446,31 +446,33 @@ - (void) didLongPressLeftButton:(UIGestureRecognizer *)sender

- (void)didPressRightButton:(id)sender
{
// Notifies the view controller when the right button's action has been triggered, manually or by using the keyboard return key.
//comment due to the lib code modified. Right action handled differently

// This little trick validates any pending auto-correction or auto-spelling just after hitting the 'Send' button
[self.textView refreshFirstResponder];

Message *message = [Message new];
message.username = [LoremIpsum name];
message.text = [self.textView.text copy];

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
UITableViewRowAnimation rowAnimation = self.inverted ? UITableViewRowAnimationBottom : UITableViewRowAnimationTop;
UITableViewScrollPosition scrollPosition = self.inverted ? UITableViewScrollPositionBottom : UITableViewScrollPositionTop;

[self.tableView beginUpdates];
[self.messages insertObject:message atIndex:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:rowAnimation];
[self.tableView endUpdates];

[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:scrollPosition animated:YES];

// Fixes the cell from blinking (because of the transform, when using translucent cells)
// See https://github.com/slackhq/SlackTextViewController/issues/94#issuecomment-69929927
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

[super didPressRightButton:sender];
// // Notifies the view controller when the right button's action has been triggered, manually or by using the keyboard return key.
//
// // This little trick validates any pending auto-correction or auto-spelling just after hitting the 'Send' button
// [self.textView refreshFirstResponder];
//
// Message *message = [Message new];
// message.username = [LoremIpsum name];
// message.text = [self.textView.text copy];
//
// NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
// UITableViewRowAnimation rowAnimation = self.inverted ? UITableViewRowAnimationBottom : UITableViewRowAnimationTop;
// UITableViewScrollPosition scrollPosition = self.inverted ? UITableViewScrollPositionBottom : UITableViewScrollPositionTop;
//
// [self.tableView beginUpdates];
// [self.messages insertObject:message atIndex:0];
// [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:rowAnimation];
// [self.tableView endUpdates];
//
// [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:scrollPosition animated:YES];
//
// // Fixes the cell from blinking (because of the transform, when using translucent cells)
// // See https://github.com/slackhq/SlackTextViewController/issues/94#issuecomment-69929927
// [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
//
// [super didPressRightButton:sender];
}

- (void)didPressArrowKey:(UIKeyCommand *)keyCommand
Expand Down
12 changes: 11 additions & 1 deletion Source/SLKTextViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ - (void)viewDidLayoutSubviews
[super viewDidLayoutSubviews];
}

- (void) viewSafeAreaInsetsDidChange
{
[super viewSafeAreaInsetsDidChange];
[self slk_updateViewConstraints];
}


#pragma mark - Getters

Expand Down Expand Up @@ -437,6 +443,10 @@ - (CGFloat)slk_appropriateBottomMargin
if (tabBar && !tabBar.hidden && !self.hidesBottomBarWhenPushed) {
return CGRectGetHeight(tabBar.frame);
}

if(@available(iOS 11.0, *)) {
return self.view.safeAreaInsets.bottom;
}
}

return 0.0;
Expand Down Expand Up @@ -2270,7 +2280,7 @@ - (void)slk_setupViewConstraints
NSDictionary *views = @{@"scrollView": self.scrollViewProxy,
@"autoCompletionView": self.autoCompletionView,
@"typingIndicatorView": self.typingIndicatorProxyView,
@"textInputbar": self.textInputbar,
@"textInputbar": self.textInputbar
};

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollView(0@750)][typingIndicatorView(0)]-0@999-[textInputbar(0)]|" options:0 metrics:nil views:views]];
Expand Down

0 comments on commit 4e3d83d

Please sign in to comment.