Fix layout call

This commit is contained in:
Siyu Yue 2022-12-20 14:12:21 -08:00
parent 0e875ed28f
commit 2097758b9b
1 changed files with 7 additions and 15 deletions

View File

@ -43,8 +43,7 @@ open class ListCellController<
} }
private var updatingViewModel = false private var updatingViewModel = false
private var invalidatingLayout = false private var didLayoutSubiewsWhenInvalidatingLayout = false
private var didUpdateCellWhenInvalidatingLayout = false
required public init( required public init(
viewModel: ListViewModel, viewModel: ListViewModel,
@ -146,13 +145,10 @@ open class ListCellController<
} }
override func cellDidLayoutSubviews() { override func cellDidLayoutSubviews() {
if invalidatingLayout {
updateCell(shouldInvalidateLayout: false)
didUpdateCellWhenInvalidatingLayout = true
}
guard let cell = cell else { guard let cell = cell else {
return return
} }
didLayoutSubiewsWhenInvalidatingLayout = true
cellDidLayoutSubviews(cell: cell as! ListCellType) cellDidLayoutSubviews(cell: cell as! ListCellType)
} }
@ -160,17 +156,13 @@ open class ListCellController<
guard let cell = cell else { guard let cell = cell else {
return return
} }
didLayoutSubiewsWhenInvalidatingLayout = false
if shouldInvalidateLayout { if shouldInvalidateLayout {
invalidatingLayout = true
didUpdateCellWhenInvalidatingLayout = false
layoutInvalidateHandler?(cell) layoutInvalidateHandler?(cell)
invalidatingLayout = false }
configureCell(cell: cell as! ListCellType)
if !didUpdateCellWhenInvalidatingLayout { if !didLayoutSubiewsWhenInvalidatingLayout {
configureCell(cell: cell as! ListCellType) cellDidLayoutSubviews(cell: cell as! ListCellType)
}
} else {
configureCell(cell: cell as! ListCellType)
} }
} }
} }