Skip to content

Commit

Permalink
Remove optional (#1186)
Browse files Browse the repository at this point in the history
Summary:
Issue fixed: #859

- [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)
Closes #1186

Differential Revision: D8264918

Pulled By: rnystrom

fbshipit-source-id: 9f32c085f305299efd839bb365a5d32109ff4f17
  • Loading branch information
bofeizhu authored and facebook-github-bot committed Jun 26, 2018
1 parent 749301c commit 6c64c54
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag

4.0.0 (upcoming release)
-----
### Breaking Changes

- All `IGListBindingSectionControllerSelectionDelegate` methods are now required. [Bofei Zhu] (https://github.com/zhubofei) [(#1186)](https://github.com/Instagram/IGListKit/pull/1186)

### Enhancements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,10 @@ final class MonthSectionController: ListBindingSectionController<ListDiffable>,
update(animated: true)
}

func sectionController(_ sectionController: ListBindingSectionController<ListDiffable>, didDeselectItemAt index: Int, viewModel: Any) {}

func sectionController(_ sectionController: ListBindingSectionController<ListDiffable>, didHighlightItemAt index: Int, viewModel: Any) {}

func sectionController(_ sectionController: ListBindingSectionController<ListDiffable>, didUnhighlightItemAt index: Int, viewModel: Any) {}

}
15 changes: 3 additions & 12 deletions Source/IGListBindingSectionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,15 @@ - (void)didSelectItemAtIndex:(NSInteger)index {
}

- (void)didDeselectItemAtIndex:(NSInteger)index {
id<IGListBindingSectionControllerSelectionDelegate> selectionDelegate = self.selectionDelegate;
if ([selectionDelegate respondsToSelector:@selector(sectionController:didDeselectItemAtIndex:viewModel:)]) {
[selectionDelegate sectionController:self didDeselectItemAtIndex:index viewModel:self.viewModels[index]];
}
[self.selectionDelegate sectionController:self didDeselectItemAtIndex:index viewModel:self.viewModels[index]];
}

- (void)didHighlightItemAtIndex:(NSInteger)index {
id<IGListBindingSectionControllerSelectionDelegate> selectionDelegate = self.selectionDelegate;
if ([selectionDelegate respondsToSelector:@selector(sectionController:didHighlightItemAtIndex:viewModel:)]) {
[selectionDelegate sectionController:self didHighlightItemAtIndex:index viewModel:self.viewModels[index]];
}
[self.selectionDelegate sectionController:self didHighlightItemAtIndex:index viewModel:self.viewModels[index]];
}

- (void)didUnhighlightItemAtIndex:(NSInteger)index {
id<IGListBindingSectionControllerSelectionDelegate> selectionDelegate = self.selectionDelegate;
if ([selectionDelegate respondsToSelector:@selector(sectionController:didUnhighlightItemAtIndex:viewModel:)]) {
[selectionDelegate sectionController:self didUnhighlightItemAtIndex:index viewModel:self.viewModels[index]];
}
[self.selectionDelegate sectionController:self didUnhighlightItemAtIndex:index viewModel:self.viewModels[index]];
}

@end
4 changes: 0 additions & 4 deletions Source/IGListBindingSectionControllerSelectionDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ NS_SWIFT_NAME(ListBindingSectionControllerSelectionDelegate)
didSelectItemAtIndex:(NSInteger)index
viewModel:(id)viewModel;

@optional

/**
Tells the delegate that a cell at a given index was deselected.
@param sectionController The section controller the deselection occurred in.
@param index The index of the deselected cell.
@param viewModel The view model that was bound to the cell.
@note Method is `@optional` until the 4.0.0 release where it will become required.
*/
- (void)sectionController:(IGListBindingSectionController *)sectionController
didDeselectItemAtIndex:(NSInteger)index
Expand Down
20 changes: 19 additions & 1 deletion Tests/Objects/IGTestBindingWithoutDeselectionDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,26 @@

@implementation IGTestBindingWithoutDeselectionDelegate

- (void)sectionController:(IGListBindingSectionController *)sectionController didSelectItemAtIndex:(NSInteger)index viewModel:(id)viewModel {
- (void)sectionController:(IGListBindingSectionController *)sectionController
didSelectItemAtIndex:(NSInteger)index
viewModel:(id)viewModel {
self.selected = YES;
}

- (void)sectionController:(IGListBindingSectionController *)sectionController
didDeselectItemAtIndex:(NSInteger)index
viewModel:(id)viewModel; {
}

- (void)sectionController:(nonnull IGListBindingSectionController *)sectionController
didHighlightItemAtIndex:(NSInteger)index
viewModel:(nonnull id)viewModel {
}


- (void)sectionController:(nonnull IGListBindingSectionController *)sectionController
didUnhighlightItemAtIndex:(NSInteger)index
viewModel:(nonnull id)viewModel {
}

@end

0 comments on commit 6c64c54

Please sign in to comment.