Skip to content

Commit

Permalink
Added object to single section selection delegate callback
Browse files Browse the repository at this point in the history
Summary:
- Updated selectionDelegate to pass through the model object
- Changelog entry under 3.0.0 as is breaking change

Try saying single section selection 10 times quick
Dabbing my left toe into some ObjC, so apologies if I violate years of rules

- [ ] Update documentation internally

Closes #396

- [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 #397

Differential Revision: D4406213

Pulled By: rnystrom

fbshipit-source-id: ba468fa49e75823796a47da6ed7f0e8957db3d75
  • Loading branch information
jessesquires authored and facebook-github-bot committed Jan 11, 2017
1 parent dd3b9ed commit 279f348
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
20 changes: 18 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@

The changelog for `IGListKit`. Also see the [releases](https://github.com/instagram/IGListKit/releases) on GitHub.

3.0.0 (**upcoming release**)
-----

This release closes the [3.0.0 milestone](https://github.com/Instagram/IGListKit/milestone/3).

### Breaking Changes

- Updated `didSelect` delegate call in `IGListSingleSectionControllerDelegate` to include object. [Sherlouk](https://github.com/Sherlouk) [(#397)](https://github.com/Instagram/IGListKit/pull/397)

```objc
// OLD
- (void)didSelectSingleSectionController:(IGListSingleSectionController *)sectionController;

// NEW
- (void)didSelectSectionController:(IGListSingleSectionController *)sectionController
withObject:(id)object;
```

2.2.0
-----

This release closes the [2.2.0 milestone](https://github.com/Instagram/IGListKit/milestone/4).

### Enhancements

### Fixes

- Fix bug where emptyView's hidden status is not updated after the number of items is changed with `insertInSectionController:atIndexes:` or related methods. [Peter Edmonston](https://github.com/edmonston) [(#395)](https://github.com/Instagram/IGListKit/pull/395)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ final class SingleSectionStoryboardViewController: UIViewController, IGListAdapt
return sectionController
}

func emptyView(for listAdapter: IGListAdapter) -> UIView? {
return nil
}
func emptyView(for listAdapter: IGListAdapter) -> UIView? { return nil }

// MARK: - IGListSingleSectionControllerDelegate

func didSelect(_ sectionController: IGListSingleSectionController) {
func didSelect(_ sectionController: IGListSingleSectionController, with object: Any) {
let section = adapter.section(for: sectionController) + 1
let alert = UIAlertController(title: "Section \(section) was selected \u{1F389}", message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Dismiss", style: .default, handler: nil))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ final class SingleSectionViewController: UIViewController, IGListAdapterDataSour

// MARK: - IGListSingleSectionControllerDelegate

func didSelect(_ sectionController: IGListSingleSectionController) {
func didSelect(_ sectionController: IGListSingleSectionController, with object: Any) {
let section = adapter.section(for: sectionController) + 1
let alert = UIAlertController(title: "Section \(section) was selected \u{1F389}", message: nil, preferredStyle: .alert)
let alert = UIAlertController(title: "Section \(section) was selected \u{1F389}",
message: "Cell Object: " + String(describing: object),
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Dismiss", style: .default, handler: nil))
present(alert, animated: true, completion: nil)
}
Expand Down
4 changes: 3 additions & 1 deletion Source/IGListSingleSectionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ typedef CGSize (^IGListSingleSectionCellSizeBlock)(id item, id<IGListCollectionC
Tells the delegate that the section controller was selected.
@param sectionController The section controller that was selected.
@param object The model for the given section.
*/
- (void)didSelectSingleSectionController:(IGListSingleSectionController *)sectionController;
- (void)didSelectSectionController:(IGListSingleSectionController *)sectionController
withObject:(id)object;

@end

Expand Down
2 changes: 1 addition & 1 deletion Source/IGListSingleSectionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ - (void)didUpdateToObject:(id)object {
}

- (void)didSelectItemAtIndex:(NSInteger)index {
[self.selectionDelegate didSelectSingleSectionController:self];
[self.selectionDelegate didSelectSectionController:self withObject:self.item];
}

@end
2 changes: 1 addition & 1 deletion Tests/IGListSingleSectionControllerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ - (void)test_whenSelected_thatDelegateReceivesEvent {
IGListSingleSectionController *section = [self.adapter sectionControllerForObject:self.dataSource.objects.firstObject];
id mockDelegate = [OCMockObject mockForProtocol:@protocol(IGListSingleSectionControllerDelegate)];
section.selectionDelegate = mockDelegate;
[[mockDelegate expect] didSelectSingleSectionController:section];
[[mockDelegate expect] didSelectSectionController:section withObject:self.dataSource.objects.firstObject];
[self.adapter collectionView:self.collectionView didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
[mockDelegate verify];
}
Expand Down

0 comments on commit 279f348

Please sign in to comment.