Commit graph

299 commits

Author SHA1 Message Date
Zhisheng Huang
64f053c258 Refactor and move the applyUpdate code into Helper file
Summary: I want to reuse this collection view update code in next diff, let's move it to a Helper file to support code sharing.

Reviewed By: calimarkus, iperry90

Differential Revision: D18714061

fbshipit-source-id: a85e8576226276fcab90ea1d2ed23aac5501aa17
2019-12-04 15:32:04 -08:00
Zhisheng Huang
da4a5bbf25 Simplify the code and use _itemCountIsZero (#1400)
Summary:
…uld show empty view

## Changes in this pull request

Basically we can use the existing _itemCountIsZero like all the other usage, and it's faster since it stopped early, compared to before we loop through all the sectionController.numberOfItems and sum up.

### Checklist

- [x] 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.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1400

Differential Revision: D18687637

Pulled By: lorixx

fbshipit-source-id: bcdc57ba43b86cd0ed639ffaab9ae0493fd2f844
2019-11-27 09:23:18 -08:00
Jefferson Setiawan
f50f3c7ef6 Support Project Catalyst (#1398)
Summary:
## Changes in this pull request

Add support when compile Catalyst.
Fix this error: `Cannot define category for undefined class 'IGListAdapter'`
![Screenshot 2019-11-22 at 22 35 31](https://user-images.githubusercontent.com/14871122/69440931-49979c80-0d7c-11ea-8673-f9b8a60441f0.jpg)

## Step To Reproduce
In the Main target, check the Mac under Deployment Info, more Info in [here](https://developer.apple.com/documentation/uikit/mac_catalyst?language=objc)

### Checklist

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1398

Differential Revision: D18687673

Pulled By: lorixx

fbshipit-source-id: b5b9aa60406c9b66a48abbdfeea2bc5f44c9ca66
2019-11-27 09:23:17 -08:00
kinarob
7fe113fea8 Remove useless system version code (#1396)
Summary:
## Changes in this pull request

`Examples/Examples-iOS/Pods/Pods.xcodeproj/project.pbxproj`
`Examples/Examples-tvOS/Pods/Pods.xcodeproj/project.pbxproj`

this change just Xcode 11.2 generated.

This pr aim to remove useless `IGSystemVersion` file.

### Checklist

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1396

Reviewed By: lorixx

Differential Revision: D18638299

Pulled By: iperry90

fbshipit-source-id: 0b6583f1210e5d1570dd672eed8c59901d6785f6
2019-11-21 09:56:43 -08:00
Zhisheng Huang
f3175ec31f Update the version to be 4.0
Summary:
As title, let's prepare the 4.0 release with the version bump.

1. Change the Source/Info.plist to have 4.0.0 for CFBundleShortVersionString.
2. Manually update any .md files that used the old release versions.
3. Run `./scripts/setup.sh` to re-update all the pods and the Example projects.

Reviewed By: natestedman

Differential Revision: D18616823

fbshipit-source-id: ca0f2a09cdd9ab592c2cb002fe923e195ce3ab12
2019-11-20 16:23:15 -08:00
Andrea Antonioni
ada811e1bb IGListAdapterDelegate needs Swift name of ListAdapterDelegate (#1116)
Summary:
## Changes in this pull request

Add Swift name annotation `ListAdapterDelegate` to `IGListAdapterDelegate`. The breaking change is written in the `CHANGELOG.md` for the `4.0.0` release

Issue fixed: https://github.com/Instagram/IGListKit/issues/1115

### Checklist

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1116

Reviewed By: bdotdub

Differential Revision: D18278551

Pulled By: iperry90

fbshipit-source-id: db9d1910fc4be7ffa723ee291a9c65db0fd217c0
2019-11-06 09:16:17 -08:00
Ian Perry
2fa963bfa3 Drop support for iOS 8 (#1381)
Summary:
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1381

https://github.com/Instagram/IGListKit/issues/1078

Dropping support for iOS 8
- Removed checks for iOS 8
- Updated xcodeproj file
- Updated Travis
- Updated podspec

Reviewed By: bdotdub, lorixx

Differential Revision: D18249291

fbshipit-source-id: eba9814b71e67fdc0ef50fcbc809189d86e8c5fb
2019-11-01 12:40:19 -07:00
Nate Stedman
e4c60650f2 Split IGListKit and IGListDiffKit (#1377)
Summary:
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1377

This splits the diffing-only components from `IGListKit` out into a separate library, `IGListDiffKit`, allowing them to be used independently of the rest of `IGListKit`. We've found that the diffing components of the library are useful independently of the rest of the `UICollectionView` infrastructure, and separating the libraries allows apps to take advantage of those components without paying the full binary size cost of `IGListKit`. The diffing components are available as a subspec in Cocoapods, and as an independent framework in Carthage and direct Xcode project import (i.e. Git submodules).

This is a breaking change, necessitating a major version bump, although it should have only minor impact for projects using the umbrella header `IGListKit.h`, as that header continues to import the diffing utilities. In particular, for a project using Cocoapods and importing `IGListKit.h`, there should be no code changes required.

Reviewed By: calimarkus

Differential Revision: D18114249

fbshipit-source-id: 363b5a427e32800bbc6e82f897230963b4167245
2019-10-31 08:26:12 -07:00
Maxime Ollivier
7824698610 prevent crash when inserting and deleting the same NSIndexPath multiple times
Summary:
Issue: The `NSIndexPath` level updates are really tricky because they don't go through the diffing process. It's up to the caller to make sure that the inserts/deletes/moves all add up to the final number of items. And it's not uncommon that 2 different updates will try to change the same `NSIndexPath` at the same time, which can cause headaches and crashes. For example, if we insert/delete the same `NSIndexPath` twice in the same update pass, we end up with 2 inserts and 1 delete, because we remove duplicated deletes. This causes an `NSInternalInconsistencyException` since things don't add up at the end.

Fix: Lets also remove duplicate `NSIndexPath` inserts to balance things out. In the future, it would be nice to get rid of this API entirely and have everything go through the diffing.

Reviewed By: lorixx

Differential Revision: D17423776

fbshipit-source-id: 62fdf5bd521a915e984e8de180c74858f7ae7ef4
2019-09-17 15:31:54 -07:00
Hanton Yang
b01010e5e9 Deprecate IGListStackedSectionController (#1355)
Summary:
## Changes in this pull request

Issue fixed: https://github.com/Instagram/IGListKit/issues/1099

### Checklist

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1355

Reviewed By: Ziewvater

Differential Revision: D17200801

Pulled By: lorixx

fbshipit-source-id: 22bb1abc69b38c9d856621fe848c09e61a9d41ef
2019-09-16 12:28:01 -07:00
Maxime Ollivier
6faddd99c9 avoid layout before IGListAdapter scrollToObject
Summary:
* Issue: `[IGListAdapter scrollToObject ...]` currently calls `[collectionView layoutIfNeeded]` before scrolling which creates the current visible cells that will no longer be visible after the scroll. This causes perf issues when we scroll immediately after creating the view controller.
* Fix: Instead of asking the layout object for the attributes, lets go throught the `UICollectionView`. So if the attributes are not ready, the `UICollectionView` will call `-prepareLayout`, return the attributes, but doesn't generate the cells just yet.

Differential Revision: D17326459

fbshipit-source-id: 745942225e0311fea7c3efb07ac1e8b8e0a82996
2019-09-13 14:57:52 -07:00
Maxime Ollivier
cddb29799c fix supplementary view crash when using IGListCollectionViewLayout
Summary:
* Issue: Calling `[UICollectionView layoutAttributesForSupplementaryElementOfKind...]` with an indexPath that doesn't have a supplimentary view.
* Cause: `IGListCollectionViewLayout` always returns a non-nil `UICollectionViewLayoutAttributes` when calling `layoutAttributesForSupplementaryViewOfKind` which tells the `UICollectionView` that it's fair game to ask the dataSource for a supplementary view at the indexPath. But when it does, the section controller could return nil, which throws an expection.

In the Apple docs about `[UICollectionViewDataSource collectionView:viewForSupplementaryElementOfKind:atIndexPath:]`

> This method must always return a valid view object. If you do not want a supplementary view in a particular case, your layout object should not create the attributes for that view.

https://developer.apple.com/documentation/uikit/uicollectionviewdatasource/1618037-collectionview?language=objc

* Fix: Just like `UICollectionViewFlowLayout`, if the supplementary view size is empty, lets return a nil attribute.

Reviewed By: Ziewvater

Differential Revision: D17326461

fbshipit-source-id: 507e98f43e951216cf2eafe2449f87df25439e11
2019-09-13 14:57:52 -07:00
Hanton Yang
628c547cc6 Remove the redundant __IPHONE_11_0 (#1351)
Summary:
## Changes in this pull request

Remove the redundant __IPHONE_11_0, because the minimum requirement is Xcode 9.0+ now.

### Checklist

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1351

Differential Revision: D17200815

Pulled By: lorixx

fbshipit-source-id: 25705856cf26d5c215ed956802ab1022c98cbca0
2019-09-04 23:23:25 -07:00
Hanton Yang
93da0852d1 Remove unused headers (#1358)
Summary:
###  Changes in this pull request

* Improve compilation time by reducing unnecessary compilation dependencies
* More clean code

### Checklist

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1358

Differential Revision: D17200761

Pulled By: lorixx

fbshipit-source-id: 9c6bca4d3d5e2e4b35125c7a12e483d58993c4e8
2019-09-04 23:06:57 -07:00
Hanton Yang
b194eb21e3 Update queue priority in Background Diffing (#1363)
Summary:
## Changes in this pull request

Update to use `QoS` and take higher priority for responsiveness and energy efficiency.

Following the guideline in the doc [Energy Efficiency Guide for iOS Apps](https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/PrioritizeWorkWithQoS.html).

It's better to use `User-initiated` QoS in `Background Diffing` because it focuses on "Work that the user has initiated and requires immediate results".

### Checklist

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1363

Differential Revision: D17200745

Pulled By: lorixx

fbshipit-source-id: 4b9b2159f06edeed92e79bac771fe7b89f6d5708
2019-09-04 23:04:18 -07:00
Markus Emrich
323887920d Remove stringWithFormat: calls without parameters (#1360)
Summary:
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1360

`codemod -m -d ~/fbsource/fbobjc/ --extensions m,mm '\[NSString stringWithFormat\:\@\"([^\"]*?)\"\]' '@"\1"'`

Excluded third party libraries.

Differential Revision: D15590354

fbshipit-source-id: 954db583a02e0da26ea52ad7b8762e1d8f902ab4
2019-08-20 15:11:30 -07:00
Hanton Yang
cb344f9814 Delete duplicate headers in IGListKit.h (#1347)
Summary:
## Changes in this pull request

Delete duplicate headers in `IGListKit.h`

### Checklist

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1347

Reviewed By: joetam

Differential Revision: D16542316

Pulled By: joetam

fbshipit-source-id: feaaaaca0f9eddc4be58996c8a3a2521a7817185
2019-08-01 17:52:41 -07:00
Bofei Zhu
b7bc76dce4 Change paths to path (#1205)
Summary:
## Changes in this pull request
Should map be a map of `IndexPath`s instead of arrays of `IndexPath`s? Also, we might need some unit tests on this part. I don't think it's covered.

### Checklist

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1205

Reviewed By: Ziewvater

Differential Revision: D15962803

Pulled By: lorixx

fbshipit-source-id: f207b69ef0ebad08cd72b14ba53101e56d1604fd
2019-06-25 11:46:46 -07:00
Dennis Müller
0ac855df99 Fix - Cell Reordering in IGListBindingSectionController (viewModels array not being updated) (#1274)
Summary:
- See #1262 (cell reordering using a binding section controller caused problems)

## Changes in this pull request
- Added method override in `IGListBindingSectionController` to update the internal `viewModels` array after a cell has been moved
- Subclasses of IGListBindingSectionController require to call super

Issue fixed: #1262

I've added a test for this change. Is this enough? Or should I add more corner cases or something?

### Checklist

Some tests fail, but they do seem unrelated. I don't know if this is normal. I haven't changed anything regarding those failing tests.

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1274

Reviewed By: candance

Differential Revision: D15592822

Pulled By: lorixx

fbshipit-source-id: d81c18bec0ad0a6a6613089245352bb182a92f26
2019-06-23 23:25:09 -07:00
Aaron Pang
78cca5bc43 Add experiment to have the collection view layout check the collection view instead of the collection view layout [2/2]
Summary:
The collection view layout here should not be accessing the data source directly but instead asking the collection view for the number of sections and number of items. This is because the collection view holds an internal cache and if there is a discrepancy between when the collection view cache and the data source, preparing the layout will crash the app because we will send a layout down to the collection view with a items that might not exist in the collection view's cache but exist in the data source.

This diff adds an experiment to see the impact of fixing this check so that when we prepare layouts we don't ask the data source directly but ask the collection view instead. The collection view will then update it's cache and check the data source so it does not crash when we prepare a layout.

```
NSInternalInconsistencyException at __45-[UICollectionViewData validateLayoutInRect:]_block_invoke:
UICollectionView received layout attributes for a cell with an index path that does not exist:
<NSIndexPath: 0xc198a8c3ea391fbb> {length = 2, path = 4 - 0}
```

Reviewed By: lorixx

Differential Revision: D15830610

fbshipit-source-id: f3dae3e87c55b86c3b686309c1144ccfff1375bf
2019-06-14 16:23:46 -07:00
Zhisheng Huang
8a0c69ba29 Cleanup the skiplayout in reloadData fallback
Summary: The test was actually deallocated last year, and this test is never cleaned up. Now let's clean it up.

Reviewed By: chritto

Differential Revision: D15777898

fbshipit-source-id: c3a704ee1bfdd085c4ceb89af424a10ed07a65b6
2019-06-12 18:35:54 -07:00
Qinghua Hong
08bf69cc2f Fix #1275 layouts inconsistency in updateAnimated:completion of IGListBindingSectionController (#1285)
Summary:
## Changes in this pull request

Issue fixed: https://github.com/Instagram/IGListKit/issues/1275

This PR is straintforward solution as mentioned in https://github.com/Instagram/IGListKit/issues/1275. When I finished it, I realized that it is not a problem in `IGListCollectionViewLayout Partial Optimization` and `IGListBindingSectionController` deserved it. Maybe `IGListCollectionViewLayout` is rarely used because of great builtin UICollectionViewFlowLayout or cells in section rarely need changing their sizes in practices.

Despite it is not `IGListCollectionViewLayout`'s fault, I think it can be more optimized against `invalidateLayoutWithContext`. I would like to make an another PR to optimize it.

Due to this PR just giving a proposed solution, it lacks of adding tests and changing log. When this solution is accepted, I would like to complete these todos.

### Checklist

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1285

Reviewed By: candance

Differential Revision: D15592807

Pulled By: lorixx

fbshipit-source-id: ae06abce896341509de4f3dfb73b3a7bc0a68c51
2019-06-11 22:29:34 -07:00
kinarob
de08713b33 Remove intercepted duplicate selector in IGListAdapterProxy. (#1291)
Summary:
## Changes in this pull request

### Checklist
Don't need tests.

- [x] All tests pass. Demo project builds and runs.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1291

Reviewed By: lorixx

Differential Revision: D15564138

Pulled By: candance

fbshipit-source-id: a0fabbd6a8f8389b09da7cd5484df75d67a709e5
2019-06-01 11:55:12 -07:00
Qinghua Hong(qhhonx)
619b835710 Fix scrollToObject: inconsistency bug when scrolling to bottom/right with content inset (#1284)
Summary:
The implementation of
```Objective-C
-[IGListAdapter scrollToObject:supplementaryKinds:scrollDirection:scrollPosition:animated:]
```
has little inconsistencies where the `UICollectionViewScrollPositionLeft` and `UICollectionViewScrollPositionTop` considering the content inset left/top of the collection view was being applied to the final offset. However, the `UICollectionViewScrollPositionRight` and `UICollectionViewScrollPositionBottom` ignoring the content inset right/bottom of the collection view was being applied to the final offset. The different result is that scrolling to the most `Left/Top`, the first section content always be visible by considering its content inset while scrolling to the most `Right/Bottom`, the last section content always be fully displayed but not be fully visible by considering its content inset.

## Changes in this pull request

Issue fixed: #

### Checklist

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1284

Reviewed By: lorixx

Differential Revision: D13590416

Pulled By: lorixx

fbshipit-source-id: ae52be9e5ba25b50c7a0ad768a4af728347523e2
2019-05-25 12:48:21 -07:00
Andrew Breckenridge
05e680f1cb #trivial fix inconsistent assignment ordering
Summary: Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1315

Differential Revision: D15425369

fbshipit-source-id: 54abf0f0c2258a02bdfd804f6553d6b74ab517a8
2019-05-20 19:13:22 -07:00
Benny Wong
831e9b8809 Fix travis & upgrade cocoapods (#1317)
Summary:
This is a bigger PR than I'd like but there is a bunch of stuff in here that feels like we should land all at once to fix the Travis setup.

Currently, there is a few things wrong. Briefly:
1. Travis is failing to even build the library (see: [build 2298](https://travis-ci.org/Instagram/IGListKit/jobs/506564900))
2. There are legitimately failing tests
3. Travis seems to be flakey running UI tests

This PR deals with the first two.

The Xcode projects were not building because some recently added files weren't added to the xcodeproj (ie. 46a124ddfe and 4662454c4a).

Also added `Foundation.h` import for `bool` definition for `IGSystemVersion` (also a new file)

The main `Podfile.lock` was already being generated via `1.5.3` (0c0b31ad7c) but the `Gemfile` had the wrong version and none of the example project `Podfile.lock`s were re-generated with it.

Once I got the projects correctly building and tests running, I discovered there were a bunch of tests that were legitimately failing. It's unclear when these started failing and what caused it.

I thought it made sense to disable these tests for now and then create Github issues to fix them as starter tasks instead of making this diff even larger.. I can create those if that sounds good.

Somewhat related, it seems like the UI tests on Travis may be a bit flakey. They pass locally, but breaks on Travis [[example](https://travis-ci.com/bdotdub/IGListKit/jobs/195758250)] with error messages like `Failure requesting automation session for com.instagram.IGListKitExamples:85190`

----

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1317

Reviewed By: rnystrom

Differential Revision: D15157375

Pulled By: rnystrom

fbshipit-source-id: b29131f59b74398b6d2b3a73453248cb3325a955
2019-05-01 15:13:25 -07:00
Maxime Ollivier
4f9c61a37f clean up IGListExperimentBackgroundDiffingSerial
Summary: * Cleaning up experiment

Reviewed By: lorixx

Differential Revision: D15134137

fbshipit-source-id: a3f5a6d7b4a5f3897608c4e32ad4c4e6e4e720e5
2019-04-30 10:50:52 -07:00
Maxime Ollivier
4662454c4a create IGListAdapterPerformanceDelegate
Summary:
* Currently, there's no easy way to measure how long we spend dequeueing cells or handling scroll events across the app. This makes it a bit difficult to catch scroll-perf issues early on.
* Fix: Lets create `IGListAdapterPerformanceDelegate` which gives us that information.

Reviewed By: rnystrom

Differential Revision: D14430449

fbshipit-source-id: 7bc170bdaa37807c8719976e8818f3a578ee17dd
2019-03-14 18:10:00 -07:00
Zhisheng Huang
2f76e8ce68 Cleanup the coalescing time experiment
Summary:
We have observed that keeping the coalescing time here would actually decrease the stability here, it makes the app crash more often.
It's probably caused by some race condition during that time and UICV updates become out of sync.

Reviewed By: rnystrom

Differential Revision: D14379265

fbshipit-source-id: 502c1c14fb8bdfc35969f721687e82888b160110
2019-03-08 09:58:14 -08:00
Zhisheng Huang
9e59bdea11 Remove the unnecessary assert which would affect IGListKit perf
Summary:
This assert was hoping to find if there are any duplicates from the `fromObjects`. However, from the finding, we did not see any assertion or trace that this is the case.

The `objectsWithDuplicateIdentifiersRemoved` is actually doing extra work during updates.

We should remove this for the sake of better scroll perf and faster UI update.

Reviewed By: calimarkus

Differential Revision: D14339124

fbshipit-source-id: ff40fd23a05640058673d46f63a9e4bf516dd3f6
2019-03-06 13:04:53 -08:00
Scott Wolchok
035808e750 Don't call [UIDevice currentDevice] in +load
Summary: sysctl should be faster.

Reviewed By: timonus

Differential Revision: D13981833

fbshipit-source-id: ae7a67d4eb69595441a4a66e0ef0a271762f77ce
2019-02-08 14:42:56 -08:00
Jordan Smith
46a124ddfe Define IGListCollectionViewLayoutCompatible to allow custom layouts to interact with IGListCollectionView
Summary: This change allows arbitrary layouts to be used in tandem with IGListCollectionView and recieve udpated section indices, by conforming to to conform IGListCollectionViewLayoutCompatible.

Reviewed By: maxoll

Differential Revision: D13671204

fbshipit-source-id: e030f413aefff71754731d1259037077ffb73959
2019-01-17 07:53:23 -08:00
Ofir Gluzman
36d1b8b210 Fix inconsistent state caused in UICollectionViewLayout+InteractiveReordering. (#1289)
Summary:
Issue fixed: #1288

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1289

Reviewed By: timonus

Differential Revision: D13590406

Pulled By: rnystrom

fbshipit-source-id: 0814b0c2383a185da747176bad57dfb15c7e883f
2019-01-10 08:25:26 -08:00
Tim Johnsen
a09242e279 Add experiment to perform IGListAdapterUpdater background updates on a serial queue.
Summary: This diff adds a new `IGListExperimentBackgroundDiffingSerial` experiment that behaves similarly to `IGListExperimentBackgroundDiffing` but executes changes in a per-`IGListAdapterUpdater` serial queue instead of a global queue. Global queues are concurrent, and concurrent queues by nature don't ensure the execution order of the blocks that are enqueued into them, so there's a chance that the former `IGListExperimentBackgroundDiffing` experiment would lead to changes being applied out of order.

Reviewed By: calimarkus

Differential Revision: D13567403

fbshipit-source-id: a2aebb20e5e7dc22601fad3c2dfc80112747c81b
2019-01-03 09:27:03 -08:00
Jordan Smith
b9486a104c Replace incorrect IGListSectionController dequeue calls
Summary:
Some calls to cellForItemAtIndex: on IGListSectionController expect this method to return a reference to an existing, already dequeued cell. It doesn't do this - it dequeues a new cell instance and returns that.

Added a warning note to the docs.

Reviewed By: lorixx

Differential Revision: D13222395

fbshipit-source-id: bb7a80f9f005e2675eef3d01a236a5f9f0008b46
2018-11-29 08:26:58 -08:00
Zhisheng Huang
6cdd112790 Fix some crash from IGListKit that nil dataSource might result in crash
Summary:
This happens when we set collectionView.dataSource to be nil before calling performUpdates:, the crash is easily reproduced by a simple unit test.

To make the infra more robust and we don't crash the app, let's add an early return before applying a collectionView update.

Reviewed By: rnystrom, calimarkus

Differential Revision: D12896196

fbshipit-source-id: ab024d0e7e9282d50c3be297e1e67cfccaff8242
2018-11-06 11:37:27 -08:00
Jiecong Wang
c3ae2906c9 Skip forcing layout when UICollectionView is invisible #trivial (#1268)
Summary:
Issue fixed: # https://github.com/Instagram/IGListKit/issues/1267

- [ ] 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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1268

Reviewed By: maxoll

Differential Revision: D12839019

Pulled By: rnystrom

fbshipit-source-id: c695d66234d7d1969f9f17f55cbe9d7967970adc
2018-11-01 14:57:43 -07:00
Allen Hsu
8ebde97b92 Fix logic flaw of of shouldInvalidateLayoutForBoundsChange in IGListCollectionViewLayout (#1236)
Summary:
Issue fixed: #1235

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1236

Reviewed By: lorixx

Differential Revision: D12839081

Pulled By: rnystrom

fbshipit-source-id: 3e9e1192f16912d560d76f3730a377f303708cd7
2018-11-01 14:55:01 -07:00
trungducc
3f31d05ac3 Fix documentation [IGListSectionController canMoveItemAtIndex:] #trivial (#1242)
Summary:
Issue fixed: #1219

No tests were added and no entry was added to `CHANGELOG.md` since this is a trivial 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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1242

Differential Revision: D12840487

Pulled By: rnystrom

fbshipit-source-id: ded4b09765c5666e23a9aa3596328e90df2b3229
2018-11-01 11:03:08 -07:00
Ryan Nystrom
8d8a632b67 Update MIT license language (#1272)
Summary:
Updating license language to meet FB open source standards.
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1272

Differential Revision: D12844366

Pulled By: rnystrom

fbshipit-source-id: 27ae49ae00d963c5c012c79c5738365c232a5773
2018-11-01 10:58:46 -07:00
trungducc
aa2361f449 Remove nibName argument from IGListReusableViewIdentifier #trivial (#1241)
Summary:
Issue fixed: #1223

- [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)
Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1241

Differential Revision: D12838898

Pulled By: rnystrom

fbshipit-source-id: af47550dd320fb0e813e8ae22bc7051c2460a05d
2018-10-30 13:43:59 -07:00
Zhisheng Huang
039e77e359 Add diffResult as argument to pass to willCrashWithException: in IGListAdapterUpdaterDelegate
Summary: This would help us understands what was the diff result from the algorithm and compare it with the `updates` to check what went wrong. Essentially, this would make our debugging easier going forward.

Reviewed By: calimarkus

Differential Revision: D12828892

fbshipit-source-id: 6dc52cdba1adb5a841760b51599e2df4c845c364
2018-10-29 18:33:59 -07:00
Zhisheng Huang
c1bf5f1261 Gate the preferItemReloadsForSectionReloads only to use when there is no change to the number of sections
Summary:
There are some crashes related to this path when the number of sections are changed when using the `preferItemReloadsForSectionReloads` optimization for item reloads.

For now, this change would just limit the flag only useable when the section count is unchanged. The proper fix would be finding a repro-case for the unsafe trace.
The follow-up here is adding more logging to capture the crash reason and investigate any variable that leads to this crash.

Reviewed By: calimarkus

Differential Revision: D12828061

fbshipit-source-id: 040e66c051c54f889ee9fbc3e4a48ab6bf93e162
2018-10-29 16:21:11 -07:00
Jeremy Cohen
b200ddacf5 Add more info in IGListAdapterUpdater willPerformBatchUpdates call
Summary: Provide additional context in willPerformBatchUpdates, which can be useful for debugging.

Reviewed By: lorixx

Differential Revision: D10436588

fbshipit-source-id: a59803affc24ca20f7726e36117df6126b984afb
2018-10-21 07:58:35 -07:00
Maxime Ollivier
13d22fbfed clean commented out code
Summary: * Removed comments

Reviewed By: lorixx

Differential Revision: D10453000

fbshipit-source-id: 02fb93eb7ad5c3122c2bc1b2722cc8c25dc12d84
2018-10-19 10:50:16 -07:00
Zhisheng Huang
ffb37d6826 Add an assertion inside IGListAdapterUpdater to see if fromObjects contains duplicate identifiers
Summary: Verify our assumption that the `fromObjects` should never contain duplicate identifiers.

Reviewed By: calimarkus

Differential Revision: D10410190

fbshipit-source-id: 4952698fee6373224b4c8395778009540c5ae380
2018-10-16 12:54:22 -07:00
Zhisheng Huang
e6032c8107 Resolve crash when using preferItemReloadsForSectionReloads and there is section movements
Summary:
section moves are extremely unsafe and crashy.

If we still use the `preferItemReloadsForSectionReloads` on, the item reloads won't be correct when we applies the same logic for cases without section moves.

It leads to crash:

```
2018-09-04 23:28:12.184875-0700 xctest[51440:12103918] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0.  The number of items contained in an existing section after the update (1) must be equal to the number of items contained in that section before the update (1), plus or minus the number of items inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'
```

even if we change to use -reloadSections: instead, we still get crash like the following:

```
2018-09-04 23:21:14.129961-0700 Direct[45654:12078189] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to perform a delete and a move from the same section (25)'
```

Thus let's only add the moves.count == 0 check before using the prefer item reloads over section reload optimization.

Reviewed By: calimarkus

Differential Revision: D9661723

fbshipit-source-id: 8c3ddcd5178cb1aa58ccd9ae274cd8e5198f7609
2018-09-05 14:03:00 -07:00
Zhisheng Huang
eddb0a5f21 Safely check the sectionIndex to be within the right bound before converting to use convertSectionReloadToItemUpdates
Summary:
This made the items reload safer, as I tested that passing in an out-of-bound section index to -[UICollectionView numberOfItemsInSection:] would crash the app.

UIKit did not handle this gracefully.

Reviewed By: calimarkus

Differential Revision: D9624061

fbshipit-source-id: bcf14a3d4746b648046992adf221faff36a0257c
2018-08-31 18:32:56 -07:00
Zhisheng Huang
66742f2309 Update doc in IGListAdapterUpdater
Summary: Make the comment doc block more concise.

Reviewed By: calimarkus

Differential Revision: D9596272

fbshipit-source-id: 1b957bb5a68a167d99c2cdd5874416d19f0a088b
2018-08-30 15:32:38 -07:00
Jeremy Lawrence
3b19cfb9d7 Fix bug with cell identifiers
Summary:
When we added the ability to register the same class with multiple reuse identifiers, forgot to adjust the `registeredClasses` set to reflect that. This resulted in a bug where the collection view could be asked for a cell of a class that had already been registered, but with a different reuse identifier, which would end in a crash.

This diff fixes the crash, I'll follow up with another diff that adds unit tests around this, but want to fix master ASAP.

Differential Revision: D9560338

fbshipit-source-id: e8df6fe5d9929b44842c6abc01d52064ccb4147e
2018-08-29 12:33:01 -07:00