Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS-3570 Simple table | fix crash iOS 18, add template view (to release) #2236

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@ final class SpreadsheetViewDataSource {
var allModels = [[EditorItem]]()
private lazy var dataSource: DataSource = makeCollectionViewDataSource()
private let collectionView: EditorCollectionView

private let templateCell = EditorViewListCell()

init(collectionView: EditorCollectionView) {
self.collectionView = collectionView
}

func dequeueCell(at indexPath: IndexPath) -> UICollectionViewCell {
func templateCell(at indexPath: IndexPath) -> UICollectionViewCell {
let item = allModels[indexPath.section][indexPath.row]

return collectionView.dequeueConfiguredReusableCell(
using: createCellRegistration(),
for: indexPath,
item: item.contentConfigurationProvider
)
setupCell(cell: templateCell, indexPath: indexPath, item: item.contentConfigurationProvider, template: true)
return templateCell
}

func contentConfigurationProvider(
Expand Down Expand Up @@ -70,7 +67,7 @@ final class SpreadsheetViewDataSource {
guard let indexPath = dataSource.indexPath(for: item),
let cell = collectionView.cellForItem(at: indexPath) as? EditorViewListCell else { return }

setupCell(cell: cell, indexPath: indexPath, item: item.contentConfigurationProvider)
setupCell(cell: cell, indexPath: indexPath, item: item.contentConfigurationProvider, template: false)
}

func dataSourceItem(for blockId: String) -> EditorItem? {
Expand All @@ -96,7 +93,7 @@ final class SpreadsheetViewDataSource {

private func createCellRegistration() -> UICollectionView.CellRegistration<EditorViewListCell, any ContentConfigurationProvider> {
.init { [weak self] cell, indexPath, item in
self?.setupCell(cell: cell, indexPath: indexPath, item: item)
self?.setupCell(cell: cell, indexPath: indexPath, item: item, template: false)
}
}

Expand All @@ -109,7 +106,8 @@ final class SpreadsheetViewDataSource {
private func setupCell(
cell: EditorViewListCell,
indexPath: IndexPath,
item: some ContentConfigurationProvider
item: some ContentConfigurationProvider,
template: Bool
) {
cell.contentConfiguration = item.makeSpreadsheetConfiguration()
cell.contentView.isUserInteractionEnabled = true
Expand All @@ -119,7 +117,7 @@ final class SpreadsheetViewDataSource {
cell.fillSubviewsWithRandomColors(recursively: false)
}

if let dynamicHeightView = cell.contentView as? any DynamicHeightView {
if !template, let dynamicHeightView = cell.contentView as? any DynamicHeightView {
dynamicHeightView.heightDidChanged = { [weak self] in
(self?.collectionView.collectionViewLayout as? SpreadsheetLayout)?.setNeedsLayout(indexPath: indexPath)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ final class SpreadsheetLayout: UICollectionViewLayout {
continue
}

let cell = dataSource.dequeueCell(at: indexPath)
let cell = dataSource.templateCell(at: indexPath)

let maxSize = CGSize(
width: columnWidth,
Expand Down
Loading