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

Support dynamic tables #42

Merged
merged 19 commits into from
Feb 22, 2020
Merged

Support dynamic tables #42

merged 19 commits into from
Feb 22, 2020

Conversation

twodayslate
Copy link
Contributor

No description provided.

Source/Views/QuickTableView.swift Outdated Show resolved Hide resolved
Source/Views/QuickTableView.swift Outdated Show resolved Hide resolved
Source/Views/QuickTableView.swift Outdated Show resolved Hide resolved
Source/Views/QuickTableView.swift Outdated Show resolved Hide resolved
Source/Views/QuickTableView.swift Outdated Show resolved Hide resolved
Example-iOS/ViewControllers/RootViewController.swift Outdated Show resolved Hide resolved
Example-iOS/ViewControllers/DynamicViewController.swift Outdated Show resolved Hide resolved
Example-iOS/ViewControllers/DynamicViewController.swift Outdated Show resolved Hide resolved
Example-iOS/ViewControllers/DynamicViewController.swift Outdated Show resolved Hide resolved
Example-iOS/ViewControllers/DynamicViewController.swift Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Feb 15, 2020

Codecov Report

Merging #42 into develop will increase coverage by 2.5%.
The diff coverage is n/a.

@@            Coverage Diff            @@
##           develop     #42     +/-   ##
=========================================
+ Coverage    92.59%   95.1%   +2.5%     
=========================================
  Files           15      14      -1     
  Lines          378     347     -31     
=========================================
- Hits           350     330     -20     
+ Misses          28      17     -11
Impacted Files Coverage Δ
Source/Views/SwitchCell.swift 75% <0%> (-5%) ⬇️
Source/Rows/NavigationRow.swift 100% <0%> (ø) ⬆️
Source/Rows/SwitchRow.swift 100% <0%> (ø) ⬆️
Source/Views/TapActionCell.swift
Source/QuickTableViewController.swift 90.24% <0%> (+3.78%) ⬆️

@bcylin
Copy link
Owner

bcylin commented Feb 17, 2020

Hi @twodayslate, thanks for opening this pull request. Can you briefly explain what these changes are for?

@twodayslate
Copy link
Contributor Author

twodayslate commented Feb 17, 2020

@bcylin I included an example to demonstrate the capabilities. The implementation is rather simplistic but it allows for the use of insertRows and the like without having to redefine tableContents- all you have to do is just define a getter for tableContents and the table will be reloaded auto-magically.

I would think this fixes the main limitation of QuickTableViewController as specified in the README. I would still say that IGListKit may still be better for large data sources however.

Open to suggestions and improvements.

Copy link
Owner

@bcylin bcylin left a comment

Choose a reason for hiding this comment

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

@twodayslate thanks for improving this library.

The demo you added in the example looks nice! However, it doesn't seem to require any changes in the QuickTableViewController class if I don't miss anything. Also, this library was not designed for adding and removing rows in the table view. With the trend towards SwiftUI, I think that'd be a much better solution to build such dynamic table contents.

I tend not to add unnecessary workarounds to the library. If you'd like to keep the demo in the example, can you please revert the changes in the Source directory? Thanks much!

Comment on lines 30 to 50
internal final class DynamicViewController: QuickTableViewController {

var dynamicRows: [Row] = []

override var tableContents: [Section] {
get {
let rows = [
TapActionRow(text: "AddCell", action: { _ in
self.dynamicRows.append(
NavigationRow(text: "UITableViewCell", detailText: .value1(String(describing: (self.dynamicRows.count + 1))), action: nil)
)
self.tableView.insertRows(at: [IndexPath(row: self.dynamicRows.count, section: 0)], with: .automatic)
})
] + dynamicRows

return [
Section(title: "Tap Action", rows: rows as! [Row & RowStyle])
]
}
set {} // swiftlint:disable:this unused_setter_value
}
Copy link
Owner

Choose a reason for hiding this comment

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

If you revert all the changes in the Source directory, these lines will still make the demo work. It seems you don't need to modify QuickTableViewController or introduce a new delegate at all?

Copy link
Contributor Author

@twodayslate twodayslate Feb 18, 2020

Choose a reason for hiding this comment

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

The calculations of tableContents wouldn't be cached tho. Add a sleep(1) and/or print to the tableContents getter and the performance difference/access count.

Copy link
Owner

Choose a reason for hiding this comment

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

If you need cache due to the dynamic contents, please implement the cachedTableContents in the subclass and override tableView in the DynamicViewController, e.g. 9dec58a.

Copy link
Contributor Author

@twodayslate twodayslate Feb 19, 2020

Choose a reason for hiding this comment

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

That works for me. I assume you have no desire to actually put QuickTableView and QuickTableViewDelegate into the package? And/or perhaps a QuickDynamicTableViewController which does the subclassing in the example for the user?

Copy link
Owner

Choose a reason for hiding this comment

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

The dynamic table view controller in the example would be nice. 👍

Example-iOS/ViewControllers/DynamicViewController.swift Outdated Show resolved Hide resolved
Copy link
Owner

@bcylin bcylin left a comment

Choose a reason for hiding this comment

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

Thanks for trying out new ideas! Just a few minor tweaks before merging. LGTM 👍

Example-iOS/ViewControllers/DynamicViewController.swift Outdated Show resolved Hide resolved
Example-iOS/ViewControllers/QuickTableView.swift Outdated Show resolved Hide resolved
@twodayslate
Copy link
Contributor Author

Thank you for taking the time to review this. Your feedback was appreciated.

@bcylin bcylin merged commit e040678 into bcylin:develop Feb 22, 2020
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.

3 participants