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

Scroll to the bottom of timeline automatically #5484

Merged
merged 1 commit into from
Feb 2, 2022
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
15 changes: 13 additions & 2 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ @interface RoomViewController () <UISearchBarDelegate, UIGestureRecognizerDelega
@property (nonatomic, readwrite) RoomDisplayConfiguration *displayConfiguration;
@property (nonatomic) AnalyticsScreenTimer *screenTimer;

// When layout of the screen changes (e.g. height), we no longer know whether
// to autoscroll to the bottom again or not. Instead we need to capture the
// scroll state just before the layout change, and restore it after the layout.
@property (nonatomic) BOOL shouldScrollToBottomAfterLayout;

@end

@implementation RoomViewController
Expand Down Expand Up @@ -650,6 +655,11 @@ - (void)viewDidDisappear:(BOOL)animated
[self.screenTimer stop];
}

- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
self.shouldScrollToBottomAfterLayout = self.isBubblesTableScrollViewAtTheBottom;
}

- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
Expand Down Expand Up @@ -715,9 +725,10 @@ - (void)viewDidLayoutSubviews
self.edgesForExtendedLayout = UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight;
}

// stay at the bottom if already was
if (self.isBubblesTableScrollViewAtTheBottom)
// re-scroll to the bottom, if at bottom before the most recent layout
if (self.shouldScrollToBottomAfterLayout)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to make shouldScrollToBottomAfterLayout false again after we scrolled to bottom?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. In practice it would not cause issues without (will/didLayout go in pair), but it will make it more explicit to reset.

{
self.shouldScrollToBottomAfterLayout = NO;
[self scrollBubblesTableViewToBottomAnimated:NO];
}

Expand Down
1 change: 1 addition & 0 deletions changelog.d/4524.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Timeline: automatically scroll timeline to the bottom when opening a room or rotating device.