mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 15:52:40 +00:00
Finalize SYIOS-17 by scrolling to the bottom the refreshed table if necessary
This commit is contained in:
parent
391b016029
commit
dd79c2d26c
1 changed files with 28 additions and 16 deletions
|
@ -302,8 +302,6 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
[[MatrixHandler sharedHandler] addObserver:self forKeyPath:@"isResumeDone" options:0 context:nil];
|
||||
// Register a listener to handle messages
|
||||
messagesListener = [self.mxRoom listenToEventsOfTypes:mxHandler.eventsFilterForMessages onEvent:^(MXEvent *event, MXEventDirection direction, MXRoomState *roomState) {
|
||||
BOOL shouldScrollToBottom = NO;
|
||||
|
||||
// Handle first live events
|
||||
if (direction == MXEventDirectionForwards) {
|
||||
// Check user's membership in live room state (Indeed we have to go back on recents when user leaves, or is kicked/banned)
|
||||
|
@ -312,12 +310,6 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
return;
|
||||
}
|
||||
|
||||
// We will scroll to bottom after updating tableView only if the most recent message is entirely visible.
|
||||
CGFloat maxPositionY = self.messagesTableView.contentOffset.y + (self.messagesTableView.frame.size.height - self.messagesTableView.contentInset.bottom);
|
||||
// Be a bit less retrictive, scroll even if the most recent message is partially hidden
|
||||
maxPositionY += 30;
|
||||
shouldScrollToBottom = (maxPositionY >= self.messagesTableView.contentSize.height);
|
||||
|
||||
// Update Table
|
||||
BOOL isHandled = NO;
|
||||
BOOL shouldBeHidden = NO;
|
||||
|
@ -390,7 +382,20 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
|
||||
// Refresh table display except if a back pagination is in progress
|
||||
if (!isBackPaginationInProgress) {
|
||||
// We will scroll to bottom after updating tableView only if the most recent message is entirely visible.
|
||||
CGFloat maxPositionY = self.messagesTableView.contentOffset.y + (self.messagesTableView.frame.size.height - self.messagesTableView.contentInset.bottom);
|
||||
// Be a bit less retrictive, scroll even if the most recent message is partially hidden
|
||||
maxPositionY += 30;
|
||||
BOOL shouldScrollToBottom = (maxPositionY >= self.messagesTableView.contentSize.height);
|
||||
// Refresh tableView
|
||||
[self.messagesTableView reloadData];
|
||||
|
||||
if (shouldScrollToBottom) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self scrollToBottomAnimated:YES];
|
||||
});
|
||||
}
|
||||
|
||||
if (isHandled) {
|
||||
if ([[AppDelegate theDelegate].masterTabBarController.visibleRoomId isEqualToString:self.roomId] == NO) {
|
||||
// Some new events are received for this room while it is not visible, scroll to bottom on viewDidAppear to focus on them
|
||||
|
@ -411,12 +416,6 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
}
|
||||
// Display is refreshed at the end of back pagination (see onComplete block)
|
||||
}
|
||||
|
||||
if (shouldScrollToBottom) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self scrollToBottomAnimated:YES];
|
||||
});
|
||||
}
|
||||
}];
|
||||
|
||||
// Trigger a back pagination by reseting first backState to get room history from live
|
||||
|
@ -1428,8 +1427,7 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
|
||||
if (scrollView == self.messagesTableView) {
|
||||
// paginate ?
|
||||
if (scrollView.contentOffset.y < -64)
|
||||
{
|
||||
if (scrollView.contentOffset.y < -64) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self triggerBackPagination];
|
||||
});
|
||||
|
@ -1776,7 +1774,21 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// We will scroll to bottom after updating tableView only if the most recent message is entirely visible.
|
||||
CGFloat maxPositionY = self.messagesTableView.contentOffset.y + (self.messagesTableView.frame.size.height - self.messagesTableView.contentInset.bottom);
|
||||
// Be a bit less retrictive, scroll even if the most recent message is partially hidden
|
||||
maxPositionY += 30;
|
||||
BOOL shouldScrollToBottom = (maxPositionY >= self.messagesTableView.contentSize.height);
|
||||
|
||||
// Refresh tableView
|
||||
[self.messagesTableView reloadData];
|
||||
|
||||
if (shouldScrollToBottom) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self scrollToBottomAnimated:YES];
|
||||
});
|
||||
}
|
||||
} failure:^(NSError *error) {
|
||||
[self handleError:error forLocalEvent:localEvent];
|
||||
}];
|
||||
|
|
Loading…
Reference in a new issue