Reuse section headers

This commit is contained in:
ismailgulek
2022-02-10 03:19:00 +03:00
parent 93460f01a9
commit 8fb3a34c7b
10 changed files with 40 additions and 28 deletions

View File

@@ -198,7 +198,7 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
[self.recentsListService updateSpace:currentSpace];
}
- (UIView *)viewForStickyHeaderInSection:(NSInteger)section withFrame:(CGRect)frame
- (UIView *)viewForStickyHeaderInSection:(NSInteger)section withFrame:(CGRect)frame inTableView:(UITableView*)tableView
{
UIView *stickyHeader;
@@ -209,7 +209,7 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
shrinkedSectionsBitMask = RECENTSDATASOURCE_SECTION_DIRECTORY;
}
stickyHeader = [self viewForHeaderInSection:section withFrame:frame];
stickyHeader = [self viewForHeaderInSection:section withFrame:frame inTableView:tableView];
shrinkedSectionsBitMask = savedShrinkedSectionsBitMask;
@@ -752,7 +752,7 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
return missedNotifAndUnreadBadgeBgView;
}
- (UIView *)viewForHeaderInSection:(NSInteger)section withFrame:(CGRect)frame
- (UIView *)viewForHeaderInSection:(NSInteger)section withFrame:(CGRect)frame inTableView:(UITableView*)tableView
{
// No header view in key backup banner section
if (section == self.secureBackupBannerSection || section == self.crossSigningBannerSection)
@@ -760,8 +760,14 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
return nil;
}
SectionHeaderView *sectionHeader = [[SectionHeaderView alloc] initWithFrame:frame];
sectionHeader.backgroundColor = ThemeService.shared.theme.headerBackgroundColor;
SectionHeaderView *sectionHeader = [tableView dequeueReusableHeaderFooterViewWithIdentifier:SectionHeaderView.defaultReuseIdentifier];
if (sectionHeader == nil)
{
sectionHeader = [[SectionHeaderView alloc] initWithReuseIdentifier:SectionHeaderView.defaultReuseIdentifier];
}
sectionHeader.backgroundView = [UIView new];
sectionHeader.frame = frame;
sectionHeader.backgroundView.backgroundColor = ThemeService.shared.theme.headerBackgroundColor;
sectionHeader.topViewHeight = RECENTSDATASOURCE_DEFAULT_SECTION_HEADER_HEIGHT;
NSInteger sectionBitwise = 0;
@@ -808,7 +814,6 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
shrinkButton.backgroundColor = [UIColor clearColor];
[shrinkButton addTarget:self action:@selector(onButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
shrinkButton.tag = sectionBitwise;
[sectionHeader addSubview:shrinkButton];
sectionHeader.topSpanningView = shrinkButton;
sectionHeader.userInteractionEnabled = YES;
@@ -825,7 +830,6 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
UIImageView *chevronView = [[UIImageView alloc] initWithImage:chevron];
chevronView.tintColor = ThemeService.shared.theme.textSecondaryColor;
chevronView.contentMode = UIViewContentModeCenter;
[sectionHeader addSubview:chevronView];
sectionHeader.accessoryView = chevronView;
}
else if (_recentsDataSourceMode == RecentsDataSourceModeHome)
@@ -835,7 +839,6 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
if (badgeView)
{
[sectionHeader addSubview:badgeView];
sectionHeader.accessoryView = badgeView;
}
}
@@ -845,7 +848,6 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
UILabel *headerLabel = [[UILabel alloc] initWithFrame:frame];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.attributedText = [self attributedStringForHeaderTitleInSection:section];
[sectionHeader addSubview:headerLabel];
sectionHeader.headerLabel = headerLabel;
return sectionHeader;