Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split cell reuse identifiers to segregate subtitle cells #7585

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ final class SettingsCellFactory: @preconcurrency CellFactoryProtocol, Sendable {
func makeCell(for item: SettingsDataSource.Item, indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell

// Instantiate cell based on the specific item type
if item == .changelog {
cell = SettingsCell(style: .subtitle, reuseIdentifier: item.reuseIdentifier.rawValue)
} else {
cell = tableView.dequeueReusableCell(withIdentifier: item.reuseIdentifier.rawValue, for: indexPath)
}
cell = tableView
.dequeueReusableCell(
withIdentifier: item.reuseIdentifier.rawValue
) ?? SettingsCell(
style: item.reuseIdentifier.cellStyle,
reuseIdentifier: item.reuseIdentifier.rawValue
)

// Configure the cell with the common logic
configureCell(cell, item: item, indexPath: indexPath)
Expand Down
24 changes: 14 additions & 10 deletions ios/MullvadVPN/View controllers/Settings/SettingsDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ import UIKit

final class SettingsDataSource: UITableViewDiffableDataSource<SettingsDataSource.Section, SettingsDataSource.Item>,
UITableViewDelegate {
enum CellReuseIdentifiers: String, CaseIterable {
enum CellReuseIdentifier: String, CaseIterable {
case basic
case changelog

var reusableViewClass: AnyClass {
SettingsCell.self
}

var cellStyle: UITableViewCell.CellStyle {
switch self {
case .basic: .default
case .changelog: .subtitle
}
}
}

private enum HeaderFooterReuseIdentifier: String, CaseIterable, HeaderFooterIdentifierProtocol {
Expand Down Expand Up @@ -68,8 +76,11 @@ final class SettingsDataSource: UITableViewDiffableDataSource<SettingsDataSource
}
}

var reuseIdentifier: CellReuseIdentifiers {
.basic
var reuseIdentifier: CellReuseIdentifier {
switch self {
case .changelog: .changelog
default: .basic
}
}
}

Expand Down Expand Up @@ -132,13 +143,6 @@ final class SettingsDataSource: UITableViewDiffableDataSource<SettingsDataSource
// MARK: - Private

private func registerClasses() {
CellReuseIdentifiers.allCases.forEach { cellIdentifier in
tableView?.register(
cellIdentifier.reusableViewClass,
forCellReuseIdentifier: cellIdentifier.rawValue
)
}

HeaderFooterReuseIdentifier.allCases.forEach { reuseIdentifier in
tableView?.register(
reuseIdentifier.headerFooterClass,
Expand Down
Loading