Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allowsBackgroundReloading Flag to ListAdapterUpdater to Give User Control of Behavior #375

Closed
wants to merge 10 commits into from

Conversation

Adlai-Holler
Copy link
Contributor

Such a powerful framework y'all have made! Game status: changed.

Changes in this pull request

  • Add a flag to ListAdapterUpdater to require it to perform diffing, even when collection view is not in a window.
    • Ensures delegate can rely on diffing callbacks.
    • Ensures layout can rely on prepareForCollectionViewUpdates:.
    • Helps with support for AsyncDisplayKit that I'm working on 🙊

Pull request checklist

  • 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

@Adlai-Holler Adlai-Holler changed the title Allow user to force ListAdapterUpdater to perform diffing, even when … Add skipsDiffingWhenOffscreen Flag to ListAdapterUpdater to Give User Control of Behavior Dec 28, 2016
@coveralls
Copy link

coveralls commented Dec 28, 2016

Coverage Status

Coverage increased (+0.0007%) to 97.979% when pulling 12c5587 on Adlai-Holler:always-be-diffing into 5cd771b on Instagram:master.

@jessesquires
Copy link
Contributor

Thanks @Adlai-Holler ! 💯

Not 100% sure about this change. I'll defer to @rnystrom.

One thing to note though: we'll need the default value to be NO to preserve existing behavior. Otherwise, this is a breaking change for clients already using the library.

@Adlai-Holler
Copy link
Contributor Author

Adlai-Holler commented Dec 29, 2016

@jessesquires The current behavior is to default to YES.

EDIT: Thanks for the review btw! Love your work!

@jessesquires
Copy link
Contributor

@Adlai-Holler - ahh ok 👍

Copy link
Contributor

@rnystrom rnystrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really curious about the ASDK integration stuff! Sounds cool.

Just a few nits then we can go ahead and land this. We had batch updates in the background for a while and removed it simply to save main queue resources for things that might be updating off-screen. Should be a harmless option.

@note This will result in better performance, but will not generate the same delegate
callbacks and your layout will not receive `prepareForCollectionViewUpdates:`.

@warning On iOS < 8.3, this behavior is unsupported and will always be treated as `NO`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@@ -155,7 +153,8 @@ - (void)performBatchUpdatesWithCollectionView:(UICollectionView *)collectionView

// if the collection view isn't in a visible window, skip diffing and batch updating. execute all transition blocks,
// reload data, execute completion blocks, and get outta here
if (_canBackgroundReload && collectionView.window == nil) {
BOOL iOS83OrLater = (NSFoundationVersionNumber >= NSFoundationVersionNumber_iOS_8_3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can keep this in here for now, but IMO better to keep PRs changing one thing at a time. Makes crawling history and blames a lot easier.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make this const BOOL too 😊

@@ -155,7 +153,8 @@ - (void)performBatchUpdatesWithCollectionView:(UICollectionView *)collectionView

// if the collection view isn't in a visible window, skip diffing and batch updating. execute all transition blocks,
// reload data, execute completion blocks, and get outta here
if (_canBackgroundReload && collectionView.window == nil) {
BOOL iOS83OrLater = (NSFoundationVersionNumber >= NSFoundationVersionNumber_iOS_8_3);
if (iOS83OrLater && _skipsDiffingWhenOffscreen && collectionView.window == nil) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the getter self.skipsDiffingWhenOffscreen since we're using more than an ivar

@@ -459,4 +459,52 @@ - (void)test_whenCallingReloadData_withUICollectionViewFlowLayout_withEstimatedS
XCTAssertEqual([collectionView numberOfItemsInSection:1], 4);
}

- (void)test_whenCollectionViewNotInWindow_andDiffSkippingFlagSetNO_diffHappens
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: sameline the { for all tests

@facebook-github-bot
Copy link
Contributor

@Adlai-Holler updated the pull request - view changes

@Adlai-Holler
Copy link
Contributor Author

@rnystrom Thanks for the review!

@coveralls
Copy link

coveralls commented Dec 29, 2016

Coverage Status

Coverage increased (+0.0007%) to 97.979% when pulling 2d60457 on Adlai-Holler:always-be-diffing into 5cd771b on Instagram:master.

@jessesquires jessesquires added this to the 2.1.0 milestone Dec 29, 2016
Copy link
Contributor

@jessesquires jessesquires left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, can we simplify this?

How about naming: allowsBackgroundReloading ?

Cocoa usually follows an "affirmative" naming style, i.e. prefersStatusBarHidden, hidesBottomBarWhenPushed, etc.

We'll need to invert the logic too.

@jessesquires
Copy link
Contributor

Marked this for 2.1.0 release.

@Adlai-Holler Adlai-Holler changed the title Add skipsDiffingWhenOffscreen Flag to ListAdapterUpdater to Give User Control of Behavior Add allowsBackgroundReloading Flag to ListAdapterUpdater to Give User Control of Behavior Dec 30, 2016
@facebook-github-bot
Copy link
Contributor

@Adlai-Holler updated the pull request - view changes

@facebook-github-bot
Copy link
Contributor

@Adlai-Holler updated the pull request - view changes

@coveralls
Copy link

coveralls commented Dec 30, 2016

Coverage Status

Coverage increased (+0.0007%) to 97.979% when pulling 4f588f4 on Adlai-Holler:always-be-diffing into 5cd771b on Instagram:master.

@coveralls
Copy link

coveralls commented Dec 30, 2016

Coverage Status

Coverage increased (+0.0007%) to 97.979% when pulling 4f588f4 on Adlai-Holler:always-be-diffing into 5cd771b on Instagram:master.

@jessesquires
Copy link
Contributor

Thanks @Adlai-Holler !

Can you check the box on the PR to "allow owners to edit" ? (something like that)

@Adlai-Holler
Copy link
Contributor Author

@jessesquires Done and done.

@facebook-github-bot
Copy link
Contributor

@Adlai-Holler updated the pull request - view changes

@facebook-github-bot
Copy link
Contributor

@Adlai-Holler updated the pull request - view changes

@facebook-github-bot
Copy link
Contributor

@Adlai-Holler updated the pull request - view changes

Copy link
Contributor

@jessesquires jessesquires left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome! 🌮 🎉

@coveralls
Copy link

coveralls commented Jan 2, 2017

Coverage Status

Coverage increased (+0.0007%) to 97.979% when pulling 808788e on Adlai-Holler:always-be-diffing into 5cd771b on Instagram:master.

@coveralls
Copy link

coveralls commented Jan 2, 2017

Coverage Status

Coverage increased (+0.0007%) to 97.979% when pulling 808788e on Adlai-Holler:always-be-diffing into 5cd771b on Instagram:master.

@coveralls
Copy link

coveralls commented Jan 2, 2017

Coverage Status

Coverage increased (+0.0007%) to 97.979% when pulling 808788e on Adlai-Holler:always-be-diffing into 5cd771b on Instagram:master.

@facebook-github-bot
Copy link
Contributor

@jessesquires has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@Adlai-Holler Adlai-Holler deleted the always-be-diffing branch January 3, 2017 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants