Skip to content

Commit

Permalink
Merge pull request #5913 from vector-im/andy/5906_typing_perf
Browse files Browse the repository at this point in the history
Fix typing performance by avoiding expensive UI operations
  • Loading branch information
Anderas authored Mar 24, 2022
2 parents 0f89eb0 + 7145a16 commit a0b7029
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Riot/Modules/Room/MXKRoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,10 @@ - (void)setPaginationLimit:(NSUInteger)paginationLimit

- (void)setRoomTitleViewClass:(Class)roomTitleViewClass
{
if ([self.titleView.class isEqual:roomTitleViewClass]) {
return;
}

// Sanity check: accept only MXKRoomTitleView classes or sub-classes
NSParameterAssert([roomTitleViewClass isSubclassOfClass:MXKRoomTitleView.class]);

Expand Down
17 changes: 13 additions & 4 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ @interface RoomViewController () <UISearchBarDelegate, UIGestureRecognizerDelega
// A flag indicating whether a room has been left
BOOL isRoomLeft;

// The last known frame of the view used to detect whether size-related layout change is needed
CGRect lastViewBounds;

// Tell whether the room has a Jitsi call or not.
BOOL hasJitsiCall;

Expand Down Expand Up @@ -225,7 +228,7 @@ @interface RoomViewController () <UISearchBarDelegate, UIGestureRecognizerDelega
// 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;
@property (nonatomic) BOOL wasScrollAtBottomBeforeLayout;

/// Handles all banners that should be displayed at the top of the timeline but that should not scroll with the timeline
@property (weak, nonatomic, nullable) IBOutlet UIStackView *topBannersStackView;
Expand Down Expand Up @@ -694,12 +697,14 @@ - (void)viewDidDisappear:(BOOL)animated

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

- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
BOOL didViewChangeBounds = !CGRectEqualToRect(lastViewBounds, self.view.bounds);
lastViewBounds = self.view.bounds;

UIEdgeInsets contentInset = self.bubblesTableView.contentInset;
contentInset.bottom = self.view.safeAreaInsets.bottom;
Expand Down Expand Up @@ -763,9 +768,9 @@ - (void)viewDidLayoutSubviews
}

// re-scroll to the bottom, if at bottom before the most recent layout
if (self.shouldScrollToBottomAfterLayout)
if (self.wasScrollAtBottomBeforeLayout && didViewChangeBounds)
{
self.shouldScrollToBottomAfterLayout = NO;
self.wasScrollAtBottomBeforeLayout = NO;
[self scrollBubblesTableViewToBottomAnimated:NO];
}

Expand Down Expand Up @@ -1378,6 +1383,10 @@ - (void)setupRoomDataSourceToResolveEvent: (void (^)(MXKRoomDataSource *roomData

- (void)setRoomTitleViewClass:(Class)roomTitleViewClass
{
if ([self.titleView.class isEqual:roomTitleViewClass]) {
return;
}

// Sanity check: accept only MXKRoomTitleView classes or sub-classes
NSParameterAssert([roomTitleViewClass isSubclassOfClass:MXKRoomTitleView.class]);

Expand Down
1 change: 1 addition & 0 deletions changelog.d/5906.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Room: Fix typing performance by avoiding expensive UI operations

0 comments on commit a0b7029

Please sign in to comment.