Closed joeljfischer closed 3 years ago
@joeljfischer The titleForHeader / viewForHeaderInSection for DiffableDataSource adapters currently doesn't support the custom sectionIndex transformers, sorry about that. I'll try to rework the adapters in an update, but for now you have the following options to work around it:
DiffableDataSource.TableViewAdapter
or DiffableDataSource.CollectionViewAdapter
and override the tableView(_:titleForHeaderInSection:)
or collectionView(_:viewForSupplementaryElementOfKind:at:)
Adding a Field.Virtual
property that implements the logic. You can then use that property as the sectionBy
key. See the Demo app's example:
Modern.ColorsDemo.dataStack.publishList(
From<Modern.ColorsDemo.Palette>()
.sectionBy(\.$colorGroup)
/ /...
)
@Field.Virtual(
"colorGroup",
customGetter: { object, field in
if let colorGroup = field.primitiveValue {
return colorGroup
}
let colorGroup: String
switch object.$hue.value * 359 {
case 0 ..< 20: colorGroup = "Lower Reds"
case 20 ..< 57: colorGroup = "Oranges and Browns"
case 57 ..< 90: colorGroup = "Yellow-Greens"
case 90 ..< 159: colorGroup = "Greens"
case 159 ..< 197: colorGroup = "Blue-Greens"
case 197 ..< 241: colorGroup = "Blues"
case 241 ..< 297: colorGroup = "Violets"
case 297 ..< 331: colorGroup = "Magentas"
default: colorGroup = "Upper Reds"
}
field.primitiveValue = colorGroup
return colorGroup
}
)
var colorGroup: String
Hi, I have a
.sectionBy
clause set up, but it appears that the name transformer isn't working.Here,
$.isStarted
a boolean virtual property, but that all appears to be working correctly. I can breakpoint within the.sectionBy
closure and it's running and returning the correct string, but0
or1
is still appearing as the section header of my list. Do I need to implementtitleForHeader
/viewForHeaderInSection
? It says to do so under theListMonitor
documentation but not the list publisher documentation. If so, what would I access to see my transformed string?