Skip to content

Commit

Permalink
Merge pull request #2236 from anyproto/ios-3570-after-creating-a-tabl…
Browse files Browse the repository at this point in the history
…e-from-slash-menu-app-crashes-release

IOS-3570 Simple table | fix crash iOS 18, add template view (to release)
  • Loading branch information
mgolovko authored Oct 17, 2024
2 parents ede3cfb + 8306fb3 commit 6ee33da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
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

0 comments on commit 6ee33da

Please sign in to comment.