Skip to content

Commit

Permalink
Room context preview dismissed unexpectedly (#5993)
Browse files Browse the repository at this point in the history
- fixed
  • Loading branch information
gileluard authored Apr 6, 2022
1 parent 1e99e19 commit 740d50f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Riot/Modules/Common/Recents/RecentsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,14 @@ - (void)viewDidLayoutSubviews

- (void)refreshRecentsTable
{
if (!self.recentsUpdateEnabled)
{
isRefreshNeeded = NO;
return;
}

isRefreshNeeded = NO;

// Refresh the tabBar icon badges
[[AppDelegate theDelegate].masterTabBarController refreshTabBarBadges];

Expand Down Expand Up @@ -1034,6 +1042,12 @@ - (void)dataSource:(MXKDataSource *)dataSource didRecognizeAction:(NSString *)ac

- (void)dataSource:(MXKDataSource *)dataSource didCellChange:(id)changes
{
if (!self.recentsUpdateEnabled)
{
[super dataSource:dataSource didCellChange:changes];
return;
}

BOOL cellReloaded = NO;
if ([changes isKindOfClass:RecentsSectionUpdate.class])
{
Expand Down Expand Up @@ -2502,6 +2516,7 @@ - (UIContextMenuConfiguration *)tableView:(UITableView *)tableView contextMenuCo
return nil;
}

self.recentsUpdateEnabled = NO;
return [self.contextMenuProvider contextMenuConfigurationWith:cellData from:cell session:self.dataSource.mxSession];
}

Expand All @@ -2511,14 +2526,22 @@ - (void)tableView:(UITableView *)tableView willPerformPreviewActionForMenuWithCo

if (!roomId)
{
self.recentsUpdateEnabled = YES;
return;
}

[animator addCompletion:^{
self.recentsUpdateEnabled = YES;
[self showRoomWithRoomId:roomId inMatrixSession:self.mainSession];
}];
}

- (UITargetedPreview *)tableView:(UITableView *)tableView previewForDismissingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration API_AVAILABLE(ios(13.0))
{
self.recentsUpdateEnabled = YES;
return nil;
}

#pragma mark - RoomContextActionServiceDelegate

- (void)roomContextActionServiceDidJoinRoom:(id<RoomContextActionServiceProtocol>)service
Expand Down
9 changes: 9 additions & 0 deletions Riot/Modules/Home/HomeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ - (UIContextMenuConfiguration *)collectionView:(UICollectionView *)collectionVie
return nil;
}

self.recentsUpdateEnabled = NO;
return [self.contextMenuProvider contextMenuConfigurationWith:cellData from:cell session:self.dataSource.mxSession];
}

Expand All @@ -911,12 +912,20 @@ - (void)collectionView:(UICollectionView *)collectionView willPerformPreviewActi

if (!roomId)
{
self.recentsUpdateEnabled = YES;
return;
}

[animator addCompletion:^{
self.recentsUpdateEnabled = YES;
[self showRoomWithRoomId:roomId inMatrixSession:self.mainSession];
}];
}

- (UITargetedPreview *)collectionView:(UICollectionView *)collectionView previewForDismissingContextMenuWithConfiguration:(UIContextMenuConfiguration *)configuration API_AVAILABLE(ios(13.0))
{
self.recentsUpdateEnabled = YES;
return nil;
}

@end
11 changes: 11 additions & 0 deletions Riot/Modules/MatrixKit/Controllers/MXKRecentListViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ limitations under the License.
The fake top view displayed in case of vertical bounce.
*/
__weak UIView *topview;

/**
`isRefreshNeeded` is set to `YES` if an update of the datasource has been triggered but the UI has not been updated.
It's set to `NO` after a refresh of the UI.
*/
BOOL isRefreshNeeded;
}

@property (weak, nonatomic) IBOutlet UISearchBar *recentsSearchBar;
Expand All @@ -83,6 +89,11 @@ limitations under the License.
*/
@property (nonatomic) BOOL enableBarButtonSearch;

/**
Enabled or disabled the UI update after recents syncs. Default YES.
*/
@property (nonatomic, getter=isRecentsUpdateEnabled) BOOL recentsUpdateEnabled;

#pragma mark - Class methods

/**
Expand Down
23 changes: 23 additions & 0 deletions Riot/Modules/MatrixKit/Controllers/MXKRecentListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ - (void)finalizeInit
{
[super finalizeInit];

_recentsUpdateEnabled = YES;
_enableBarButtonSearch = YES;
}

Expand Down Expand Up @@ -169,6 +170,8 @@ - (void)viewWillAppear:(BOOL)animated

// Observe the server sync
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSyncNotification) name:kMXSessionDidSyncNotification object:nil];

self.recentsUpdateEnabled = YES;
}

- (void)viewWillDisappear:(BOOL)animated
Expand Down Expand Up @@ -319,6 +322,10 @@ - (void)displayList:(MXKRecentsDataSource *)listDataSource

- (void)refreshRecentsTable
{
if (!self.recentsUpdateEnabled) return;

isRefreshNeeded = NO;

// For now, do a simple full reload
[self.recentsTableView reloadData];
}
Expand All @@ -330,6 +337,16 @@ - (void)hideSearchBar:(BOOL)hidden
[self.view setNeedsUpdateConstraints];
}

- (void)setRecentsUpdateEnabled:(BOOL)activeUpdate
{
_recentsUpdateEnabled = activeUpdate;

if (_recentsUpdateEnabled && isRefreshNeeded)
{
[self refreshRecentsTable];
}
}

#pragma mark - Action

- (IBAction)search:(id)sender
Expand Down Expand Up @@ -385,6 +402,12 @@ - (NSString *)cellReuseIdentifierForCellData:(MXKCellData*)cellData

- (void)dataSource:(MXKDataSource *)dataSource didCellChange:(id)changes
{
if (!_recentsUpdateEnabled)
{
isRefreshNeeded = YES;
return;
}

// For now, do a simple full reload
[self refreshRecentsTable];
}
Expand Down
1 change: 1 addition & 0 deletions changelog.d/5992.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RecentsViewController: Room context preview dismissed unexpectedly

0 comments on commit 740d50f

Please sign in to comment.