97 Commits

Author SHA1 Message Date
Ryan Nystrom
0a416914d5 Rename sectionIndex API to just section
Summary:
Quick rename before releasing 3.0 to get this API in parity w/ `isFirstSection` and `isLastSection`. My b I should have caught this in review.

Closes #720

Reviewed By: jessesquires, amonshiz

Differential Revision: D5031184

fbshipit-source-id: 1cd7b00c8b32084fecd861e78808eea0d0056337
2017-05-11 14:49:59 -07:00
Andrew Monshizadeh
1d140e441a Reset all section controllers when a list adapter is deallocated
Summary:
This change will ensure that section controllers have the following properties reset to sensible default values when their owning list adapter is deallocated.

```
isFirstSection = NO
isLastSection = NO
sectionIndex = NSNotFound
```

Issue fixed: #709

- [X] All tests pass. Demo project builds and runs.
- [X] I added tests, an experiment, or detailed why my change isn't tested. (Existing test is updated to ensure this doesn't regress)
- [ ] 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 https://github.com/Instagram/IGListKit/pull/723

Reviewed By: rnystrom

Differential Revision: D5032445

Pulled By: jessesquires

fbshipit-source-id: 446a30f4206ce02d3ad89fcd9b4586587f396f58
2017-05-10 10:02:55 -07:00
Robert Payne
40625f8ff9 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 14:31:28 -07:00
Ryan Nystrom
a4dfe9676e Fix reusing collection views among multiple adapters
Summary:
When multiple `UICollectionView`s are reused among multiple `IGListAdapter`s (horizontal lists embedded in a bigger, vertical list), the mapping between the old view and adapter is not broken. When a new collection view is attached to the old adapter, an unrelated adapter->collection view reference will be erroneously broken.

The unit test in this diff fails on the second `XCTAssertEqual(adapter2.collectionView, collectionView1);` without this patch.

Issue fixed: #699

t15661237 internally

cc amonshiz since we were talking about this

- [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.
Closes https://github.com/Instagram/IGListKit/pull/721

Reviewed By: amonshiz

Differential Revision: D5026330

Pulled By: rnystrom

fbshipit-source-id: b2164a4ab39802f7fba870ceab6692b7b501b5c2
2017-05-09 08:08:46 -07:00
Andrew Monshizadeh
a4e5ad862e Move section index to property
Summary:
This pull request removes the `sectionForSectionController:` method from the `IGListCollectionContext` protocol so that the protocol is exclusively for presentation methods.

This should not add new functionality, but rather makes the index directly accessible on the section controllers themselves. This change makes sense because at no time will there be an update to the list that the list adapter is unaware of and so it will always be able to set and update any indexes for a section controller that has changed.

Issue fixed: #609

- [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 https://github.com/Instagram/IGListKit/pull/671

Reviewed By: jessesquires

Differential Revision: D4942159

Pulled By: amonshiz

fbshipit-source-id: d648cfdd381cbf1d9ee7ff549ae27d2972a84622
2017-05-01 07:28:27 -07:00
Ryan Nystrom
ee4f3c95c6 Balance reload delete and insert calls
Summary:
In 073fc073e0 we deduped delete calls, but since we convert reloads into delete+insert when only deduping deletes, we end up with unbalanced delete+insert calls.

Unit test added reproduced a crash we see internally. Fix passes the test.

Not adding a changelog entry since this is a new regression fixed between releases. #trivial

Issue fixed: t17539856

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
Closes https://github.com/Instagram/IGListKit/pull/687

Differential Revision: D4933545

Pulled By: rnystrom

fbshipit-source-id: d38a900a99b1aa796dd654ddedb42e3cb4ef4378
2017-04-22 12:15:59 -07:00
Ryan Nystrom
5fe27d8809 Add debug dump scripts
Summary:
Got a little time on the plane to mess around with this idea. Very much want comments on this! Some questions:

- We should probably compile out parts of this using `#if DEBUG`.
  - Should I compile out all of the description methods?
  - Maybe I wrap the entire debug files w/ `#if DEBUG ... #endif` so none of it is loaded?
- ryanolsonk I used [FLEX](https://github.com/Flipboard/FLEX/blob/master/Classes/Utility/FLEXHeapEnumerator.m) for searching the heap, lmk if you see any problems w/ this
  - Its lifted w/ only a few changes for my specific needs (including comments 😂)
  - Chalk us up for using [another bit](https://github.com/Instagram/IGListKit/blob/master/Source/Internal/IGListAdapterProxy.m#L77-L82) of your code
- Added a basic test so that the basics of this work and coverage doesn't tank
  - Anything else I should test?
- Is there more data we should be dumping?
- I have to track batch update state on the updater in order to dump it. If this seems dan
Closes https://github.com/Instagram/IGListKit/pull/617

Reviewed By: jessesquires

Differential Revision: D4929426

Pulled By: rnystrom

fbshipit-source-id: fcba0d6f0b7766485440f208cf70ad39dfc7a42e
2017-04-21 16:46:06 -07:00
Bas Broek
ea5a4cc00f Init without working range size
Summary:
Issue fixed: #414

- [x] All tests pass. Demo project builds and runs.
- [ ] 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)

What should we do with testing? I changed all the occurrences of the old initializer with the new one, so I think this is good to go?
Closes https://github.com/Instagram/IGListKit/pull/686

Differential Revision: D4931986

Pulled By: jessesquires

fbshipit-source-id: d6f0ac6578c11f8ef37ec0e385bc110e3abd7c91
2017-04-21 14:30:46 -07:00
Artem Goncharov
e729ab8211 Fixed empty space bug in CollectionView
Summary:
Fixed situation when cells with small height don't intersect with the _Rect_ and stop the enumeration that cause empty spaces in _collectionView_.

Issue fixed: # [680](https://github.com/Instagram/IGListKit/issues/680)

- [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 https://github.com/Instagram/IGListKit/pull/684

Differential Revision: D4929315

Pulled By: rnystrom

fbshipit-source-id: 4437df21772697a9a6421d213f4fed7b8470371b
2017-04-21 08:20:16 -07:00
Ryan Nystrom
fdbe025fe1 Add base test case class for simpler unit testing
Summary:
Making it simpler to setup tests w/ default config and objects. Less LoC in tests, lower setup cost when creating new test suites.

Should I changelog?

Issue fixed: #183

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
Closes https://github.com/Instagram/IGListKit/pull/678

Differential Revision: D4921633

Pulled By: rnystrom

fbshipit-source-id: fb4d08acb6ed0ba885cf56ce147f70b304301ff1
2017-04-20 14:36:28 -07:00
Ryan Nystrom
073fc073e0 Prevent duplicate item deletes and drop reload collisions
Summary:
a415ef5552 exposed a bug in `UICollectionView` where its state gets corrupted when deleting the same index path more than once in a single batch update block. This resulted crashes like

```
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x4)
Closes https://github.com/Instagram/IGListKit/pull/657

Reviewed By: jessesquires

Differential Revision: D4913790

Pulled By: rnystrom

fbshipit-source-id: 8f6fcdd2e2438da309fc64ca0ac111b9a0980149
2017-04-19 17:17:41 -07:00
heshamsalman
04e6c1bff1 Increased timeout time, close #669
Summary:
Simple find and replace for `waitForExpectationsWithTimeout:15` and `waitForExpectationsWithTimeout:16`

Issue fixed: #669

- [ ] All tests pass. Demo project builds and runs.
- [ ] I added tests, an experiment, or detailed why my change isn't tested.
- [ ] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [ ] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
Closes https://github.com/Instagram/IGListKit/pull/670

Differential Revision: D4915711

Pulled By: rnystrom

fbshipit-source-id: 7afd990cd5d18844ec1da08c5335f7138feb0b87
2017-04-19 13:00:47 -07:00
Ryan Nystrom
301f1471c9 Add generic type section controller
Summary: Adding and implementing an example of a new section controller that can be configured with a type. This section controller automatically stores its object in `didUpdateToObject:`, and implementations can trust the type-safety of the object!

Reviewed By: jessesquires

Differential Revision: D4914179

fbshipit-source-id: 39e2dce8ca29a1c0c92dc78eb8c25a7ab0a21978
2017-04-19 12:45:36 -07:00
Ryan Nystrom
3102852ce2 Remove IGListSectionType
Summary:
Removing the `IGListSectionType` protocol and adding default implementations into `IGListSectionController`.

- `numberOfItems` returns 1
- `cellForItemAtIndex:` asserts (have to return a cell)
- `didUpdateToObject:` no-ops
- `didSelectItemAtIndex:` no-ops

Fixes #168

Reviewed By: jessesquires

Differential Revision: D4909585

fbshipit-source-id: 8816702504e3fc0683868914ff4dd20e4af7c166
2017-04-19 08:26:30 -07:00
Ryan Nystrom
4441bd84cc Fix crash when requesting OOB layout attributes
Summary: There's a small crash showing up when requesting an index path that doesn't exist. It's totally valid that this could be requested from a product and not the infra. Should fail gracefully.

Differential Revision: D4911349

fbshipit-source-id: eee8891cf9400b3c3cd5539e839296f393f82354
2017-04-19 08:26:30 -07:00
Jesse Squires
a415ef5552 Prevent a crash when inserting the same index twice, re-open of #616
Summary:
Original comment:

If you insert or delete into the same index twice **and** update your data source to reflect those changes, we will squash the insert/delete into a single update because we're using `NSSet` internally.

This becomes very apparent when multiple updates are coalesced.

Issue fixed: #483

- [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.
Closes https://github.com/Instagram/IGListKit/pull/634

Differential Revision: D4860479

Pulled By: jessesquires

fbshipit-source-id: 3aa271d90fca21b11201f62cefa8d7fbcef6930f
2017-04-11 15:02:13 -07:00
PhilCai
7c81d0bd3d fix a test mistake in IGListDisplayHandlerTests
Summary:
Issue fixed: #

- [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 https://github.com/Instagram/IGListKit/pull/605

Differential Revision: D4817720

Pulled By: rnystrom

fbshipit-source-id: a6d2cda39ede7bf4b44c2fefe6675339f467f2ae
2017-04-02 13:37:40 -07:00
Jesse Squires
2284ce3897 kill IGListCollectionView. GH issue #409 (redo of D4640425)
Summary:
Take 2. Remove `IGListCollectionView` per #409. Use plain old `UICollectionView`.
(This re-applies D4640425 and updates as needed.)

Also:
- run `pod update` everywhere
- update changelog

Reviewed By: paulvanderspek

Differential Revision: D4812207

fbshipit-source-id: 1ddbae06cdeddb43d8af175d3e8a045a36ff150e
2017-03-31 14:54:09 -07:00
Ryan Nystrom
623ff2a8a8 Container size doesnt use content inset, add new APIs
Summary:
The content inset of a collection view can change at any time (as it does with our refresh control) and isn't a good measure of the container size. I don't want to totally remove that API though, so I changed the default behavior, added an insets API, and also added the functionality of the original in a new API.

This makes sizes much more deterministic.

Reviewed By: jessesquires

Differential Revision: D4800758

fbshipit-source-id: 85ce843b5b1c297cea2e2ea705fa255617cbe356
2017-03-30 09:35:03 -07:00
Ryan Nystrom
4e9b0bb4c4 Prevent negative spaces for items and supplementaries
Summary:
If a negative height/width comes down, cap it to `0.0`.

Issue fixed: #566

Also fixes t16455632 internally.

- [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.
Closes https://github.com/Instagram/IGListKit/pull/583

Differential Revision: D4797520

Pulled By: jessesquires

fbshipit-source-id: 3eeec5244a445bb451460286b4f006ca0d9c67d1
2017-03-29 15:01:08 -07:00
Ryan Nystrom
5eca718ea7 Drop section moves if they are also deleted or inserted
Summary:
Issue fixed: #430

- [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.
Closes https://github.com/Instagram/IGListKit/pull/577

Differential Revision: D4768612

Pulled By: rnystrom

fbshipit-source-id: 6a2024101411302446cc2b7843fa175cd43a1562
2017-03-23 22:31:38 -07:00
Ryan Nystrom
a15ea08614 Move section controller mutation API to object provided in update block
Summary:
We constantly have random bugs pop up when mutations are made outside of a batch update. This change restricts the mutation API to a batch context object (which is just an `IGListAdapter`) so they can only be done **inside an update block**.

- Fixed open source project
- Confirmed open source examples build
- Updated all of Instagram.app to use this API
- Changelog breaking changes entry

Fixes #392

Reviewed By: jessesquires

Differential Revision: D4754129

fbshipit-source-id: 11d32a0fac3e50c9edbb01e92a8a0c7b8a43cf2d
2017-03-22 12:46:49 -07:00
Shiyi Zhao
24308a9881 handle float number fraction part for layout.
Summary:
[IGListCollectionViewLayout]: handle float number fraction part for layout.
When width of item is a float number with non-zero fraction part.
After integer scaled, it might add up smaller or bigger than maxWidth.
Ex with 6 items with 13 padding on each side
1. iPhone 7, maxWidth = 349, scaledItemWidth = 58 -> 58 * 6 = 348, which is smaller than 349
-> this can cause issue where is extra one line at end
2. iPone 7 plus, maxWidth = 388, scaledItemWidth = 64.6667 -> 64.6667 * 6 = 388.0002, which is bigger than 388
-> this can cause issue where last item is mistakenly shifted to next row

To fix it, add epsilon = 1 to allow some error range
Also add stretchToEdge BOOL flag to handle case 1 to decide whether to strech the width of last item.

Reviewed By: ryanolsonk, jessesquires

Differential Revision: D4720156

fbshipit-source-id: 765f6b13b7d601394d65788c30ae69ac1b37c3f2
2017-03-17 12:33:34 -07:00
Shiyi Zhao
a80245a696 add integer pixel scaled for frame
Summary: [IGListCollectionViewLayout]: add integer pixel scaled for frame

Reviewed By: jessesquires

Differential Revision: D4727500

fbshipit-source-id: dccabe9152fdec4a9bee2b92d9a7897552a0fecb
2017-03-17 12:33:34 -07:00
Bofei Zhu
f7702fa713 Container Inset Size For Section Controller
Summary:
Add API for #315. Not sure if this is what you want rnystrom though 🤔. Will add tests after you confirm.

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [ ] 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 https://github.com/Instagram/IGListKit/pull/456

Reviewed By: jessesquires

Differential Revision: D4697190

Pulled By: rnystrom

fbshipit-source-id: f8513cf2fa33441eb40f486954136553d19dda0c
2017-03-15 09:25:40 -07:00
Ryan Nystrom
79348164a7 Auto diffing section controller
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 https://github.com/Instagram/IGListKit/pull/494

Reviewed By: amonshiz

Differential Revision: D4696966

Pulled By: rnystrom

fbshipit-source-id: f21b8341b3ed4389f2a4a106d0d316f481ba6943
2017-03-15 07:47:24 -07:00
Shiyi Zhao
7f652e2c17 fix a bug which caused double inset being applied when having non-zero left contentInset.
Summary: [IGListCollectionViewLayout]: fix a bug which caused double inset being applied when having non-zero left contentInset.

Reviewed By: jessesquires

Differential Revision: D4692870

fbshipit-source-id: 1a1a3ccf944a83fea3a706b83f54293346b35c5a
2017-03-10 19:00:41 -08:00
Ryan Nystrom
3f9dea21e0 Track batch updates in object and explicit state
Summary:
Batch updates are complicated b/c its unknown when the update block will actually execute. When executing the block, we want to collect inserts/deletes/reloads/moves (item and section). Allow mutations to happen synchronously outside of the update block.

Tracking state will also help with the auto-diff where we need to allow re-entrant updates.

Peeling off a chunk from #494

Issue fixed: #288

- [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.
Closes https://github.com/Instagram/IGListKit/pull/525

Reviewed By: jessesquires

Differential Revision: D4656463

Pulled By: rnystrom

fbshipit-source-id: 8f4d3dc21b03d595e02ee9ee9664277e8ead0531
2017-03-07 09:33:03 -08:00
Leyla Hujer
68a264d29c Revert D4640425: [IGListKit] kill IGListCollectionView. GH issue #409
Summary: This reverts commit 871b75eaeb1c9f2a40fe8f3fd81b209661704587

Differential Revision: D4640425

fbshipit-source-id: 4b0e8a9820891062cf7f8d13de13d678adb5df4a
2017-03-06 16:15:31 -08:00
Jesse Squires
3fb2ac0d60 kill IGListCollectionView. GH issue #409
Summary: Remove `IGListCollectionView` per #409. Use plain old `UICollectionView`.

Reviewed By: rnystrom

Differential Revision: D4640425

fbshipit-source-id: 871b75eaeb1c9f2a40fe8f3fd81b209661704587
2017-03-06 15:01:01 -08:00
Ryan Nystrom
2e996e283e Test and fix layout fitting width and inset sections with newline
Summary:
Fixes internally reported issue where the layout was new lining a section that had proper width math. Also, when inset sections were all on the same line, the max height added inset for each section, causing the newline to be too low.

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
Closes https://github.com/Instagram/IGListKit/pull/522

Reviewed By: jessesquires

Differential Revision: D4655554

Pulled By: rnystrom

fbshipit-source-id: 5e759451e285ccd636ed59dcee0777ce590797ad
2017-03-04 16:15:51 -08:00
Alex Mathers
2a0b4c990a Add IGListCollectionContext API to get visible indexes.
Summary:
Add IGListCollectionContext API to get visible indexes:
`- (NSArray<NSIndexPath *> *)visiblePathsForSectionController:(IGListSectionController<IGListSectionType> *) sectionController`

Issue fixed: #465

- [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 https://github.com/Instagram/IGListKit/pull/507

Differential Revision: D4621418

Pulled By: jessesquires

fbshipit-source-id: 4b55500c83ca1b911c418e5857756bb076fc80e4
2017-02-28 14:32:06 -08:00
Ryan Nystrom
f639cdd287 Prevent stale adapter:collectionView corruptions
Summary:
This becomes an issue pretty easily in embedded `IGListAdapter` environments (lists in lists). IGListKit creates a single `IGListSectionController` instance per object, but cells are reused within `IGListCollectionView`. If you assign `adapter.collectionView = cell.collectionView` (like we recommend in our [example](https://github.com/Instagram/IGListKit/blob/master/Examples/Examples-iOS/IGListKitExamples/SectionControllers/HorizontalSectionController.swift#L40)), then you can have many adapters with a weak ref to the **same collection view**.

Obviously when updates happen across all embedded lists, adapters could potentially update the same collection view and apply a corrupted batch update.

I proposed using `<objc/runtime.h>` and using associated objects, but since `OBJC_ASSOCIATION_ASSIGN` is not zerod-on-release reference (its just `unsafe_unretained`) I'd have to make a weak wrapped object, which is overkill.

Instead I think a global weak:weak map is fine. We d
Closes https://github.com/Instagram/IGListKit/pull/517

Differential Revision: D4623300

Pulled By: rnystrom

fbshipit-source-id: 53d2dd158923c431e793b0c8e28997e9bbf55b8b
2017-02-28 07:32:10 -08:00
Ryan Nystrom
6bdcac81d8 Layout invalidation API
Summary:
Adding a new layout-invalidation API, telling the layout object to query and rebuild the layout for all items in the section controller. This works with `UICollectionViewFlowLayout` and should work with other custom layouts (including our own).

Issue fixed: #360, #459

- [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.
Closes https://github.com/Instagram/IGListKit/pull/499

Reviewed By: jessesquires

Differential Revision: D4590274

Pulled By: rnystrom

fbshipit-source-id: f87235be4e6c024bf979b831a8938be68895e011
2017-02-21 15:30:56 -08:00
Vincent Peng
2adea72158 Rename "withCollectionView:" param to "collectionView:"
Summary:
- Rename "withCollectionView:" param to "collectionView:" param to be consistent with the rest
of the protocol.
- Update tests.

Related issue: #466

- [x] All tests pass. Demo project builds and runs.
- [ ] 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 https://github.com/Instagram/IGListKit/pull/491

Differential Revision: D4589976

Pulled By: rnystrom

fbshipit-source-id: 5e5aa7328a6bbac6baa705d5228f0eb4321d8c31
2017-02-21 09:15:45 -08:00
Ryan Nystrom
9c37fbf8a4 Handle nil section controllers from data source
Summary:
Removing the assert and handling `nil` section controllers. This wont effect Swift code which demands a non-optional section controller, but Objective-C is more nuanced. There is evidence that some callers do not have a default state and are returning `nil`.

Unfortunately this will [OOB here](https://github.com/Instagram/IGListKit/blob/master/Source/Internal/IGListSectionMap.m#L63) if using the original `objects` array provided by the data source. Instead we prune the array, only allowing in objects that have a matching section controller.

Fixes t15773862 internally.

- [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.
Closes https://github.com/Instagram/IGListKit/pull/488

Reviewed By: dshahidehpour

Differential Revision: D4553886

Pulled By: rnystrom

fbshipit-source-id: a473a99b5eb513e4b610019dba0394a014193fc4
2017-02-14 08:01:47 -08:00
Ryan Nystrom
a5a08d2e11 Remove IGListGridCollectionViewLayout
Summary:
Follow from #450, this layout has been replaced. You served us well!

- [x] All tests pass. Demo project builds and runs.
- [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
Closes https://github.com/Instagram/IGListKit/pull/482

Differential Revision: D4553897

Pulled By: rnystrom

fbshipit-source-id: caccb386ba8914fbbf5e81d997524efb78c6e4ea
2017-02-13 14:30:58 -08:00
Ryan Nystrom
4eddd4a191 Consider supplementary views when sending display events
Summary:
This was a little bit of an invasive change with the display handler, but I think that this is the right call. When sending display events for objects, we should account for the supplementary view as part of the section controller. This is especially useful for headers and footers.

Note that this wont effect the working range API at all.

Fixes #300
Closes https://github.com/Instagram/IGListKit/pull/470

Differential Revision: D4551338

Pulled By: rnystrom

fbshipit-source-id: dda6fbf18bcfc2c941d80ee2314a543d1ab83843
2017-02-13 07:01:13 -08:00
Dustin Shahidehpour
fef72e579e Backed out changeset b72b444c1197
Summary: This diff isn't correct, and the Instagram cut happens today. Pulling back so I have time to test the correct change more throughly.

Reviewed By: rnystrom

Differential Revision: D4550149

fbshipit-source-id: 2e882caeb9ef999b7fd57562740b352ea8edfa5f
2017-02-12 14:30:39 -08:00
Ryan Nystrom
e2c2d3dcec Vertical UICollectionViewLayout supporting inline sections (take 2)
Summary:
Working on porting our collection view layout to IGListKit. I'm doing this because its a solid layout, and we just finished preparing it to work with inline sections. It is designed to work in tandem with IGListKit, so we're adding it.

This is still a WIP as I add more tests, but I'd love as much feedback as possible.

Aside from the glob of header documentation, this has the following features:

- Infinite sections that each have infinite items. Sections and items can fall inline. When they break the width of their container they will fall on the next row.
- Sections can have their own insets, line spacing, and interitem spacing.
- Sticky header support! When you use headers, it will always newline the section.
- Maximum width with a border decoration view
  - Use this to pinch in your content on larger devices

Followup to #423

- [ ] ~~Move decoration view support to delegate~~ removed
- [x] Unit test changing [top y sticky inset](https://coveralls.io/builds/9977284/source?filen
Closes https://github.com/Instagram/IGListKit/pull/484

Differential Revision: D4547760

Pulled By: rnystrom

fbshipit-source-id: 879e2da16eb78bb6a90967e77d9ad0bbf7c69594
2017-02-10 18:01:22 -08:00
Ryan Nystrom
4dec244416 Add item-level moves to IGListCollectionContext
Summary:
Adding an API to do item-level (cell) moves on the collection view. This complicates things a little bit because of all the issues that moving sections have while in batch updates (e.g. simultaneous animation UICV bugs). Thankfully we use pretty strict types so the compiler does most of the work for us.

Closes #145

- [x] Tests build and pass
- [x] Add `IGListBatchUpdateData` tests to check moves during
  - [x] ~~Moving within a reloaded section (no op)~~ can't reload sections
  - [x] Moving within a deleted section (no op)
  - [x] Moving within a moved section (convert section ops to delete+insert)
  - [x] Moving an index path that is also reloaded (convert to delete+insert path)
- [x] Add move unit tests to `IGListAdapterUpdater`
- [x] Add move unit tests to `IGListReloadDataUpdater` (mostly for code coverage...)
- [x] Add move unit tests to `IGListStackedSectionController`
- [x] Add `CHANGELOG.md` entry for 3.0.0
- [x] Test moving without batch
Closes https://github.com/Instagram/IGListKit/pull/418

Reviewed By: jessesquires

Differential Revision: D4521732

Pulled By: rnystrom

fbshipit-source-id: 99a46d1cbb0cc1f857a62ff6ca257aff6e8b7f25
2017-02-10 18:01:18 -08:00
Ryan Nystrom
80ad941369 Revert D4521797: [IGListKit][PR] Vertical UICollectionViewLayout supporting inline sections
Summary: This reverts commit 20b36ae573d38ca3125a6f3d5faec181c290ab94

Differential Revision: D4521797

fbshipit-source-id: 447de6cf2b30de9c2109dffb266326aceceec7fc
2017-02-10 11:33:07 -08:00
Ryan Nystrom
727833409f Vertical UICollectionViewLayout supporting inline sections
Summary:
Working on porting our collection view layout to IGListKit. I'm doing this because its a solid layout, and we just finished preparing it to work with inline sections. It is designed to work in tandem with IGListKit, so we're adding it.

This is still a WIP as I add more tests, but I'd love as much feedback as possible.

Aside from the glob of header documentation, this has the following features:

- Infinite sections that each have infinite items. Sections and items can fall inline. When they break the width of their container they will fall on the next row.
- Sections can have their own insets, line spacing, and interitem spacing.
- Sticky header support! When you use headers, it will always newline the section.
- Maximum width with a border decoration view
  - Use this to pinch in your content on larger devices

Followup to #423

- [ ] ~~Move decoration view support to delegate~~ removed
- [x] Unit test changing [top y sticky inset](https://coveralls.io/builds/9977284/source?filen
Closes https://github.com/Instagram/IGListKit/pull/450

Reviewed By: jessesquires

Differential Revision: D4521797

Pulled By: rnystrom

fbshipit-source-id: 20b36ae573d38ca3125a6f3d5faec181c290ab94
2017-02-10 08:30:33 -08:00
Adlai Holler
106054c181 Add -[IGListAdapter sectionControllerForSection:]
Summary:
Before the diff, you can lookup the object for a given section, and then lookup the section controller for that object, but this seems like a pretty valuable/common operation.
Closes https://github.com/Instagram/IGListKit/pull/477

Differential Revision: D4537479

Pulled By: rnystrom

fbshipit-source-id: ad47a243f0bb0fc72a362863dff2f00b0b640fab
2017-02-09 11:31:17 -08:00
Dustin Shahidehpour
fce3286ae4 Decouple Empty View from backgroundView, make it move with PTR
Summary:
1. The "Empty View" and CV background view are different things. People can now differentiate.
2. The Empty View isn't created until it is needed.
3. The Empty View moves with Refresh Controls.

![](https://media.giphy.com/media/26gslZ7qP07e4N9h6/giphy.gif)

- [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 https://github.com/Instagram/IGListKit/pull/462

Reviewed By: rnystrom

Differential Revision: D4502591

Pulled By: dshahidehpour

fbshipit-source-id: b72b444c1197c90c385c7414f0662299070a86d1
2017-02-06 08:14:00 -08:00
Sherlock
528bd33136 Added -[IGListAdapter visibleCellsForObject:] API
Summary:
- Added `-[IGListAdapter visibleCellsForObject:]` API

1. Get all visible cells
2. Get the section for the object
3. Filter cells where indexPath.section of cell is equal to the object
4. Return

- [x] All tests pass. Demo project builds and runs.
- [x] I added test(s), an experiment, or detailed why my change isn't tested.
- [ ] 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)

-------------

Purely additive, can go in 2.2.0 release? Hold off on changelog until agreed.
Wanting to learn some more ObjC so gave this a shot, would appreciate some nit picking/feedback

Closes #437
Closes https://github.com/Instagram/IGListKit/pull/442

Differential Revision: D4450259

Pulled By: jessesquires

fbshipit-source-id: 521583c669fc1160212a7c46a50d62d951cafa2e
2017-01-23 11:28:57 -08:00
Bofei Zhu
2074eba50e Convert NSUInteger to NSInteger
Summary:
- [x] All tests pass. Demo project builds and runs.

No breaking changes that I am aware of.
Closes https://github.com/Instagram/IGListKit/pull/440

Differential Revision: D4448496

Pulled By: rnystrom

fbshipit-source-id: 9ad9bc3734b605ceab25bf6cdf993568aa6561c1
2017-01-22 14:44:14 -08:00
Jeff Bailey
8d74b8f778 Fix for #348 - IGListStackedSectionController's children need to know numberOrItems before didUpdate is called
Summary:
The reloadData method in IGListStackedSectionController was being called too soon.  It was moved from the constructor to the `didUpdateToObject` method.  Tests were updated to reflect the change.

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [ ] 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 https://github.com/Instagram/IGListKit/pull/390

Differential Revision: D4419751

Pulled By: rnystrom

fbshipit-source-id: 7c812d306b23dd251c160425873930eb8022b1a5
2017-01-14 14:29:03 -08:00
Jesse Squires
279f348a4a Added object to single section selection delegate callback
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 https://github.com/Instagram/IGListKit/pull/397

Differential Revision: D4406213

Pulled By: rnystrom

fbshipit-source-id: ba468fa49e75823796a47da6ed7f0e8957db3d75
2017-01-11 15:14:01 -08:00
Peter Edmonston
dd3b9eddcc Fix for #378 - emptyView not updated when items added
Summary:
Modified `IGListAdapter` to update the `hidden` status of the `emptyView` after any item-level changes (`insertInSectionController:atIndexes:` and related methods) based on whether the item count is zero.

Closes #378

- [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 https://github.com/Instagram/IGListKit/pull/395

Differential Revision: D4400155

Pulled By: jessesquires

fbshipit-source-id: 6c3422297d86947e7e2878ba1b9227ff2a2a18b4
2017-01-10 14:43:57 -08:00