Recommended UIContentConfiguration / UIContentView pattern for table and collection cells
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Documentación
- Claridad
- Necesita aclaración
- Estado de actividad
- Tranquilo
- Stack tecnológico
- swift
- Área
- mobile-dev
Línea de trabajo
Comienza con Sources/QuickLayout/QuickLayoutBridge/ViewImplementation/HasBody.swift en el caso especial vinculado de UITableViewCell y UICollectionViewCell, y luego revisa el ejemplo de UIContentConfiguration y CardContentView en este issue. Documenta el comportamiento admitido de ownership, sizing e invalidation, las directrices de reutilización de supports(_:) y cualquier diferencia entre tablas y colecciones, con ejemplos para ambos tipos de celda.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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+
- Lenguaje dominante
- Swift
- Estrellas
- 365
- Forks
- 21
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de facebook/QuickLayout
-
Is Mac Catalyst unsupported? Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
facebook/QuickLayout#21 · 2 comentarios ·
-
Naming duplicate issues Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
facebook/QuickLayout#6 · 6 comentarios ·
-
How to run the Test? Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
facebook/QuickLayout#2 · 3 comentarios ·
-
Does QuickLayout support iOS14? Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 20/100
facebook/QuickLayout#1 · 1 comentario ·
Todos los issues de facebook/QuickLayout
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
googleapis/google-cloud-swift#1106 ·
-
bug channel: beta feature: preferences feature: ui/ux
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Cocoanetics/SwiftACP#52 ·