|
|
@@ -50,19 +50,14 @@ class LNGameCategoryListView: UIView {
|
|
|
guard let index = categories.firstIndex(where: { $0.code == category.code }) else {
|
|
|
return
|
|
|
}
|
|
|
- runOnMain { [weak self] in
|
|
|
+ DispatchQueue.main.async { [weak self] in
|
|
|
guard let self else { return }
|
|
|
- let sections = collectionView.numberOfSections
|
|
|
- guard sections > 0, index < sections else { return }
|
|
|
- collectionView.layoutIfNeeded()
|
|
|
if let headerAttributes = collectionView.layoutAttributesForSupplementaryElement(
|
|
|
ofKind: UICollectionView.elementKindSectionHeader,
|
|
|
at: IndexPath(item: 0, section: index))
|
|
|
{
|
|
|
collectionView.setContentOffset(.init(x: 0, y: headerAttributes.frame.origin.y), animated: true)
|
|
|
} else {
|
|
|
- let items = collectionView.numberOfItems(inSection: index)
|
|
|
- guard items > 0 else { return }
|
|
|
collectionView.scrollToItem(at: .init(row: 0, section: index), at: .top, animated: true)
|
|
|
}
|
|
|
}
|
|
|
@@ -74,7 +69,7 @@ class LNGameCategoryListView: UIView {
|
|
|
let width = (bounds.width - collectionViewLayout.minimumInteritemSpacing) / CGFloat(columns) - collectionViewLayout.minimumInteritemSpacing
|
|
|
collectionViewLayout.itemSize = .init(width: width, height: 68)
|
|
|
|
|
|
- runOnMain { [weak self] in
|
|
|
+ DispatchQueue.main.async { [weak self] in
|
|
|
guard let self else { return }
|
|
|
fixBottomSpace()
|
|
|
}
|
|
|
@@ -87,14 +82,10 @@ class LNGameCategoryListView: UIView {
|
|
|
|
|
|
extension LNGameCategoryListView: UIScrollViewDelegate {
|
|
|
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
|
|
- guard !categories.isEmpty else { return }
|
|
|
let offsetY = scrollView.contentOffset.y
|
|
|
|
|
|
- let sections = collectionView.numberOfSections
|
|
|
- guard sections > 0 else { return }
|
|
|
-
|
|
|
var section = 0
|
|
|
- for index in 0..<min(categories.count, sections) {
|
|
|
+ for index in 0..<categories.count {
|
|
|
if let headerAttributes = collectionView.layoutAttributesForSupplementaryElement(
|
|
|
ofKind: UICollectionView.elementKindSectionHeader,
|
|
|
at: IndexPath(item: 0, section: index)) {
|
|
|
@@ -151,16 +142,11 @@ extension LNGameCategoryListView: UICollectionViewDataSource, UICollectionViewDe
|
|
|
extension LNGameCategoryListView {
|
|
|
private func fixBottomSpace() {
|
|
|
guard !categories.isEmpty else { return }
|
|
|
- let sections = collectionView.numberOfSections
|
|
|
- guard sections > 0 else { return }
|
|
|
- collectionView.layoutIfNeeded()
|
|
|
- let lastSection = min(categories.count - 1, sections - 1)
|
|
|
if let headerAttributes = collectionView.layoutAttributesForSupplementaryElement(
|
|
|
ofKind: UICollectionView.elementKindSectionHeader,
|
|
|
- at: IndexPath(item: 0, section: lastSection)) {
|
|
|
- let offset = max(0, collectionView.contentSize.height - headerAttributes.frame.origin.y)
|
|
|
- let inset = max(0, bounds.height - offset)
|
|
|
- collectionView.contentInset = .init(top: 0, left: 0, bottom: inset, right: 0)
|
|
|
+ at: IndexPath(item: 0, section: categories.count - 1)) {
|
|
|
+ let offset = collectionView.contentSize.height - headerAttributes.frame.origin.y
|
|
|
+ collectionView.contentInset = .init(top: 0, left: 0, bottom: bounds.height - offset, right: 0)
|
|
|
}
|
|
|
}
|
|
|
|