Recommended UIContentConfiguration / UIContentView pattern for table and collection cells
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Documentazione
- Chiarezza
- Da chiarire
- Stato di attività
- Tranquilla
- Stack tecnologico
- swift
- Ambito
- mobile-dev
Direzione di ricerca
Inizia da Sources/QuickLayout/QuickLayoutBridge/ViewImplementation/HasBody.swift nel caso speciale collegato di UITableViewCell e UICollectionViewCell, quindi esamina l’esempio di UIContentConfiguration e CardContentView in questa issue. Documenta il comportamento supportato relativo a ownership, sizing e invalidation, le indicazioni sul riutilizzo di supports(_:) e le eventuali differenze tra tabelle e collezioni, con esempi per entrambi i tipi di cella.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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+
- Lingua principale
- Swift
- Stelle
- 366
- Fork
- 21
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di facebook/QuickLayout
-
Is Mac Catalyst unsupported?Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
facebook/QuickLayout#21 · 2 commenti ·
-
Naming duplicate issuesAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
facebook/QuickLayout#6 · 6 commenti ·
-
How to run the Test?Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
facebook/QuickLayout#2 · 3 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 20/100
facebook/QuickLayout#1 · 1 commento ·
Tutte le issue di facebook/QuickLayout
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
TelegramMessenger/Telegram-iOS#2354 ·
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:other issue-rating: 🦞 diamond lobster no-stale P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
steipete/CodexBar#4202 · 2 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
api: remoteconfig
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
firebase/firebase-ios-sdk#16816 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
gax
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
googleapis/google-cloud-swift#1346 ·
I maintainer di solito rispondono entro 1 giorno