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

Renew supplementary node on relayout #842

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
929d118
fix SIMULATE_WEB_RESPONSE not imported #449
wsdwsd0829 Jul 16, 2017
dd24d8f
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Sep 6, 2017
b8eaffa
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Oct 4, 2017
2918ea0
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Oct 11, 2017
9c42266
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Oct 12, 2017
329f35f
Fix to make rangeMode update in right time
wsdwsd0829 Feb 5, 2018
5f8b7ec
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Feb 7, 2018
d87bb11
merge master from upstream
wsdwsd0829 Feb 15, 2018
269c2ab
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Mar 10, 2018
24c1ce8
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Mar 12, 2018
5b9acd4
Renew supplementary node on relayout.
wsdwsd0829 Mar 12, 2018
a4e4ba7
Add support for layoutDelegate (ASCollectionLayout).
wsdwsd0829 Mar 18, 2018
fcb4a05
revert space
wsdwsd0829 Mar 18, 2018
233169e
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Mar 26, 2018
d0e78dc
Update change log
wsdwsd0829 Mar 27, 2018
785d6fc
merge master
wsdwsd0829 Mar 27, 2018
19fc1e3
fix build error
wsdwsd0829 Apr 10, 2018
9f7cf47
Merge branch 'master' into renew-supplementary-node-on-relayout
Adlai-Holler May 26, 2018
327d65c
refactor
wsdwsd0829 May 29, 2018
90686fd
merge upstream
wsdwsd0829 May 29, 2018
1c7a7f6
merge upstream
wsdwsd0829 May 29, 2018
88db8b7
set default size
wsdwsd0829 May 29, 2018
5865ce7
Merge branch 'master' into renew-supplementary-node-on-relayout
wsdwsd0829 May 30, 2018
785c97a
Merge branch 'renew-supplementary-node-on-relayout' of github.com:wsd…
wsdwsd0829 May 30, 2018
811c5d0
return early when can delegate
wsdwsd0829 May 30, 2018
8ec0e25
Merge branch 'master' into renew-supplementary-node-on-relayout
wsdwsd0829 Jun 4, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## master
* Add your own contributions to the next release on the line below this with your name.
- [ASDataController] Add capability to renew supplementary views (update map) when size change from zero to non-zero.[Max Wang](https://github.com/wsdwsd0829) [#842](https://github.com/TextureGroup/Texture/pull/842)
- Make `ASPerformMainThreadDeallocation` visible in C. [Adlai Holler](https://github.com/Adlai-Holler)
- Add snapshot test for astextnode2. [Max Wang](https://github.com/wsdwsd0829) [#935](https://github.com/TextureGroup/Texture/pull/935)
- Internal housekeeping on the async transaction (rendering) system. [Adlai Holler](https://github.com/Adlai-Holler)
Expand Down
62 changes: 57 additions & 5 deletions Source/Details/ASDataController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#import <AsyncDisplayKit/ASCellNode.h>
#import <AsyncDisplayKit/ASCollectionElement.h>
#import <AsyncDisplayKit/ASCollectionLayoutContext.h>
#import <AsyncDisplayKit/ASCollectionLayoutState.h>
#import <AsyncDisplayKit/ASDispatch.h>
#import <AsyncDisplayKit/ASDisplayNodeExtras.h>
#import <AsyncDisplayKit/ASElementMap.h>
Expand Down Expand Up @@ -281,6 +282,50 @@ - (void)_repopulateSupplementaryNodesIntoMap:(ASMutableElementMap *)map
}
}

/**
* Update supplementary nodes of all kinds for sections.
*
* @param map The element map into which to apply the change.
* @param traitCollection The trait collection needed to initialize elements
* @param shouldFetchSizeRanges Whether constrained sizes should be fetched from data source
*/
- (void)_updateSupplementaryNodesIntoMap:(ASMutableElementMap *)map
traitCollection:(ASPrimitiveTraitCollection)traitCollection
shouldFetchSizeRanges:(BOOL)shouldFetchSizeRanges
previousMap:(ASElementMap *)previousMap
{
ASDisplayNodeAssertMainThread();
if (self.layoutDelegate != nil) {
// TODO: https://github.com/TextureGroup/Texture/issues/948
return;
}
NSUInteger sectionCount = [self itemCountsFromDataSource].size();
if (sectionCount > 0) {
NSIndexSet *sectionIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, sectionCount)];
ASSizeRange newSizeRange = ASSizeRangeZero;
for (NSString *kind in [self supplementaryKindsInSections:sectionIndexes]) {
NSArray<NSIndexPath *> *indexPaths = [self _allIndexPathsForItemsOfKind:kind inSections:sectionIndexes];
NSMutableArray<NSIndexPath *> *indexPathsToDeleteForKind = [[NSMutableArray alloc] init];
NSMutableArray<NSIndexPath *> *indexPathsToInsertForKind = [[NSMutableArray alloc] init];
// If supplementary node does exist and size is now zero, remove it.
// If supplementary node doesn't exist and size is now non-zero, insert one.
for (NSIndexPath *indexPath in indexPaths) {
ASCollectionElement *previousElement = [previousMap supplementaryElementOfKind:kind atIndexPath:indexPath];
newSizeRange = [self constrainedSizeForNodeOfKind:kind atIndexPath:indexPath];
BOOL sizeRangeIsZero = ASSizeRangeEqualToSizeRange(ASSizeRangeZero, newSizeRange);
if (previousElement != nil && sizeRangeIsZero) {
[indexPathsToDeleteForKind addObject:indexPath];
} else if (previousElement == nil && !sizeRangeIsZero) {
[indexPathsToInsertForKind addObject:indexPath];
}
}

[map removeSupplementaryElementsAtIndexPaths:indexPathsToDeleteForKind kind:kind];
[self _insertElementsIntoMap:map kind:kind atIndexPaths:indexPathsToInsertForKind traitCollection:traitCollection shouldFetchSizeRanges:shouldFetchSizeRanges changeSet:nil previousMap:previousMap];
}
}
}

/**
* Inserts new elements of a certain kind for some sections
*
Expand Down Expand Up @@ -830,13 +875,20 @@ - (void)relayoutAllNodesWithInvalidationBlock:(nullable void (^)())invalidationB
- (void)_relayoutAllNodes
{
ASDisplayNodeAssertMainThread();
// Aggressively repopulate all supplemtary elements
// Assuming this method is run on the main serial queue, _pending and _visible maps are synced and can be manipulated directly.
ASDisplayNodeAssert(_visibleMap == _pendingMap, @"Expected visible and pending maps to be synchronized: %@", self);

ASMutableElementMap *newMap = [_pendingMap mutableCopy];
[self _updateSupplementaryNodesIntoMap:newMap
traitCollection:[self.node primitiveTraitCollection]
shouldFetchSizeRanges:YES
previousMap:_pendingMap];
_pendingMap = [newMap copy];
_visibleMap = _pendingMap;

for (ASCollectionElement *element in _visibleMap) {
// Ignore this element if it is no longer in the latest data. It is still recognized in the UIKit world but will be deleted soon.
NSIndexPath *indexPathInPendingMap = [_pendingMap indexPathForElement:element];
if (indexPathInPendingMap == nil) {
continue;
}

NSString *kind = element.supplementaryElementKind ?: ASDataControllerRowNodeKind;
ASSizeRange newConstrainedSize = [self constrainedSizeForNodeOfKind:kind atIndexPath:indexPathInPendingMap];

Expand Down
2 changes: 2 additions & 0 deletions Source/Private/ASMutableElementMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ AS_SUBCLASSING_RESTRICTED

- (void)removeSectionsOfItems:(NSIndexSet *)itemSections;

- (void)removeSupplementaryElementsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths kind:(NSString *)kind;

- (void)insertEmptySectionsOfItemsAtIndexes:(NSIndexSet *)sections;

- (void)insertElement:(ASCollectionElement *)element atIndexPath:(NSIndexPath *)indexPath;
Expand Down
5 changes: 5 additions & 0 deletions Source/Private/ASMutableElementMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ - (void)removeSectionsAtIndexes:(NSIndexSet *)indexes
[_sections removeObjectsAtIndexes:indexes];
}

- (void)removeSupplementaryElementsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths kind:(NSString *)kind
{
[_supplementaryElements[kind] removeObjectsForKeys:indexPaths];
}

- (void)removeAllElements
{
[_sectionsOfItems removeAllObjects];
Expand Down