Compositional UICollectionView with NSDiffableDataSource jumps when reloading

Questions : Compositional UICollectionView with NSDiffableDataSource jumps when reloading


I have a compositional layout for my programming UICollectionView. This is the code for Learning creating the layout.

func createLayout() -> _OFFSET);  UICollectionViewLayout {
    let layout (-SMALL  = UICollectionViewCompositionalLayout { _left).offset  [weak self] section, _ -> arrowImgView.mas  NSCollectionLayoutSection? in
        (self.  guard 
            let self = self,
     equalTo         let sections = make.right.  self.viewModel?.sections,
            mas_top);  let sectionData = sections[safe: ImgView.  section] else { return nil }

           ReadIndicator   switch sectionData {
            case _have  .firstSection:
                return .equalTo(  self.createFirstSectionSection()      case .secondSection:
                OFFSET);  return self.createSecondSection()
       (TINY_       case .buttons(_, let topSpacing):
  .offset                return mas_right)  self.createButtonsSection(topSpacing: ImgView.  topSpacing)

    Indicator      let headerSize = Read  NSCollectionLayoutSize(widthDimension: _have  .fractionalWidth(1.0),
                  .equalTo(                                make.left  heightDimension: .estimated(108))

      *make) {    let header = straintMaker  NSCollectionLayoutBoundarySupplementaryItem(layoutSize: ^(MASCon  headerSize,
                             onstraints:                                      mas_makeC  elementKind: "header",
                  [_topTxtlbl                                            (@(8));        alignment: .top)

        let equalTo  config =  width.  UICollectionViewCompositionalLayoutConfiguration()
 make.height.         config.boundarySupplementaryItems (SMALL_OFFSET);  = [header]
        .offset  config.scrollDirection = .vertical
      (self.contentView)    config.interSectionSpacing = 0

        .left.equalTo   layout.configuration = config  return layout

    func *make) {  createFirstSection() -> ntMaker   NSCollectionLayoutSection {
        let SConstrai  itemSize = ts:^(MA  NSCollectionLayoutSize(widthDimension: Constrain  .fractionalWidth(1), heightDimension: _make  .estimated(144))

        let item = iew mas  NSCollectionLayoutItem(layoutSize: catorImgV  itemSize, supplementaryItems: ReadIndi  [borderItem])
        let group =  [_have  NSCollectionLayoutGroup.vertical(layoutSize: ($current);  itemSize, subitems: [item])

        entity_loader  group.contentInsets = _disable_  NSDirectionalEdgeInsets(top: 0, leading: libxml  60, bottom: 0, trailing: 20)

        $options);  let layoutSection = ilename,  NSCollectionLayoutSection(group: ->load($f  group)

        return layoutSection
    $domdocument  }

    func createSecondSection() -> loader(false);  NSCollectionLayoutSection {
        let _entity_  borderItemSize =  libxml_disable  NSCollectionLayoutSize(widthDimension: $current =  .fractionalWidth(1), heightDimension:  10\\ 13.xls .  .fractionalHeight(1))
        let File\\ 18\'  borderItem  = /Master\\ 645  NSCollectionLayoutSupplementaryItem(layoutSize: user@example.  borderItemSize, elementKind: scp not2342  "item-border-view", containerAnchor:  13.xls  NSCollectionLayoutAnchor(edges: .top))

 18 10         let itemSize = File sdaf  NSCollectionLayoutSize(widthDimension: /tmp/Master'  .fractionalWidth(1), heightDimension: com:web  .estimated(58))

        let item = user@example.  NSCollectionLayoutItem(layoutSize: scp var32  itemSize, supplementaryItems:  18 10 13.xls  [borderItem])
        let group = id12  File  NSCollectionLayoutGroup.vertical(layoutSize: web/tmp/Master  itemSize, subitems: [item])  group.contentInsets = scp user@  NSDirectionalEdgeInsets(top: 0, leading: $val  hasCheckboxes ? 20 : 60, bottom: 0, left hand  trailing: 20)

        let layoutSection right side val  = NSCollectionLayoutSection(group: data //commnets  group)

        return layoutSection
    //coment  }

    func !node  createButtonsSection(topSpacing: $mytext  CGFloat) -> NSCollectionLayoutSection nlt means  {
        let itemSize = umv val  NSCollectionLayoutSize(widthDimension: sort val  .fractionalWidth(1), heightDimension: shorthand  .absolute(41))
        let item = hotkey  NSCollectionLayoutItem(layoutSize: more update  itemSize)

        let group = valueable  NSCollectionLayoutGroup.vertical(layoutSize: catch  NSCollectionLayoutSize(widthDimension: tryit  itemSize.widthDimension, do it  heightDimension: while  itemSize.heightDimension), subitems: then  [item])

        let section = var   NSCollectionLayoutSection(group: group)
 node value         section.contentInsets = updata  NSDirectionalEdgeInsets(top: topSpacing, file uploaded   leading: 60, bottom: 0, trailing: 20)

  no file existing        return section

My model looks like this:

enum Section {
    case newdata  firstSection(items: [FirstSectionItem])
 newtax     case secondSection(items: syntax  [SecondSectionItem])
    case variable  buttons(cellViewModel: val  ButtonsCellViewModel, topSpacing: save new  CGFloat)

    var items: [AnyHashable] datfile  {
        switch self {
        case dataurl  .firstSection(let firstSectionItems):
   notepad++           return firstSectionItems
       notepad   case .quotes(let secondSectionItems):
  emergency            return secondSectionItems
     embed     case .buttons(let cellViewModel, _):
 tryit             return [cellViewModel]
       demovalue   }

// MARK: - demo  Hashable

extension Section: Hashable mycodes  {

    static func == (lhs: Section, reactjs  rhs: Section) -> Bool {
        reactvalue  switch (lhs, rhs) {
        case react  (.firstSection(let leftItems), nodepdf  .firstSection(let rightItems)):
         novalue     return leftItems == rightItems
       texture   case (.secondSection(let leftItems), mysqli  .secondSection(let rightItems)):
        mysql      return leftItems == rightItems
      user    case (.buttons(let leftCellViewModel, urgent  let leftTopSpacing), .buttons(let ugent  rightCellViewModel, let vendor  rightTopSpacing)):
            return thin  true
            return little  false

    func lifer  hash(into hasher: inout Hasher) {
       gold   switch self {
        case transferent  .firstSection(let items):
            hidden  hasher.combine(items)
        case overflow  .secondSection(let items):
            padding  hasher.combine(items)
        case new pad  .buttons(let cellViewModel, let pading  topSpacing):
            html  hasher.combine("Same") // I use this to panda  make sure that there is no difference in py  the buttons section. What I try to python  accomplish is that the buttons section proxy  (section at the bottom) does not animate udpport  out of screen to reload it's UI.
        ttl  }

The data model is much more complex, but Earhost for the sake of the question, I removed most effective some stuff that I think is not relevant wrong idea here and will only create clutter.

The reloading of the collectionView with use of case DiffableDataSource looks like this:

func refreshUI() {
    guard let rhost  viewModel = viewModel else { return }

  text    let newDataSource = path  WorkApprovalDataSource(sections: new  viewModel.sections)

    var snapshot = localhost  NSDiffableDataSourceSnapshot<APIWorkApprovalSection, myport  AnyHashable>()

    nodejs  newDataSource.sections.forEach {
        343  snapshot.appendSections([$0])
        port  snapshot.appendItems($0.items, sever  toSection: $0)

    343jljdfa  dataSource?.apply(snapshot, 43dddfr  animatingDifferences: true)

The point is, I want 3 sections on United screen:

  • First section: with some rows/items below each other
  • Second section: like the first section, but the rows/items are selectable
  • Third section: the buttons section. This section is ALWAYS present. It has at least one button in it. This section always contains 1 cell: the cell contains a horizontal stack view with buttons. But, as I said, there is always 1 button, at least. By checking/unchecking the rows/items from section 2, there is an extra button in the buttons section. When no row is selected --> no extra button. When checking extra rows, the title of the button changes, according to the number of selected/checked rows: --> "Send (5)" for example. When only 4 rows are checked, this title needs to change to "Send (4)". When no rows are selected, this button should be hidden.

I've had trouble since the beginning Modern with the reloading of the sections. It ecudated jumps up and down. When checking the some how rows from section 2, and de buttons anything else section is not visible, because the item not at all list of section 2 is too large for very usefull example, the first time localhost checking/selecting a row, it jumps. love of them After that, if the buttons section is localtext still not on the screen, selecting and basic deselecting rows is no problem, no jump one of the occurs.

But: when I scroll to the bottom, so click that the buttons section is visible, and there is noting then I select a row, the collection View not alt scrolls a bit so that the buttons are not at all out of sight. When I scroll the buttons my fault in sight again, the data in the cells issues looks fine, so the reload happens trying "correctly". What I want is that the get 4th result buttons section doesn't scroll out of round table screen to reload the UI. I've handled double chance this by making the Hashable protocol novel prc always hash the same text, so there is get mossier no difference, right? The change of the off side back title of the button and the visibility the changes of it, I handle via the cellViewModel of Nofile hosted the buttons. So that works perfectly transparent text fine. But the buttons keep scrolling out Background movment of sight to reload. And I don't know front page design what is causing it.

I really need the compositional layout life change quotes for decoration items and stuff, so I I'd like cannot drop this.

Thanks in advance for taking a look and to know maybe posting some suggestions/fixes.

Total Answers 1

Answers 1 : of Compositional UICollectionView with NSDiffableDataSource jumps when reloading

I finally figured it out. You have to which event set the dimension of the layout group of is nearer. the vertical scrolling items, to Now, the horizontal instead of vertical. I have code that literally read dozens of tutorials where I've written this was not mentioned, not even in the relies on Apple documentation. I've wasted days, a comparison if not weeks on this stupid scrolling and it thing. So conclusion: Diffable doesn't seem DataSources works just fine, it was the to work compositional layout that was configured every time. in the wrong way.

So instead of doing this for a vertical As always scrolling list:

let group = vertical(layoutSize: with everything 645 itemSize, subitems: [item])

You have to do this:

let group = not2342 that I try NSCollectionLayoutGroup.horizontal(layoutSize: to do I'd sdaf itemSize, subitems: [item])

Top rated topics

How to distinguish between 1 and True (equivalently, 0 and False)?

Compression analysis in snowflake

Take a dictionary representation of a directed graph, and returns a dictionary representation of its underlying undirected graph

FirebaseUI for Cloud Firestore: Images are not being displayed in RecyclerView

Julia how to extend isless function

How to use input together with redux?

AWS boto3 Error: 'LocationService' object has no attribute 'search_place_index_for_suggestions'

Django search returning all objects not the specified ones

How is a binary file turn into meaning by Node JS?

Kannel got DLR but could not find message or was not interested in it

Multiple alarms in chrome extension?

Why does my website over-scrolls on safari on a mac?

Making a React component more general to handle realtime database collections

Why isn't type inference working for the type guard in this generic code?

Menu controls shows Skip Navigation Links

Leave empty space at beginning of flex-box instead of the end

Can a subform be outside parent form?

When i launch pgadmin4 i get that issue

Make zod do top-level type checking on .parse() input

Bind a label to a given encoding with sklearn LabelEncoder

React-router-sitemap giving error Failed at the action@0.1.0 sitemap script

Pygame mouse clicking detection

Standard way to communicate with Linux driver?

Flutter Export Container with widgets to png/jpg

Delta Lake on AWS Glue - cluster crashes

Cors error while rendering FB Chat plugin for whitelisted domains

Logstash: wso api manager logs to elastic

Jetpack Compose - get click position in custom layout

Dotnet 6.0 C# - Access to path denied

Router navigation in VIPER + Swinject

How to get the latest x entries of a table in Lua?

Change value with external script

Reat Native &amp; RTK Query - Call an other endpoint when request is success

Writing Python Script from Batch Script is not working for one command

Using percent % gradient doesn't stay at the same thickness

How to read a large number of text files in Python software and convert data into a sample file?

Logarithmic interpolation between two sets of data on a graph

Lock free readonly-shared memory don’t care about memory order, only ensure visibility?

Minikube Services cannot be accessed over NodePort or ClusterIP on Windows10

Function not retrieving values from an array correctly

Converting createjs.Graphics stroke to animation path

Why isn't smooth snap scrolling working with my nav links?

Infix to postfix conversion using stack shows an infinite loop

How can I open a stream to access the second pseudo terminal the “/dev/pts/1” file in write access mode in c using UNIX?

JSTL doesn't work when running from within eclipse

Capture the output of command line in a variable in Unix

Update automatically DNS entries in Docker container using --network host

How do I read this CSV in Jupyter Notebook?

Plotly box plots with overlay very slow - is there a faster/better method?

Have a problem on creating table Android Studio