Skip to content

Commit

Permalink
- AccountController: replace section.addExpanded() with expansion Col…
Browse files Browse the repository at this point in the history
…lectionViewAction

- CollectionViewAction: add missing parts in implementation for .expand() to expand cells, add status awareness (double expansion collapses them again)
- CollectionViewSection: check cell expansion status before expanding the cell (double expansion collapses them again)
  • Loading branch information
felix-schwarz committed Dec 11, 2023
1 parent 23b11e1 commit ecf3610
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,12 @@ public class AccountController: NSObject, OCDataItem, OCDataItemVersioning, Acco
if let quickAccessFolderDataSource = specialItemsDataSources[.quickAccessFolder] {
sources.append(quickAccessFolderDataSource)
}

if configuration.expandQuickAccess, let accountControllerSection = accountControllerSection,
let quickAccessItemRef = accountControllerSection.collectionViewController?.wrap(references: [ specialItemsDataReferences[.quickAccessFolder]! ], forSection: accountControllerSection.identifier).first {
accountControllerSection.addExpanded(item: quickAccessItemRef)
accountControllerSection.collectionViewController?.addActions([
CollectionViewAction(kind: .expand(animated: false), itemReference: quickAccessItemRef)
])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,19 @@ public class CollectionViewAction: NSObject {
viewController.performDataSourceUpdate { updateDone in
if let datasource = viewController.collectionViewDataSource, let sectionID {
var sectionSnapshot = datasource.snapshot(for: sectionID)
sectionSnapshot.expand([ itemRef ])
datasource.apply(sectionSnapshot, to: sectionID, animatingDifferences: animated, completion: {
completion?()
updateDone()
})
if !sectionSnapshot.isExpanded(itemRef) {
sectionSnapshot.expand([ itemRef ])

if let section = viewController.sectionsByID[sectionID] {
let childSnapshot = section.provideHierarchicContent(for: collectionView, parentItemRef: itemRef, existingSectionSnapshot: nil)
sectionSnapshot.replace(childrenOf: itemRef, using: childSnapshot)

datasource.apply(sectionSnapshot, to: sectionID, animatingDifferences: animated, completion: {
completion?()
updateDone()
})
}
}
} else {
completion?()
updateDone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,12 @@ public class CollectionViewSection: NSObject, OCDataItem, OCDataItemVersioning {
if let collectionView = collectionViewController?.collectionView {
for expandedItemRef in expandedItemRefs {
if sectionSnapshot.contains(expandedItemRef) {
sectionSnapshot.expand([expandedItemRef])
if !sectionSnapshot.isExpanded(expandedItemRef) {
sectionSnapshot.expand([expandedItemRef])

let childSnapshot = provideHierarchicContent(for: collectionView, parentItemRef: expandedItemRef, existingSectionSnapshot: nil)
sectionSnapshot.replace(childrenOf: expandedItemRef, using: childSnapshot)
let childSnapshot = provideHierarchicContent(for: collectionView, parentItemRef: expandedItemRef, existingSectionSnapshot: nil)
sectionSnapshot.replace(childrenOf: expandedItemRef, using: childSnapshot)
}
}
}
}
Expand Down

0 comments on commit ecf3610

Please sign in to comment.