Recommended UIContentConfiguration / UIContentView pattern for table and collection cells
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- swift
- Lĩnh vực
- mobile-dev
Hướng nghiên cứu
Bắt đầu với Sources/QuickLayout/QuickLayoutBridge/ViewImplementation/HasBody.swift tại trường hợp đặc biệt UITableViewCell và UICollectionViewCell được liên kết, sau đó xem lại ví dụ UIContentConfiguration và CardContentView trong issue này. Ghi lại hành vi được hỗ trợ về ownership, sizing và invalidation, hướng dẫn tái sử dụng supports(_:) và mọi khác biệt giữa table và collection, kèm ví dụ cho cả hai loại cell.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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+
- Ngôn ngữ chính
- Swift
- Star
- 365
- Fork
- 21
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của facebook/QuickLayout
-
Is Mac Catalyst unsupported? Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
facebook/QuickLayout#21 · 2 bình luận ·
-
Naming duplicate issues Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
facebook/QuickLayout#6 · 6 bình luận ·
-
How to run the Test? Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
facebook/QuickLayout#2 · 3 bình luận ·
-
Does QuickLayout support iOS14? Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
facebook/QuickLayout#1 · 1 bình luận ·
Tất cả issue của facebook/QuickLayout
Issue tương tự
-
pending-maintainer-response pending-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
make notarise-dmg notarises whichever dist/ image sorts last, not the one make dmg just built Đang mởarea:build bug good first issue P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
uttrflow/uttrflow-swift#1412 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
enhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
-
T-Defect
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
element-hq/element-x-ios#6191 ·