Recommended UIContentConfiguration / UIContentView pattern for table and collection cells
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Documentation
- Clarity
- Needs clarification
- Activity status
- Quiet
- Tech stack
- swift
- Domain
- mobile-dev
Research direction
Start with Sources/QuickLayout/QuickLayoutBridge/ViewImplementation/HasBody.swift at the linked UITableViewCell and UICollectionViewCell special case, then review the UIContentConfiguration and CardContentView example in this issue. Document the supported ownership, sizing and invalidation behavior, supports(_:) reuse guidance, and any table-versus-collection differences, with examples for both cell types.
Written by the indexing model from the issue text.
Description
Question
Related to #12, but this question is about UIKit’s configuration-based cell architecture rather than applying @QuickLayout directly to each cell subclass.
QuickLayout currently special-cases UITableViewCell and UICollectionViewCell so that a cell’s QuickLayout body is hosted in cell.contentView. With UIContentConfiguration, UIKit creates and manages a custom UIContentView. I could not find an example of this pattern and am unsure which object should own QuickLayout layout and sizing.
When a generic UITableViewCell or UICollectionViewCell receives a custom UIContentView, is applying @QuickLayout to that content view the supported approach?
Minimal example
struct CardConfiguration: UIContentConfiguration {
let title: String
@MainActor
func makeContentView() -> any UIView & UIContentView {
CardContentView(configuration: self)
}
func updated(for state: any UIConfigurationState) -> Self {
self
}
}
@QuickLayout
final class CardContentView: UIView, UIContentView {
private let titleLabel = UILabel()
private var model: CardConfiguration
var configuration: any UIContentConfiguration {
get { model }
set {
guard let configuration = newValue as? CardConfiguration else { return }
model = configuration
titleLabel.text = configuration.title
setNeedsLayout()
}
}
init(configuration: CardConfiguration) {
model = configuration
super.init(frame: .zero)
self.configuration = configuration
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError()
}
var body: Layout {
HStack {
titleLabel
}
.padding(.horizontal, 16)
.padding(.vertical, 8)
}
}
// The same configuration is assigned to either cell type:
cell.contentConfiguration = CardConfiguration(title: title)
Could you clarify:
- Should
@QuickLayoutlive only on the customUIContentView, leaving the cell generic, or should the cell also adopt@QuickLayout? - For self-sizing table rows and collection items with estimated dimensions, is the generated
sizeThatFits(_:)on the content view sufficient, or is cell-level sizing customization still required as discussed in #12? - When applying a configuration that changes the content size, is
setNeedsLayout()sufficient? ShouldinvalidateIntrinsicContentSize(), a cell-level invalidation call, or a QuickLayout-specific helper be used? - On iOS 16+, should
supports(_:)be implemented so UIKit can reuse the existing content view? - Are there any differences in the recommended pattern for
UITableViewCellandUICollectionViewCell?
An official example covering both cell types would be very helpful. Thanks!
Environment
- QuickLayout:
mainat38020f2 - Swift 6
- iOS 15+
- Dominant language
- Swift
- Stars
- 365
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from facebook/QuickLayout
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
facebook/QuickLayout#21 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
facebook/QuickLayout#6 · 6 comments ·
-
How to run the Test? Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
facebook/QuickLayout#2 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 20/100
facebook/QuickLayout#1 · 1 comment ·
All issues in facebook/QuickLayout
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
googleapis/google-cloud-swift#1106 ·
-
bug channel: beta feature: preferences feature: ui/ux
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Cocoanetics/SwiftACP#52 ·