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

Introduce ASCellLayoutMode #1273

Merged
merged 6 commits into from
Dec 10, 2018
Merged

Introduce ASCellLayoutMode #1273

merged 6 commits into from
Dec 10, 2018

Conversation

maicki
Copy link
Contributor

@maicki maicki commented Dec 7, 2018

ASCellLayoutModes are flexible settings for applications to improve the flexibility of integrating Texture within an app.
Providing this mode allows for developers to debug potential issues or work towards resolving technical debt in their collection view data source, while ramping up asynchronous collection layout.

@@ -10,6 +10,41 @@
#import <UIKit/UIKit.h>
#import <AsyncDisplayKit/ASBaseDefines.h>

typedef NS_OPTIONS(NSUInteger, ASCellLayoutMode) {
/** No options set. Default value. */
ASCellLayoutModeNone = 0,
Copy link
Member

Choose a reason for hiding this comment

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

Document the default behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried to clarify the default values for ASCellLayoutMode flags a bit better.

}
} else {
[super performBatchUpdates:updates completion:completion];
}
Copy link
Member

Choose a reason for hiding this comment

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

Why have this fork in two places i.e. here and also below at 1750 and 2214?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the two places we have a different logic when to perform a batch update or reload data. In rangeController:updateWithChangeSet:updates: besides checking for the ASCellLayoutModeAlwaysReloadData flag we also checking some more conditions to decide if we should reload data or batch update.

That said I removed the "automatic" behavior within _superPerformBatchUpdates:completion: and we are now explicitly calling if else in places where we would like to differentiate between the calls. It was not really obvious from a caller perspective that this automatic behavior exists in the first place.

@maicki
Copy link
Contributor Author

maicki commented Dec 7, 2018

@Adlai-Holler Can you please give it another look. Thanks!

@@ -869,17 +846,29 @@ - (CGSize)_sizeForUIKitCellWithKind:(NSString *)kind atIndexPath:(NSIndexPath *)
return size;
}

- (void)_superReloadData:(void(^)())updates completion:(void(^)(BOOL finished))completion
{
if (updates) {
Copy link
Member

Choose a reason for hiding this comment

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

Seems like the updates block should be non-nil. At the very least, we want to swap the maps. If it's non-nil, we can mark it that way and skip the nil check? The main point is I don't want people to think that it can ever be nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can be nil, if you just would like to call [super reloadData] with a completion block. I actually replaced all places where we call [super reloadData] with the call to _superReloadData so we have one central point to call in.

Copy link
Member

Choose a reason for hiding this comment

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

Oh yeah, I overlooked those calls. 👍

Source/ASCollectionViewProtocols.h Show resolved Hide resolved
Source/ASSectionController.h Show resolved Hide resolved
@@ -1049,6 +1049,7 @@ - (void)testInitialRangeBounds
UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
ASCollectionViewTestController *testController = [[ASCollectionViewTestController alloc] initWithNibName:nil bundle:nil];
ASCollectionNode *cn = testController.collectionNode;
cn.cellLayoutMode = ASCellLayoutModeAlwaysAsync;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we test the default behavior? Maybe add another test case if need to for this new mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! Added a test.

@@ -869,17 +846,29 @@ - (CGSize)_sizeForUIKitCellWithKind:(NSString *)kind atIndexPath:(NSIndexPath *)
return size;
}

- (void)_superReloadData:(void(^)())updates completion:(void(^)(BOOL finished))completion
{
if (updates) {
Copy link
Member

Choose a reason for hiding this comment

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

Oh yeah, I overlooked those calls. 👍

Source/ASSectionController.h Show resolved Hide resolved
Copy link
Member

@appleguy appleguy left a comment

Choose a reason for hiding this comment

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

More than a year in the making! Thanks a lot for cleaning this up before upstreaming...there was a lot of complexity you were able to drop, @maicki. Hopefully we'll thin this down even more in the coming months, but for now it is a great feeling to be fully (or very nearly) in sync with upstream.

@appleguy appleguy merged commit 82b4d34 into master Dec 10, 2018
@maicki maicki deleted the MSCellLayoutModes branch December 13, 2018 02:20
wsdwsd0829 pushed a commit to wsdwsd0829/Texture that referenced this pull request Mar 14, 2019
* Introduce ASCellLayoutMode

* Some smaller improvements

* Improve logic around _superPerformBatchUpdates:completion:

* Add comment about default values for ASCellLayoutModeNone

* Always call _superReloadData:completion: within UICollectionView

* Add initial range test for ASCellLayoutModeNone
wsdwsd0829 pushed a commit to wsdwsd0829/Texture that referenced this pull request Mar 15, 2019
* Introduce ASCellLayoutMode

* Some smaller improvements

* Improve logic around _superPerformBatchUpdates:completion:

* Add comment about default values for ASCellLayoutModeNone

* Always call _superReloadData:completion: within UICollectionView

* Add initial range test for ASCellLayoutModeNone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants