-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Started work on the plane to get this moving since #418 is up and ready to land. We'll likely need to spend some time fleshing out the API of this, and I think I'll split it up into a couple different PRs once ready for review. Putting this up now to get early feedback. This adds an auto-diffing section controller as outlined in #38. There are several key parts: - Subclass a new section controller `IGListAutoSectionController` (naming wip) - Connect a data source - Implement the data source methods that do 3 things: - Given a top-level object, transform it into an array of **diffable** view models - Given a view model, return a cell - Given a view model, return a size for a cell - A new protocol for the cell `IGListBindable` so that we can control when the cell is updated w/ the view model. - The most important part of this is that it unlocks moving and reloading a cell, which you can't do w/ `UICollectionView` - [ ] Unit test `reloadObjects:` - [x] Add Closes #494 Reviewed By: amonshiz Differential Revision: D4696966 Pulled By: rnystrom fbshipit-source-id: f21b8341b3ed4389f2a4a106d0d316f481ba6943
- Loading branch information
1 parent
982ded0
commit 7934816
Showing
44 changed files
with
2,409 additions
and
871 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Examples/Examples-iOS/IGListKitExamples/Models/Month.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
Copyright (c) 2016-present, Facebook, Inc. All rights reserved. | ||
The examples provided by Facebook are for non-commercial testing and evaluation | ||
purposes only. Facebook reserves all rights not expressly granted. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import Foundation | ||
import IGListKit | ||
|
||
final class Month { | ||
|
||
let name: String | ||
let days: Int | ||
|
||
// day int mapped to an array of appointment names | ||
let appointments: [Int: [NSString]] | ||
|
||
init(name: String, days: Int, appointments: [Int: [NSString]]) { | ||
self.name = name | ||
self.days = days | ||
self.appointments = appointments | ||
} | ||
|
||
} | ||
|
||
extension Month: IGListDiffable { | ||
|
||
func diffIdentifier() -> NSObjectProtocol { | ||
return name as NSObjectProtocol | ||
} | ||
|
||
func isEqual(toDiffableObject object: IGListDiffable?) -> Bool { | ||
return true | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
Examples/Examples-iOS/IGListKitExamples/Models/ViewModels/DayViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
Copyright (c) 2016-present, Facebook, Inc. All rights reserved. | ||
The examples provided by Facebook are for non-commercial testing and evaluation | ||
purposes only. Facebook reserves all rights not expressly granted. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import Foundation | ||
import IGListKit | ||
|
||
final class DayViewModel { | ||
|
||
let day: Int | ||
let today: Bool | ||
let selected: Bool | ||
let appointments: Int | ||
|
||
init(day: Int, today: Bool, selected: Bool, appointments: Int) { | ||
self.day = day | ||
self.today = today | ||
self.selected = selected | ||
self.appointments = appointments | ||
} | ||
|
||
} | ||
|
||
extension DayViewModel: IGListDiffable { | ||
|
||
func diffIdentifier() -> NSObjectProtocol { | ||
return day as NSObjectProtocol | ||
} | ||
|
||
func isEqual(toDiffableObject object: IGListDiffable?) -> Bool { | ||
if self === object { return true } | ||
guard let object = object as? DayViewModel else { return false } | ||
return today == object.today && selected == object.selected && appointments == object.appointments | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
Examples/Examples-iOS/IGListKitExamples/Models/ViewModels/MonthTitleViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
Copyright (c) 2016-present, Facebook, Inc. All rights reserved. | ||
The examples provided by Facebook are for non-commercial testing and evaluation | ||
purposes only. Facebook reserves all rights not expressly granted. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import Foundation | ||
import IGListKit | ||
|
||
final class MonthTitleViewModel { | ||
|
||
let name: String | ||
|
||
init(name: String) { | ||
self.name = name | ||
} | ||
|
||
} | ||
|
||
extension MonthTitleViewModel: IGListDiffable { | ||
|
||
func diffIdentifier() -> NSObjectProtocol { | ||
return name as NSObjectProtocol | ||
} | ||
|
||
func isEqual(toDiffableObject object: IGListDiffable?) -> Bool { | ||
if self === object { return true } | ||
guard object is MonthTitleViewModel else { return false } | ||
// name is checked in the diffidentifier, so we can assume its equal | ||
return true | ||
} | ||
|
||
} |
Oops, something went wrong.