Giter VIP home page Giter VIP logo

Comments (6)

ra1028 avatar ra1028 commented on May 27, 2024

Hi @Wolly1985,

UICollectionView.moveItem doesn't call cellForItemAtIndexPath.
If you want to update the cell appearance, you should return a false value in your model's isContentEqual(to:).
This way DifferenceKit will call reloadItem and update cell appearances.

from differencekit.

Wolly1985 avatar Wolly1985 commented on May 27, 2024

Hi @ra1028 this reload all cells and not only this that moves. also the call reloadItem is before the item is move to the another section

greetz

from differencekit.

Wolly1985 avatar Wolly1985 commented on May 27, 2024

i found a Soulution with a edit CollectionView Extension. thx for help

`public extension UICollectionView {

func reload<C>(
    using stagedChangeset: StagedChangeset<C>,
    reloadChangeCells: Bool,
    interrupt: ((Changeset<C>) -> Bool)? = nil,
    setData: (C) -> Void
) {
    if case .none = window, let data = stagedChangeset.last?.data {
        setData(data)
        return reloadData()
    }
    
    let contentOffset = self.contentOffset
    var indexPaths: [IndexPath] = []
    for changeset in stagedChangeset {
        if let interrupt = interrupt, interrupt(changeset), let data = stagedChangeset.last?.data {
            setData(data)
            return reloadData()
        }
        
        performBatchUpdates({
            setData(changeset.data)
            
            if !changeset.sectionDeleted.isEmpty {
                deleteSections(IndexSet(changeset.sectionDeleted))
            }
            
            if !changeset.sectionInserted.isEmpty {
                insertSections(IndexSet(changeset.sectionInserted))
            }
            
            if !changeset.sectionUpdated.isEmpty {
                reloadSections(IndexSet(changeset.sectionUpdated))
            }
            
            for (source, target) in changeset.sectionMoved {
                moveSection(source, toSection: target)
            }
            
            if !changeset.elementDeleted.isEmpty {
                deleteItems(at: changeset.elementDeleted.map { IndexPath(item: $0.element, section: $0.section) })
            }
            
            if !changeset.elementInserted.isEmpty {
                insertItems(at: changeset.elementInserted.map { IndexPath(item: $0.element, section: $0.section) })
            }
            
            if !changeset.elementUpdated.isEmpty {
                reloadItems(at: changeset.elementUpdated.map { IndexPath(item: $0.element, section: $0.section) })
            }
            
            for (source, target) in changeset.elementMoved {
                moveItem(at: IndexPath(item: source.element, section: source.section), to: IndexPath(item: target.element, section: target.section))
                indexPaths.append(IndexPath(item: target.element, section: target.section))
            }
        }) { (complete) in
            if reloadChangeCells {
                self.reloadItems(at: indexPaths)
            }
        }
    }
    
    if contentSize.height > bounds.size.height {
        setContentOffset(contentOffset, animated: false)
    }
}

}`

from differencekit.

Wolly1985 avatar Wolly1985 commented on May 27, 2024

my solution crashs after move many items has completion conflict with the datasource. but in performBatchUpdates its to early because when call moveItem, reloadItems(at: indexPaths) crashs because wrong index.

from differencekit.

ra1028 avatar ra1028 commented on May 27, 2024

@Wolly1985
Sorry for my late reply.

I think you should contain all the rendering information in your model instance.
But you can workaround as below is also possible.

collectionView.reload(using: changeset) { data in
    self.data = data
}
collectionView.indexPathsForVisibleItems.forEach { indexPath in
    guard let cell = collectionView.cellForItem(at: indexPath) else { return }
    cell.alpha = indexPath.section == 0 ? 1 : 0.5
}

from differencekit.

ra1028 avatar ra1028 commented on May 27, 2024

I close this issue.
If you still want to ask, please reopen it.

from differencekit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.