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
@@ -791,19 +791,24 @@
return sectionTitle;
}
- (UIView *)viewForHeaderInSection:(NSInteger)section withFrame:(CGRect)frame
- (UIView *)viewForHeaderInSection:(NSInteger)section withFrame:(CGRect)frame inTableView:(UITableView *)tableView
{
NSInteger sectionBitwise = 0;
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.frame = frame;
sectionHeader.backgroundView = [UIView new];
sectionHeader.backgroundView.backgroundColor = ThemeService.shared.theme.headerBackgroundColor;
sectionHeader.topViewHeight = CONTACTSDATASOURCE_DEFAULT_SECTION_HEADER_HEIGHT;
frame.size.height = CONTACTSDATASOURCE_DEFAULT_SECTION_HEADER_HEIGHT - 10;
UILabel *headerLabel = [[UILabel alloc] initWithFrame:frame];
headerLabel.attributedText = [self attributedStringForHeaderTitleInSection:section];
headerLabel.backgroundColor = [UIColor clearColor];
[sectionHeader addSubview:headerLabel];
sectionHeader.headerLabel = headerLabel;
if (_areSectionsShrinkable)
@@ -832,7 +837,6 @@
shrinkButton.backgroundColor = [UIColor clearColor];
[shrinkButton addTarget:self action:@selector(onButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
shrinkButton.tag = sectionBitwise;
[sectionHeader addSubview:shrinkButton];
sectionHeader.topSpanningView = shrinkButton;
sectionHeader.userInteractionEnabled = YES;
@@ -849,7 +853,6 @@
UIImageView *chevronView = [[UIImageView alloc] initWithImage:chevron];
chevronView.tintColor = ThemeService.shared.theme.textSecondaryColor;
chevronView.contentMode = UIViewContentModeCenter;
[sectionHeader addSubview:chevronView];
sectionHeader.accessoryView = chevronView;
}
@@ -893,20 +896,19 @@
localContactsCheckbox.tintColor = ThemeService.shared.theme.tintColor;
// Add the check box container
[sectionHeader addSubview:localContactsCheckboxContainer];
sectionHeader.bottomView = localContactsCheckboxContainer;
}
return sectionHeader;
}
- (UIView *)viewForStickyHeaderInSection:(NSInteger)section withFrame:(CGRect)frame
- (UIView *)viewForStickyHeaderInSection:(NSInteger)section withFrame:(CGRect)frame inTableView:(UITableView *)tableView
{
// Return the section header used when the section is shrinked
NSInteger savedShrinkedSectionsBitMask = shrinkedSectionsBitMask;
shrinkedSectionsBitMask = CONTACTSDATASOURCE_LOCALCONTACTS_BITWISE | CONTACTSDATASOURCE_USERDIRECTORY_BITWISE;
UIView *stickyHeader = [self viewForHeaderInSection:section withFrame:frame];
UIView *stickyHeader = [self viewForHeaderInSection:section withFrame:frame inTableView:tableView];
shrinkedSectionsBitMask = savedShrinkedSectionsBitMask;