2017-03-15 14:44:52 +00:00
|
|
|
/**
|
|
|
|
|
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 IGListKit
|
2018-01-22 20:01:53 +00:00
|
|
|
import UIKit
|
2017-03-15 14:44:52 +00:00
|
|
|
|
Swift name annotations
Summary:
This adds `NS_SWIFT_NAME` annotations to all public API's to provide cleaner integration into Swift:
- Removes the need to prefix classes in Swift code, instead rely on Swift module name spacing
- Adds more argument labels to C function API's like `IGListDiff([], [], .equality)` => `ListDiff(oldArray: [], newArray: [], option: .equality)`
While this is a large API change it should be as easy as:
- Find and replace `(IGList)([^K])` to `List$2` in Xcode with a scope set to Swift
- Build and follow compiler's auto fix corrections for C API's or any missed renames
I have not updated the documentation to reflect this yet, I am totally willing to do so but before I sink that amount of time into it I wanted to see if the Instagram team is even open to this change!
- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
- [ ] I have updated the documentation
Closes https://github.com/Instagram/IGListKit/pull/593
Reviewed By: jessesquires
Differential Revision: D5028039
Pulled By: rnystrom
fbshipit-source-id: b473d874a1f9574e56b2ebaabd5b73d1b57d4bab
2017-05-09 21:29:52 +00:00
|
|
|
final class MonthSectionController: ListBindingSectionController<ListDiffable>, ListBindingSectionControllerDataSource, ListBindingSectionControllerSelectionDelegate {
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2017-04-11 20:20:56 +00:00
|
|
|
private var selectedDay: Int = -1
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2017-03-15 14:44:52 +00:00
|
|
|
override init() {
|
|
|
|
|
super.init()
|
|
|
|
|
dataSource = self
|
|
|
|
|
selectionDelegate = self
|
|
|
|
|
}
|
2017-05-16 14:30:08 +00:00
|
|
|
|
Swift name annotations
Summary:
This adds `NS_SWIFT_NAME` annotations to all public API's to provide cleaner integration into Swift:
- Removes the need to prefix classes in Swift code, instead rely on Swift module name spacing
- Adds more argument labels to C function API's like `IGListDiff([], [], .equality)` => `ListDiff(oldArray: [], newArray: [], option: .equality)`
While this is a large API change it should be as easy as:
- Find and replace `(IGList)([^K])` to `List$2` in Xcode with a scope set to Swift
- Build and follow compiler's auto fix corrections for C API's or any missed renames
I have not updated the documentation to reflect this yet, I am totally willing to do so but before I sink that amount of time into it I wanted to see if the Instagram team is even open to this change!
- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
- [ ] I have updated the documentation
Closes https://github.com/Instagram/IGListKit/pull/593
Reviewed By: jessesquires
Differential Revision: D5028039
Pulled By: rnystrom
fbshipit-source-id: b473d874a1f9574e56b2ebaabd5b73d1b57d4bab
2017-05-09 21:29:52 +00:00
|
|
|
// MARK: ListBindingSectionControllerDataSource
|
2017-05-16 14:30:08 +00:00
|
|
|
|
Swift name annotations
Summary:
This adds `NS_SWIFT_NAME` annotations to all public API's to provide cleaner integration into Swift:
- Removes the need to prefix classes in Swift code, instead rely on Swift module name spacing
- Adds more argument labels to C function API's like `IGListDiff([], [], .equality)` => `ListDiff(oldArray: [], newArray: [], option: .equality)`
While this is a large API change it should be as easy as:
- Find and replace `(IGList)([^K])` to `List$2` in Xcode with a scope set to Swift
- Build and follow compiler's auto fix corrections for C API's or any missed renames
I have not updated the documentation to reflect this yet, I am totally willing to do so but before I sink that amount of time into it I wanted to see if the Instagram team is even open to this change!
- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
- [ ] I have updated the documentation
Closes https://github.com/Instagram/IGListKit/pull/593
Reviewed By: jessesquires
Differential Revision: D5028039
Pulled By: rnystrom
fbshipit-source-id: b473d874a1f9574e56b2ebaabd5b73d1b57d4bab
2017-05-09 21:29:52 +00:00
|
|
|
func sectionController(_ sectionController: ListBindingSectionController<ListDiffable>, viewModelsFor object: Any) -> [ListDiffable] {
|
2017-03-15 14:44:52 +00:00
|
|
|
guard let month = object as? Month else { return [] }
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2017-03-15 14:44:52 +00:00
|
|
|
let date = Date()
|
|
|
|
|
let today = Calendar.current.component(.day, from: date)
|
2017-05-16 14:30:08 +00:00
|
|
|
|
Swift name annotations
Summary:
This adds `NS_SWIFT_NAME` annotations to all public API's to provide cleaner integration into Swift:
- Removes the need to prefix classes in Swift code, instead rely on Swift module name spacing
- Adds more argument labels to C function API's like `IGListDiff([], [], .equality)` => `ListDiff(oldArray: [], newArray: [], option: .equality)`
While this is a large API change it should be as easy as:
- Find and replace `(IGList)([^K])` to `List$2` in Xcode with a scope set to Swift
- Build and follow compiler's auto fix corrections for C API's or any missed renames
I have not updated the documentation to reflect this yet, I am totally willing to do so but before I sink that amount of time into it I wanted to see if the Instagram team is even open to this change!
- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
- [ ] I have updated the documentation
Closes https://github.com/Instagram/IGListKit/pull/593
Reviewed By: jessesquires
Differential Revision: D5028039
Pulled By: rnystrom
fbshipit-source-id: b473d874a1f9574e56b2ebaabd5b73d1b57d4bab
2017-05-09 21:29:52 +00:00
|
|
|
var viewModels = [ListDiffable]()
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2017-03-15 14:44:52 +00:00
|
|
|
viewModels.append(MonthTitleViewModel(name: month.name))
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2017-03-15 14:44:52 +00:00
|
|
|
for day in 1..<(month.days + 1) {
|
|
|
|
|
let viewModel = DayViewModel(
|
|
|
|
|
day: day,
|
|
|
|
|
today: day == today,
|
|
|
|
|
selected: day == selectedDay,
|
|
|
|
|
appointments: month.appointments[day]?.count ?? 0
|
|
|
|
|
)
|
|
|
|
|
viewModels.append(viewModel)
|
|
|
|
|
}
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2017-03-15 14:44:52 +00:00
|
|
|
for appointment in month.appointments[selectedDay] ?? [] {
|
|
|
|
|
viewModels.append(appointment)
|
|
|
|
|
}
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2017-03-15 14:44:52 +00:00
|
|
|
return viewModels
|
|
|
|
|
}
|
2017-05-16 14:30:08 +00:00
|
|
|
|
|
|
|
|
func sectionController(_ sectionController: ListBindingSectionController<ListDiffable>,
|
|
|
|
|
cellForViewModel viewModel: Any,
|
2017-09-22 13:34:52 +00:00
|
|
|
at index: Int) -> UICollectionViewCell & ListBindable {
|
2017-03-15 14:44:52 +00:00
|
|
|
let cellClass: AnyClass
|
|
|
|
|
if viewModel is DayViewModel {
|
|
|
|
|
cellClass = CalendarDayCell.self
|
|
|
|
|
} else if viewModel is MonthTitleViewModel {
|
|
|
|
|
cellClass = MonthTitleCell.self
|
|
|
|
|
} else {
|
|
|
|
|
cellClass = LabelCell.self
|
|
|
|
|
}
|
2018-01-22 20:01:53 +00:00
|
|
|
guard let cell = collectionContext?.dequeueReusableCell(of: cellClass, for: self, at: index) as? UICollectionViewCell & ListBindable
|
2017-09-22 13:34:52 +00:00
|
|
|
else { fatalError() }
|
|
|
|
|
return cell
|
2017-03-15 14:44:52 +00:00
|
|
|
}
|
2017-05-16 14:30:08 +00:00
|
|
|
|
|
|
|
|
func sectionController(_ sectionController: ListBindingSectionController<ListDiffable>,
|
|
|
|
|
sizeForViewModel viewModel: Any,
|
|
|
|
|
at index: Int) -> CGSize {
|
2017-03-15 14:44:52 +00:00
|
|
|
guard let width = collectionContext?.containerSize.width else { return .zero }
|
|
|
|
|
if viewModel is DayViewModel {
|
|
|
|
|
let square = width / 7.0
|
|
|
|
|
return CGSize(width: square, height: square)
|
|
|
|
|
} else if viewModel is MonthTitleViewModel {
|
|
|
|
|
return CGSize(width: width, height: 30.0)
|
|
|
|
|
} else {
|
|
|
|
|
return CGSize(width: width, height: 55.0)
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-16 14:30:08 +00:00
|
|
|
|
Swift name annotations
Summary:
This adds `NS_SWIFT_NAME` annotations to all public API's to provide cleaner integration into Swift:
- Removes the need to prefix classes in Swift code, instead rely on Swift module name spacing
- Adds more argument labels to C function API's like `IGListDiff([], [], .equality)` => `ListDiff(oldArray: [], newArray: [], option: .equality)`
While this is a large API change it should be as easy as:
- Find and replace `(IGList)([^K])` to `List$2` in Xcode with a scope set to Swift
- Build and follow compiler's auto fix corrections for C API's or any missed renames
I have not updated the documentation to reflect this yet, I am totally willing to do so but before I sink that amount of time into it I wanted to see if the Instagram team is even open to this change!
- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
- [ ] I have updated the documentation
Closes https://github.com/Instagram/IGListKit/pull/593
Reviewed By: jessesquires
Differential Revision: D5028039
Pulled By: rnystrom
fbshipit-source-id: b473d874a1f9574e56b2ebaabd5b73d1b57d4bab
2017-05-09 21:29:52 +00:00
|
|
|
// MARK: ListBindingSectionControllerSelectionDelegate
|
2017-05-16 14:30:08 +00:00
|
|
|
|
Swift name annotations
Summary:
This adds `NS_SWIFT_NAME` annotations to all public API's to provide cleaner integration into Swift:
- Removes the need to prefix classes in Swift code, instead rely on Swift module name spacing
- Adds more argument labels to C function API's like `IGListDiff([], [], .equality)` => `ListDiff(oldArray: [], newArray: [], option: .equality)`
While this is a large API change it should be as easy as:
- Find and replace `(IGList)([^K])` to `List$2` in Xcode with a scope set to Swift
- Build and follow compiler's auto fix corrections for C API's or any missed renames
I have not updated the documentation to reflect this yet, I am totally willing to do so but before I sink that amount of time into it I wanted to see if the Instagram team is even open to this change!
- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
- [ ] I have updated the documentation
Closes https://github.com/Instagram/IGListKit/pull/593
Reviewed By: jessesquires
Differential Revision: D5028039
Pulled By: rnystrom
fbshipit-source-id: b473d874a1f9574e56b2ebaabd5b73d1b57d4bab
2017-05-09 21:29:52 +00:00
|
|
|
func sectionController(_ sectionController: ListBindingSectionController<ListDiffable>, didSelectItemAt index: Int, viewModel: Any) {
|
2017-03-15 14:44:52 +00:00
|
|
|
guard let dayViewModel = viewModel as? DayViewModel else { return }
|
|
|
|
|
if dayViewModel.day == selectedDay {
|
|
|
|
|
selectedDay = -1
|
|
|
|
|
} else {
|
|
|
|
|
selectedDay = dayViewModel.day
|
|
|
|
|
}
|
|
|
|
|
update(animated: true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|