mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Register unique cells for home screen sections
This commit is contained in:
parent
867af20b40
commit
e29c4515b4
3 changed files with 87 additions and 3 deletions
|
@ -0,0 +1,30 @@
|
||||||
|
//
|
||||||
|
// Copyright 2022 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
@objc enum RecentsDataSourceSectionType: Int {
|
||||||
|
case crossSigningBanner
|
||||||
|
case secureBackupBanner
|
||||||
|
case directory
|
||||||
|
case invites
|
||||||
|
case favorites
|
||||||
|
case people
|
||||||
|
case conversation
|
||||||
|
case lowPriority
|
||||||
|
case serverNotice
|
||||||
|
case suggestedRooms
|
||||||
|
}
|
|
@ -93,8 +93,8 @@
|
||||||
target:self
|
target:self
|
||||||
action:@selector(onPlusButtonPressed)];
|
action:@selector(onPlusButtonPressed)];
|
||||||
|
|
||||||
// Register table view cell used for rooms collection.
|
// Register table view cells used for rooms collection.
|
||||||
[self.recentsTableView registerClass:TableViewCellWithCollectionView.class forCellReuseIdentifier:TableViewCellWithCollectionView.defaultReuseIdentifier];
|
[self registerCellsWithCollectionViews];
|
||||||
|
|
||||||
// Change the table data source. It must be the home view controller itself.
|
// Change the table data source. It must be the home view controller itself.
|
||||||
self.recentsTableView.dataSource = self;
|
self.recentsTableView.dataSource = self;
|
||||||
|
@ -302,6 +302,57 @@
|
||||||
|
|
||||||
#pragma mark - UITableViewDataSource
|
#pragma mark - UITableViewDataSource
|
||||||
|
|
||||||
|
// Table view cells on the home screen contain nested collection views with their own data source and state.
|
||||||
|
// In order to preserve properties such as content offset of each collection view, the parent cells must
|
||||||
|
// be directly associated with each section, so that when getting dequed by the table view, the correct cell
|
||||||
|
// is reused, rather than cells getting randomly swapped around.
|
||||||
|
- (void)registerCellsWithCollectionViews
|
||||||
|
{
|
||||||
|
NSArray<NSNumber *> *sections = @[
|
||||||
|
@(RecentsDataSourceSectionTypeDirectory),
|
||||||
|
@(RecentsDataSourceSectionTypeInvites),
|
||||||
|
@(RecentsDataSourceSectionTypeFavorites),
|
||||||
|
@(RecentsDataSourceSectionTypePeople),
|
||||||
|
@(RecentsDataSourceSectionTypeConversation),
|
||||||
|
@(RecentsDataSourceSectionTypeLowPriority),
|
||||||
|
@(RecentsDataSourceSectionTypeServerNotice),
|
||||||
|
@(RecentsDataSourceSectionTypeSuggestedRooms)
|
||||||
|
];
|
||||||
|
for (NSNumber *section in sections) {
|
||||||
|
NSString *cellIdentifier = [self cellIdentifierForSectionType:section.integerValue];
|
||||||
|
[self.recentsTableView registerClass:TableViewCellWithCollectionView.class forCellReuseIdentifier:cellIdentifier];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)cellIdentifierForSectionType:(RecentsDataSourceSectionType)sectionType
|
||||||
|
{
|
||||||
|
// Create cell identifier unique to each semantic section, e.g. 'favorites' will have different cell
|
||||||
|
// identifier to 'conversations'.
|
||||||
|
return [NSString stringWithFormat:@"%@-%ld", TableViewCellWithCollectionView.defaultReuseIdentifier, sectionType];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (RecentsDataSourceSectionType)sectionTypeAtIndexPath:(NSIndexPath *)indexPath
|
||||||
|
{
|
||||||
|
if (indexPath.section == recentsDataSource.directorySection) {
|
||||||
|
return RecentsDataSourceSectionTypeDirectory;
|
||||||
|
} else if (indexPath.section == recentsDataSource.invitesSection) {
|
||||||
|
return RecentsDataSourceSectionTypeInvites;
|
||||||
|
} else if (indexPath.section == recentsDataSource.favoritesSection) {
|
||||||
|
return RecentsDataSourceSectionTypeFavorites;
|
||||||
|
} else if (indexPath.section == recentsDataSource.peopleSection) {
|
||||||
|
return RecentsDataSourceSectionTypePeople;
|
||||||
|
} else if (indexPath.section == recentsDataSource.conversationSection) {
|
||||||
|
return RecentsDataSourceSectionTypeConversation;
|
||||||
|
} else if (indexPath.section == recentsDataSource.lowPrioritySection) {
|
||||||
|
return RecentsDataSourceSectionTypeLowPriority;
|
||||||
|
} else if (indexPath.section == recentsDataSource.serverNoticeSection) {
|
||||||
|
return RecentsDataSourceSectionTypeServerNotice;
|
||||||
|
} else if (indexPath.section == recentsDataSource.suggestedRoomsSection) {
|
||||||
|
return RecentsDataSourceSectionTypeSuggestedRooms;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
||||||
{
|
{
|
||||||
// Return the actual number of sections prepared in recents dataSource.
|
// Return the actual number of sections prepared in recents dataSource.
|
||||||
|
@ -335,7 +386,9 @@
|
||||||
return [recentsDataSource tableView:tableView cellForRowAtIndexPath:indexPath];
|
return [recentsDataSource tableView:tableView cellForRowAtIndexPath:indexPath];
|
||||||
}
|
}
|
||||||
|
|
||||||
TableViewCellWithCollectionView *tableViewCell = [tableView dequeueReusableCellWithIdentifier:TableViewCellWithCollectionView.defaultReuseIdentifier forIndexPath:indexPath];
|
RecentsDataSourceSectionType sectionType = [self sectionTypeAtIndexPath:indexPath];
|
||||||
|
NSString *cellIdentifier = [self cellIdentifierForSectionType:sectionType];
|
||||||
|
TableViewCellWithCollectionView *tableViewCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
|
||||||
tableViewCell.collectionView.tag = indexPath.section;
|
tableViewCell.collectionView.tag = indexPath.section;
|
||||||
[tableViewCell.collectionView registerClass:RoomCollectionViewCell.class forCellWithReuseIdentifier:RoomCollectionViewCell.defaultReuseIdentifier];
|
[tableViewCell.collectionView registerClass:RoomCollectionViewCell.class forCellWithReuseIdentifier:RoomCollectionViewCell.defaultReuseIdentifier];
|
||||||
tableViewCell.collectionView.delegate = self;
|
tableViewCell.collectionView.delegate = self;
|
||||||
|
|
1
changelog.d/5958.bugfix
Normal file
1
changelog.d/5958.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Rooms: Register unique cells for home screen sections
|
Loading…
Reference in a new issue