I'm skeptical because some of these variables do not semantically represent a "state".
If I look at the sample WWDC sample code for custom cells configurations, all the variables used in updateConfiguration(using:) method are stored in the custom key value store of UICellConfigurationState. In fact, in this sample code, it's the whole model that it's stored in a state custom key.
It seems weird because the base properties of UICellConfigurationState are real "state" properties: like selected, highlighted.
In the same way, for the cells provided by UIKit, non state properties are stored in the configuration. For example, UIListContentConfiguration.imageProperties.tintColor, UIListContentConfiguration.imageToTextPadding.
For a custom cell, we could imagine to subclass UIListContentConfiguration but it's not possible because it's a struct.
Imagine you have a custom UICollectionViewListCell with a custom checkmark view.
Associated to this checkmark, you have:
checkmarkTintColor: an “appearance” property to set the tint color of the checkmark.
checkmarkChecked: a ”state” property associated to the checkmark state.
Code Block var checkmarkChecked: Bool = false { didSet { guard oldValue != checked else { return } setNeedsUpdateConfiguration() } } var checkmarkTintColor: UIColor? = nil { didSet { guard oldValue != checkmarkTintColor else { return } setNeedsUpdateConfiguration() } } var configuration: UIListContentConfiguration? { didSet { guard oldValue != configuration else { return } setNeedsUpdateConfiguration() } } override var configurationState: UICellConfigurationState { var state = super.configurationState state.checkmarkChecked = checkmarkChecked state.checkmarkTintColor = checkmarkTintColor return state } override func updateConfiguration(using state: UICellConfigurationState) { ... checkmarkImageView.image = state.checked ? UIImage(systemName: "checkmark.circle.fill") : UIImage(systemName: "circle") checkmarkImageView.tintColor = checkmarkTintColor }
There are a couple different ways to interpret what custom cell means:From what I understand, if I make a custom cell, I cannot have a custom configuration. Let's take an example:
If I make a custom UICollectionViewListCell cell for a sidebar, then use UIListContentConfiguration.sidebarCell() in order to have all its rendering for free (text label, image view, ...). I would insert the UIListContentView associated to UIListContentConfiguration.sidebarCell() in the view hiearchy and add some custom views.
If I have some properties controlling the appearance for these extra custom views, they should be placed in a configuration but since my custom views are in the cell's context, it's not possible because I don't have any configuration associated to them.
So, in this case, I think it's a limitation of the API and I need to place these properties in the UICellConfigurationStatecustom key value store.
A subclass of UICollectionViewCell or UICollectionViewListCell that you create. This is very common. You can use a cell subclass without manually adding any custom views to its contentView, if you set the contentConfiguration of the cell directly.
A cell with your own custom views that you create and add to the cell's contentView. Usually this is implemented in a cell subclass.
Now, in addition to all that, you can also create a custom content configuration and content view, using the UIContentConfiguration and UIContentView protocols. This allows you to create a configuration type (like UIListContentConfiguration) and a paired content view type (like UIListContentView), and then use that custom configuration just like a system-provided one. You can set a custom configuration to the contentConfiguration property directly on the cell, and provided you implemented it correctly, it will create or update your content view and allow you to do anything you want.
If you are making a custom content configuration and view, you can use composition to build on top of the system-provided UIListContentConfiguration and UIListContentView. Just include a UIListContentConfiguration as a property on your custom configuration, and then in your custom content view implementation, create a UIListContentView that you add and update using the UIListContentConfiguration from your custom configuration. In this way, you can use all the features of the system-provided configuration/view, and add additional views or behaviors on top of it.
To answer your question, if you are just adding a UIListContentView and one or two custom views alongside it to the cell's contentView, and are not using a custom content configuration, you don't need to put the properties for your extra custom views in a content configuration, but you still may want to put those properties into the UICellConfigurationState so you can get some of the benefits discussed earlier. For example, you can do all the setup and updating of your extra custom views from inside your cell subclass' override of updateConfiguration(using state:), based entirely on the state passed in. See the CustomListCell in the Implementing Modern Collection Views sample code for an example of this. You don't have to put those properties into the UICellConfigurationState if you don't want to, though — you could manage your cell's custom views the same way you would have before iOS 14, if you prefer.