Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/data did set #67

Merged
merged 6 commits into from Jul 8, 2021
Merged

Feature/data did set #67

merged 6 commits into from Jul 8, 2021

Conversation

BenShutt
Copy link
Contributor

When reloadData() is not desired after setting data subclasses may set reloadDataOnDataDidSet = false.
Subclasses should be responsible for their own reloading in this case.

Motivation and Context

Fix issue with a search row in an app referencing this framework.

How Has This Been Tested?

In the app referencing this framework.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@BenShutt
Copy link
Contributor Author

BenShutt commented Jan 22, 2021

An example here would be

// Get `IndexSet` to delete and insert
let indexSetToDelete = toDeleteIndexSet()
self.data = sections
let indexSetToInsert = toInsertIndexSet()

// Execute `tableView` updates
tableView.beginUpdates()
tableView.deleteSections(indexSetToDelete, with: .fade)
tableView.insertSections(indexSetToInsert, with: .fade)
tableView.endUpdates()

@simonmitchell
Copy link
Contributor

Nice! I actually need this for something I'm working on at the moment in Camrote. My only thought is it may also be nice to get a temporary disabling rather than a toggle (As well?) So you could either:

reloadDataOnDataDidSet = false
// Get `IndexSet` to delete and insert
let insetSetToDelete = toDeleteIndexSet()
self.data = sections
let insetSetToInsert = toInsertIndexSet()

// Execute `tableView` updates
tableView.beginUpdates()
tableView.deleteSections(insetSetToDelete, with: .fade)
tableView.insertSections(insetSetToInsert, with: .fade)
tableView.endUpdates()
reloadDataOnDataDidSet = true

OR

withoutReloading { // Store a separate boolean to `reloadDataOnDataDidSet`
    // Get `IndexSet` to delete and insert
    let insetSetToDelete = toDeleteIndexSet()
    self.data = sections
    let insetSetToInsert = toInsertIndexSet()

    // Execute `tableView` updates
    tableView.beginUpdates()
    tableView.deleteSections(insetSetToDelete, with: .fade)
    tableView.insertSections(insetSetToInsert, with: .fade)
    tableView.endUpdates()
}

@BenShutt
Copy link
Contributor Author

BenShutt commented Feb 1, 2021

@simonmitchell Yeah that does make sense :). I guess it would fundamentally work the same as this, but reloadDataOnDataDidSet would become private and we make a new public interface for withoutReloading

Copy link
Contributor

@simonmitchell simonmitchell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, discussion above can be done at a future date!

@BenShutt BenShutt changed the base branch from develop to release/v1.7.0 July 8, 2021 15:01
@BenShutt BenShutt merged commit a4da695 into release/v1.7.0 Jul 8, 2021
@BenShutt BenShutt deleted the feature/data-did-set branch July 8, 2021 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants