@@ -25,11 +25,17 @@ final class SettingsDataSource: UITableViewDiffableDataSource<SettingsDataSource
25
25
}
26
26
}
27
27
28
- private enum HeaderFooterReuseIdentifier : String , CaseIterable {
28
+ private enum HeaderFooterReuseIdentifier : String , CaseIterable , HeaderFooterIdentifierProtocol {
29
+ case primary
29
30
case spacer
30
31
31
- var reusableViewClass : AnyClass {
32
- EmptyTableViewHeaderFooterView . self
32
+ var headerFooterClass : AnyClass {
33
+ switch self {
34
+ case . primary:
35
+ UITableViewHeaderFooterView . self
36
+ case . spacer:
37
+ EmptyTableViewHeaderFooterView . self
38
+ }
33
39
}
34
40
}
35
41
@@ -38,6 +44,20 @@ final class SettingsDataSource: UITableViewDiffableDataSource<SettingsDataSource
38
44
case main
39
45
case version
40
46
case problemReport
47
+
48
+ var sectionFooter : String ? {
49
+ switch self {
50
+ case . daita:
51
+ NSLocalizedString (
52
+ " SETTINGS_DAITA_SECTION_FOOTER " ,
53
+ tableName: " Settings " ,
54
+ value: " Makes it possible to use DAITA with any server and is automatically enabled. " ,
55
+ comment: " "
56
+ )
57
+ default :
58
+ nil
59
+ }
60
+ }
41
61
}
42
62
43
63
enum Item : String {
@@ -130,16 +150,43 @@ final class SettingsDataSource: UITableViewDiffableDataSource<SettingsDataSource
130
150
)
131
151
}
132
152
133
- func tableView( _ tableView: UITableView , viewForFooterInSection section: Int ) -> UIView ? {
134
- nil
153
+ func tableView( _ tableView: UITableView , heightForHeaderInSection section: Int ) -> CGFloat {
154
+ let sectionIdentifier = snapshot ( ) . sectionIdentifiers [ section]
155
+
156
+ return switch sectionIdentifier {
157
+ case . main:
158
+ 0
159
+ case . daita, . version, . problemReport:
160
+ UITableView . automaticDimension
161
+ }
135
162
}
136
163
137
- func tableView( _ tableView: UITableView , heightForHeaderInSection section: Int ) -> CGFloat {
138
- return UIMetrics . TableView. sectionSpacing
164
+ func tableView( _ tableView: UITableView , viewForFooterInSection section: Int ) -> UIView ? {
165
+ let sectionIdentifier = snapshot ( ) . sectionIdentifiers [ section]
166
+ guard let sectionFooterText = sectionIdentifier. sectionFooter else { return nil }
167
+
168
+ guard let headerView = tableView
169
+ . dequeueReusableView ( withIdentifier: HeaderFooterReuseIdentifier . primary)
170
+ else { return nil }
171
+
172
+ var contentConfiguration = UIListContentConfiguration . mullvadGroupedFooter ( tableStyle: . plain)
173
+ contentConfiguration. text = sectionFooterText
174
+
175
+ headerView. contentConfiguration = contentConfiguration
176
+ // headerView.directionalLayoutMargins = UIMetrics.SettingsCell.apiAccessInsetLayoutMargins
177
+
178
+ return headerView
139
179
}
140
180
141
181
func tableView( _ tableView: UITableView , heightForFooterInSection section: Int ) -> CGFloat {
142
- 0
182
+ let sectionIdentifier = snapshot ( ) . sectionIdentifiers [ section]
183
+
184
+ return switch sectionIdentifier {
185
+ case . daita:
186
+ UITableView . automaticDimension
187
+ case . main, . version, . problemReport:
188
+ 0
189
+ }
143
190
}
144
191
145
192
// MARK: - Private
@@ -154,7 +201,7 @@ final class SettingsDataSource: UITableViewDiffableDataSource<SettingsDataSource
154
201
155
202
HeaderFooterReuseIdentifier . allCases. forEach { reuseIdentifier in
156
203
tableView? . register (
157
- reuseIdentifier. reusableViewClass ,
204
+ reuseIdentifier. headerFooterClass ,
158
205
forHeaderFooterViewReuseIdentifier: reuseIdentifier. rawValue
159
206
)
160
207
}
0 commit comments