Commit graph

29 commits

Author SHA1 Message Date
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
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
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
Ryan Nystrom
000bc36919 Relicense to MIT
Summary: Relicensing IGListKit under MIT

Reviewed By: calimarkus

Differential Revision: D7764125

fbshipit-source-id: 6c773195ef3184202725fe7f08de754f979cb83f
2018-05-01 14:50:56 -07:00
Marcus Wu
e49c94b25d Show header when section item is empty
Summary:
Issue fixed: #1117

I adding a new constructor for making a `IGListCollectionViewLayout` instance that can always show sticky header although section data is empty.

It's working well and [this is demo project](https://github.com/marcuswu0814/IGListKit_ShowStickyHeaderWhenDataEmpty).

Bug I'm not sure is any good way to let this much more readability. Is there any good advice?

```objc
const CGRect headerBounds = (self.scrollDirection == UICollectionViewScrollDirectionVertical) ?
                CGRectMake(insets.left,
                        (itemCount == 0) ? CGRectGetMaxY(rollingSectionBounds) : CGRectGetMinY(rollingSectionBounds) - headerSize.height,
                        paddedLengthInFixedDirection,
                        headerSize.height) :
                CGRectMake((itemCount == 0) ? CGRectGetMaxX(rollingSectionBounds) : CGRectGetMinX(rollingSectionBounds) - headerSize.width,
                        insets.top,
                        headerSize.width,
                        paddedLengthInFixedDirection);
```

- [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/1129

Differential Revision: D7551628

Pulled By: rnystrom

fbshipit-source-id: a60b65a92efcea5175c86aaed1de02686ea6d20a
2018-04-09 08:37:18 -07:00
Sho Ikeda
9315299fbc Minimum fixes for Xcode 9.3 build errors
Summary:
Issue fixed: #1141

This is a set of minimum fixes for Xcode 9.3 rather than #1142. Much smaller diffs 😃

The changes here were done by Xcode's FixIt. See also https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265-SW5.

> Platform Dependencies
>
> OS X uses several data types—NSInteger, NSUInteger,CGFloat, and CFIndex—to provide a consistent means of representing values in 32- and 64-bit environments. In a 32-bit environment, NSInteger and NSUInteger are defined as int and unsigned int, respectively. In 64-bit environments, NSInteger and NSUInteger are defined as long and unsigned long, respectively. To avoid the need to use different printf-style type specifiers depending on the platform, you can use the specifiers shown in Table 3. Note that in some cases you may have to cast the value.

- [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/1143

Differential Revision: D7551617

Pulled By: rnystrom

fbshipit-source-id: b27ebe2b1a1c93ebfd1218dc38b7621fefee2e6b
2018-04-09 08:37:18 -07:00
Cole Potrocky
9a45e166cb Updated IGListCollectionViewLayout to rely on layoutAttributesClass
Summary:
…instead of just allocating a vanilla UICollectionViewLayoutAttributes.    I'm happy to add tests here, but don't really have much of an opinion either way on whether this should have an explicit test case or not.

Issue fixed: #1134

- [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/1135

Differential Revision: D7551624

Pulled By: rnystrom

fbshipit-source-id: 930218c40b0082912454bb98bd02e7daa8257a3e
2018-04-09 07:45:56 -07:00
Brandon Kieft
01770eb303 Prefix all private methods with an underscore
Summary: Prefix all private methods with an underscore. A private method is defined as any method not exposed via an interface or protocol. This will improve the readability of the code and hopefully reduce bugs.

Reviewed By: rnystrom

Differential Revision: D7421346

fbshipit-source-id: 536472d57ea7fd8990fe50f3e950907ca57b8e6d
2018-04-02 15:08:21 -07:00
Ryan Wang
afbfcbdf04 fixed Footer is sticky to the top
Summary:
if `stickyHeader` is true, the footer could be sticky to the top

Issue fixed: #1093

- [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/1094

Differential Revision: D7246636

Pulled By: rnystrom

fbshipit-source-id: 9b7da52ab46229606b530a378c01d799767e27f2
2018-03-12 15:51:50 -07:00
Jesse Squires
95b779a584 Update .travis.yml and lint.sh, try to fix #1060 and lint errors #trivial
Summary:
project:
- fix file target membership issues in framework targets and test targets
- fix private/internal header imports, which shouldn't be `<IGListKit/` apparently
- fix static analyzer errors

travis:
- always install latest swiftlint
- ~~don't cache bundler, attempts to fix #1060~~
- remove markdown link check

swiftlint:
- make script non-failing if *any* version of swiftlint is installed
- warning if incorrect version is installed
- fail if not installed
- remove `scripts/generate_ci_yaml.rb`, we can just set the config file path directly
Closes https://github.com/Instagram/IGListKit/pull/1068

Differential Revision: D6885575

Pulled By: rnystrom

fbshipit-source-id: 51b7baa73feefcea71d870c1220d0382df484199
2018-02-02 13:16:46 -08:00
Sue Suhan Ma
26924ec3b6 Customized post insertion animation
Summary:
The current animation is the collection default animation - fade in/out: demo: https://pxl.cl/bj8R
Based on our design, we want the Shelf to be push down: demo https://pxl.cl/bj9R

1. Created **IGListCollectionViewDelegate** which inherits **UICollectionViewDelegateFlowLayout**
2. **IGListAdapter ** conforms **UICollectionViewDelegateFlowLayout**
3. add **transitionDelegate** to IGListSectionController
4. **IGFeedSectionController** sets transitionDelegate as itself and handles IGListCollectionViewDelegate methods

Reviewed By: rnystrom

Differential Revision: D6785726

fbshipit-source-id: bdf19f84fef05264ca0e082c6a326a31494a20da
2018-01-29 11:03:11 -08:00
Maxime Ollivier
a8275e08e1 clarify assert message
Summary:
* Clarify assert message by adding item width/height
 * Before: Width of item 1 in section 2 must be less than container 375 accounting for section insets {0, 0, 0, 0}
 * After: Width of item 1 in section 2 (415 pt) must be less than or equal to container (375 pt) accounting for section insets {0, 0, 0, 0}

Reviewed By: rnystrom

Differential Revision: D6711829

fbshipit-source-id: be99e83fd68cd345cb6a05acdde27c8252e59650
2018-01-16 07:59:35 -08:00
yiplee
e63a0e78fe Add new iOS 11 api adjustedContentInset support
Summary:
adopt adjustedContentInset instead of contentInset on iOS 11

- [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/1020

Reviewed By: manicakes

Differential Revision: D6513703

Pulled By: rnystrom

fbshipit-source-id: 5d718f2cb30361959ca5ba8238746427223cb5fd
2017-12-18 08:51:14 -08:00
Maxime Ollivier
f0b947cd1f expose didModifySection on IGListCollectionViewLayout
Summary: * IGListCollectionViewLayout can now keep track of the minimumInvalidatedSection given individual section updates.

Reviewed By: rnystrom

Differential Revision: D6545333

fbshipit-source-id: 64c9b5ff32339299b52059a4d990a42d9e6a1af5
2017-12-15 09:33:39 -08:00
Maxime Ollivier
7a23ed521d update IGListCollectionViewLayout to allow for partial layout invalidation
Summary:
* Currently, we invalidate the entire layout whenever we make any updates, like inserting new rows at the bottom.
* This is one of the most common causes of frame drop on feed, so let's allow partial invalidation based on the minimum modified section.
  * For example, if we delete section 10, move section 4, and insert section 12, we would re-calculate the layout starting at section 4.
* This gets us the majority of the performance gains and it's relatively simple. In the future, we can make further optimizations, like 1) index path level invalidation and 2) finding the smallest modified index path whose properties (ex: size) have actually changed.

Reviewed By: rnystrom

Differential Revision: D6510140

fbshipit-source-id: 6ff1766b400c5aa82abc29ae76ab96660c3bb106
2017-12-15 09:33:39 -08:00
Igor Vasilenko
a0cf76c757 Added support UICollectionElementKindSectionFooter for IGListCollectionViewLayout
Summary:
**Changes occurred only for the IGListCollectionViewLayout.**

**Specifically:**
1. Harnessed the hardcore to the fact that it is possible to use only headers.
2. Assertions removed
3. Caching for layout of attributes of footers
4. Implemented the location of the footers in any orientation scroll

Issue fixed: #898

I need this enhancement ASAP 🙏

**Example:**
Footers with user comments count
![simulator screen shot - iphone 6 - 2017-11-14 at 13 35 22](https://user-images.githubusercontent.com/7735730/32775551-c69868cc-c940-11e7-8307-ae2e353519ff.png)

- [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)
- [x] I updated example project with implemented feature
Closes https://github.com/Instagram/IGListKit/pull/1017

Reviewed By: jeremycohen

Differential Revision: D6385893

Pulled By: rnystrom

fbshipit-source-id: 5f1bad5655d2df321f8c71496aa797ac8e3d226a
2017-11-21 12:45:38 -08:00
Peter Edmonston
9e312275c3 Add horizontal scrolling support to IGListCollectionViewLayout
Summary:
Issue fixed: #752

- [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)

This PR generalizes the layout logic in `IGListCollectionViewLayout.mm` to handle horizontally scrolling layouts, mainly by generalizing references to `width`, `height`, `x` and `y` to take scrolling direction into account. This changes the signature of `IGListCollectionViewLayout.init` as well as the names of a few properties, so it would be a breaking change.

I added a couple of unit tests specifically for horizontal layouts -- but held off from adding a horizontal version of *every* unit test for this class, as it would basically double the number of tests. But if you want that, just let me know and I'm happy to do it.

Also let me know if you want me to add a demo VC to the Examples project that uses this new horizontal flow layout -- I have some demo code handy (I used it for testing), but didn't want to clutter up the PR if you didn't want/need it.
Closes https://github.com/Instagram/IGListKit/pull/857

Reviewed By: ryanolsonk

Differential Revision: D5547266

Pulled By: rnystrom

fbshipit-source-id: 6094c45069fc265273d0f95c296fa78e47470384
2017-08-07 09:33:30 -07:00
Andrew Monshizadeh
e58a44cfbe Compare using FLT_EPSILON
Summary:
Floating point math loses precision and so comparing two floats that are likely to only differ in the mantissa, and even then by extremely small amounts, is tricky. Exact equality often fails in these cases and asserting on exact equality is probably not necessary.
Closes https://github.com/Instagram/IGListKit/pull/828

Differential Revision: D5310575

Pulled By: rnystrom

fbshipit-source-id: f942489fbe0b2bc5f215329caac8abbae577a830
2017-06-26 18:03:51 -07:00
Viktor Gardart
95367bb6a4 replace alloc] init] -> new]
Summary:
Issue fixed: #822

As rnystrom would've said: Go 💚
Closes https://github.com/Instagram/IGListKit/pull/823

Differential Revision: D5301864

Pulled By: rnystrom

fbshipit-source-id: c7a0f62b91712a54ee75ee0d1fe62b8611745e37
2017-06-22 09:31:45 -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
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
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
PhilCai
bbd4738ca2 Simplify header height check in layout
Summary:
Issue fixed: #

- [ ] 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)

Small changes
Closes https://github.com/Instagram/IGListKit/pull/565

Differential Revision: D4728939

Pulled By: rnystrom

fbshipit-source-id: 4f0c3455f55d4c267dffe5d7ebd37a96a648ec52
2017-03-17 08:20:39 -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
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
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
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