Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Rename ASCollectionContentAttributes to ASCollectionLayoutState
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhuy committed Apr 3, 2017
1 parent 28eb7e4 commit cb91a60
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 56 deletions.
16 changes: 8 additions & 8 deletions AsyncDisplayKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@
E5B078001E69F4EB00C24B5B /* ASElementMap.m in Sources */ = {isa = PBXBuildFile; fileRef = E5B077FE1E69F4EB00C24B5B /* ASElementMap.m */; };
E5B0780C1E6A01E200C24B5B /* ASCollectionFlowLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = E5B0780A1E6A01E200C24B5B /* ASCollectionFlowLayout.h */; settings = {ATTRIBUTES = (Public, ); }; };
E5B0780D1E6A01E200C24B5B /* ASCollectionFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = E5B0780B1E6A01E200C24B5B /* ASCollectionFlowLayout.m */; };
E5E281741E71C833006B67C2 /* ASCollectionContentAttributes.h in Headers */ = {isa = PBXBuildFile; fileRef = E5E281731E71C833006B67C2 /* ASCollectionContentAttributes.h */; };
E5E281761E71C845006B67C2 /* ASCollectionContentAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = E5E281751E71C845006B67C2 /* ASCollectionContentAttributes.m */; };
E5E281741E71C833006B67C2 /* ASCollectionLayoutState.h in Headers */ = {isa = PBXBuildFile; fileRef = E5E281731E71C833006B67C2 /* ASCollectionLayoutState.h */; };
E5E281761E71C845006B67C2 /* ASCollectionLayoutState.m in Sources */ = {isa = PBXBuildFile; fileRef = E5E281751E71C845006B67C2 /* ASCollectionLayoutState.m */; };
F711994E1D20C21100568860 /* ASDisplayNodeExtrasTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F711994D1D20C21100568860 /* ASDisplayNodeExtrasTests.m */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -799,8 +799,8 @@
E5B077FE1E69F4EB00C24B5B /* ASElementMap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASElementMap.m; sourceTree = "<group>"; };
E5B0780A1E6A01E200C24B5B /* ASCollectionFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASCollectionFlowLayout.h; sourceTree = "<group>"; };
E5B0780B1E6A01E200C24B5B /* ASCollectionFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASCollectionFlowLayout.m; sourceTree = "<group>"; };
E5E281731E71C833006B67C2 /* ASCollectionContentAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASCollectionContentAttributes.h; sourceTree = "<group>"; };
E5E281751E71C845006B67C2 /* ASCollectionContentAttributes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASCollectionContentAttributes.m; sourceTree = "<group>"; };
E5E281731E71C833006B67C2 /* ASCollectionLayoutState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASCollectionLayoutState.h; sourceTree = "<group>"; };
E5E281751E71C845006B67C2 /* ASCollectionLayoutState.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASCollectionLayoutState.m; sourceTree = "<group>"; };
EFA731F0396842FF8AB635EE /* libPods-AsyncDisplayKitTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-AsyncDisplayKitTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
F711994D1D20C21100568860 /* ASDisplayNodeExtrasTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASDisplayNodeExtrasTests.m; sourceTree = "<group>"; };
FB07EABBCF28656C6297BC2D /* Pods-AsyncDisplayKitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AsyncDisplayKitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AsyncDisplayKitTests/Pods-AsyncDisplayKitTests.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1413,8 +1413,8 @@
E5B077EB1E6843AF00C24B5B /* Collection Layout */ = {
isa = PBXGroup;
children = (
E5E281731E71C833006B67C2 /* ASCollectionContentAttributes.h */,
E5E281751E71C845006B67C2 /* ASCollectionContentAttributes.m */,
E5E281731E71C833006B67C2 /* ASCollectionLayoutState.h */,
E5E281751E71C845006B67C2 /* ASCollectionLayoutState.m */,
E5B077E11E6843A600C24B5B /* ASCollectionLayout.h */,
E597E3C51E817B2800451596 /* ASCollectionLayout+Subclasses.h */,
E5B077F41E68576B00C24B5B /* ASCollectionLayout.mm */,
Expand Down Expand Up @@ -1566,7 +1566,7 @@
AC6145411D8AFAE8003D62A2 /* ASSection.h in Headers */,
8BBBAB8C1CEBAF1700107FC6 /* ASDefaultPlaybackButton.h in Headers */,
690ED5991E36D118000627C0 /* ASImageNode+tvOS.h in Headers */,
E5E281741E71C833006B67C2 /* ASCollectionContentAttributes.h in Headers */,
E5E281741E71C833006B67C2 /* ASCollectionLayoutState.h in Headers */,
254C6B741BF94DF4003EC431 /* ASTextNodeWordKerner.h in Headers */,
698DFF441E36B6C9002891F1 /* ASStackLayoutSpecUtilities.h in Headers */,
CCF18FF41D2575E300DF5895 /* NSIndexSet+ASHelpers.h in Headers */,
Expand Down Expand Up @@ -1935,7 +1935,7 @@
68355B341CB579B9001D4E68 /* ASImageNode+AnimatedImage.mm in Sources */,
E5711A301C840C96009619D4 /* ASCollectionElement.mm in Sources */,
B35062511B010EFD0018CF92 /* ASDisplayNode+UIViewBridge.mm in Sources */,
E5E281761E71C845006B67C2 /* ASCollectionContentAttributes.m in Sources */,
E5E281761E71C845006B67C2 /* ASCollectionLayoutState.m in Sources */,
B35061FC1B010EFD0018CF92 /* ASDisplayNode.mm in Sources */,
B35061FF1B010EFD0018CF92 /* ASDisplayNodeExtras.mm in Sources */,
B35062011B010EFD0018CF92 /* ASEditableTextNode.mm in Sources */,
Expand Down
18 changes: 9 additions & 9 deletions Source/Details/ASCollectionFlowLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import <AsyncDisplayKit/ASCollectionLayout+Subclasses.h>

#import <AsyncDisplayKit/ASCellNode.h>
#import <AsyncDisplayKit/ASCollectionContentAttributes.h>
#import <AsyncDisplayKit/ASCollectionLayoutState.h>
#import <AsyncDisplayKit/ASCollectionElement.h>
#import <AsyncDisplayKit/ASCollectionLayoutHelpers.h>
#import <AsyncDisplayKit/ASDataControllerLayoutContext.h>
Expand Down Expand Up @@ -53,12 +53,12 @@ - (ASSizeRange)sizeRangeThatFits:(CGSize)viewportSize
return sizeRange;
}

- (ASCollectionContentAttributes *)calculateLayoutForLayoutContext:(ASDataControllerLayoutContext *)context
- (ASCollectionLayoutState *)calculateLayoutForLayoutContext:(ASDataControllerLayoutContext *)context
{
ASElementMap *elementMap = context.elementMap;
NSMutableArray<ASCellNode *> *children = ASArrayByFlatMapping(elementMap.itemElements, ASCollectionElement *element, element.node);
if (children.count == 0) {
return [[ASCollectionContentAttributes alloc] initWithElementMap:elementMap
return [[ASCollectionLayoutState alloc] initWithElementMap:elementMap
contentSize:CGSizeZero
elementToLayoutArrtibutesMap:[NSMapTable weakToStrongObjectsMapTable]];
}
Expand Down Expand Up @@ -90,16 +90,16 @@ - (ASCollectionContentAttributes *)calculateLayoutForLayoutContext:(ASDataContro

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
ASCollectionContentAttributes *content = self.currentContentAttributes;
ASCollectionElement *element = [content.elementMap elementForItemAtIndexPath:indexPath];
return [content.elementToLayoutArrtibutesMap objectForKey:element];
ASCollectionLayoutState *state = self.currentContentAttributes;
ASCollectionElement *element = [state.elementMap elementForItemAtIndexPath:indexPath];
return [state.elementToLayoutArrtibutesMap objectForKey:element];
}

- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath
{
ASCollectionContentAttributes *content = self.currentContentAttributes;
ASCollectionElement *element = [content.elementMap supplementaryElementOfKind:elementKind atIndexPath:indexPath];
return [content.elementToLayoutArrtibutesMap objectForKey:element];
ASCollectionLayoutState *state = self.currentContentAttributes;
ASCollectionElement *element = [state.elementMap supplementaryElementOfKind:elementKind atIndexPath:indexPath];
return [state.elementToLayoutArrtibutesMap objectForKey:element];
}

- (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath
Expand Down
8 changes: 4 additions & 4 deletions Source/Details/ASCollectionLayout+Subclasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#import <AsyncDisplayKit/ASCollectionLayout.h>
#import <AsyncDisplayKit/ASDataController+Beta.h>

@class ASCollectionContentAttributes;
@class ASCollectionLayoutState;

NS_ASSUME_NONNULL_BEGIN

@interface ASCollectionLayout () <ASDataControllerLayoutDelegate>

/// The current content, if any. This property must be accessed on main thread.
@property (nonatomic, strong, nullable) ASCollectionContentAttributes *currentContentAttributes;
/// The current state of this layout object, if any. This property must be accessed on main thread.
@property (nonatomic, strong, nullable) ASCollectionLayoutState *state;

/**
* @abstract Prepares and returns a new layout for given context.
Expand All @@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @discussion This method must block its calling thread but can dispatch to other theads to reduce blocking time.
*/
- (ASCollectionContentAttributes *)calculateLayoutForLayoutContext:(ASDataControllerLayoutContext *)context;
- (ASCollectionLayoutState *)calculateLayoutForLayoutContext:(ASDataControllerLayoutContext *)context;

@end

Expand Down
50 changes: 25 additions & 25 deletions Source/Details/ASCollectionLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#import <AsyncDisplayKit/ASAssert.h>
#import <AsyncDisplayKit/ASCollectionElement.h>
#import <AsyncDisplayKit/ASCollectionContentAttributes.h>
#import <AsyncDisplayKit/ASCollectionLayoutState.h>
#import <AsyncDisplayKit/ASCollectionNode.h>
#import <AsyncDisplayKit/ASDataControllerLayoutContext.h>
#import <AsyncDisplayKit/ASDisplayNode+FrameworkPrivate.h>
Expand All @@ -23,12 +23,12 @@ @interface ASCollectionLayout () {
ASDN::Mutex __instanceLock__; // Non-recursive mutex, ftw!

// Main thread only.
ASCollectionContentAttributes *_currentContentAttributes;
ASCollectionLayoutState *_state;

// The pending content calculated ahead of time, if any.
ASCollectionContentAttributes *_pendingContentAttributes;
// The context used to calculate _pendingContentAttributes
ASDataControllerLayoutContext *_layoutContextForPendingContentAttributes;
// The pending state calculated ahead of time, if any.
ASCollectionLayoutState *_pendingState;
// The context used to calculate _pendingState
ASDataControllerLayoutContext *_layoutContextForPendingState;
}

@end
Expand All @@ -40,17 +40,17 @@ - (instancetype)init
return [super init];
}

- (ASCollectionContentAttributes *)currentContentAttributes
- (ASCollectionLayoutState *)state
{
ASDisplayNodeAssertMainThread();
return _currentContentAttributes;
return _state;
}

- (void)setCurrentContentAttributes:(ASCollectionContentAttributes *)newAttrs
- (void)setState:(ASCollectionLayoutState *)newState
{
ASDisplayNodeAssertMainThread();
if (! ASObjectIsEqual(_currentContentAttributes, newAttrs)) {
_currentContentAttributes = newAttrs;
if (! ASObjectIsEqual(_state, newState)) {
_state = newState;
}
}

Expand All @@ -64,11 +64,11 @@ - (ASDataControllerLayoutContext *)layoutContextWithElementMap:(ASElementMap *)m

- (void)prepareLayoutForLayoutContext:(ASDataControllerLayoutContext *)context
{
ASCollectionContentAttributes *attrs = [self calculateLayoutForLayoutContext:context];
ASCollectionLayoutState *state = [self calculateLayoutForLayoutContext:context];

ASDN::MutexLocker l(__instanceLock__);
_pendingContentAttributes = attrs;
_layoutContextForPendingContentAttributes = context;
_pendingState = state;
_layoutContextForPendingState = context;
}

#pragma mark - UICollectionViewLayout overrides
Expand All @@ -78,40 +78,40 @@ - (void)prepareLayout
ASDisplayNodeAssertMainThread();
ASDataControllerLayoutContext *context = [self layoutContextWithElementMap:[_dataSource elementMapForCollectionLayout:self]];

ASCollectionContentAttributes *attrs;
ASCollectionLayoutState *state;
{
ASDN::MutexLocker l(__instanceLock__);
if (_pendingContentAttributes != nil && ASObjectIsEqual(_layoutContextForPendingContentAttributes, context)) {
if (_pendingState != nil && ASObjectIsEqual(_layoutContextForPendingState, context)) {
// Looks like we can use the pending attrs. Great!
attrs = _pendingContentAttributes;
_pendingContentAttributes = nil;
_layoutContextForPendingContentAttributes = nil;
state = _pendingState;
_pendingState = nil;
_layoutContextForPendingState = nil;
}
}

if (attrs == nil) {
attrs = [self calculateLayoutForLayoutContext:context];
if (state == nil) {
state = [self calculateLayoutForLayoutContext:context];
}

_currentContentAttributes = attrs;
_state = state;
}

- (void)invalidateLayout
{
ASDisplayNodeAssertMainThread();
[super invalidateLayout];
_currentContentAttributes = nil;
_state = nil;
}

- (CGSize)collectionViewContentSize
{
ASDisplayNodeAssertMainThread();
return _currentContentAttributes.contentSize;
return _state.contentSize;
}

#pragma mark - Subclass hooks

- (ASCollectionContentAttributes *)calculateLayoutForLayoutContext:(ASDataControllerLayoutContext *)context
- (ASCollectionLayoutState *)calculateLayoutForLayoutContext:(ASDataControllerLayoutContext *)context
{
// Subclass hooks
ASDisplayNodeAssertLockUnownedByCurrentThread(__instanceLock__);
Expand Down
4 changes: 2 additions & 2 deletions Source/Details/ASCollectionLayoutHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

#import <AsyncDisplayKit/ASBaseDefines.h>

@class ASCollectionContentAttributes, ASLayout, ASElementMap;
@class ASCollectionLayoutState, ASLayout, ASElementMap;

extern AS_WARN_UNUSED_RESULT ASCollectionContentAttributes *ASLayoutToCollectionContentAttributes(ASLayout *layout, ASElementMap *elementMap);
extern AS_WARN_UNUSED_RESULT ASCollectionLayoutState *ASLayoutToCollectionContentAttributes(ASLayout *layout, ASElementMap *elementMap);
6 changes: 3 additions & 3 deletions Source/Details/ASCollectionLayoutHelpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#import <AsyncDisplayKit/ASCollectionLayoutHelpers.h>

#import <AsyncDisplayKit/ASCellNode+Internal.h>
#import <AsyncDisplayKit/ASCollectionContentAttributes.h>
#import <AsyncDisplayKit/ASCollectionLayoutState.h>
#import <AsyncDisplayKit/ASCollectionElement.h>
#import <AsyncDisplayKit/ASElementMap.h>
#import <AsyncDisplayKit/ASLayout.h>

ASCollectionContentAttributes *ASLayoutToCollectionContentAttributes(ASLayout *layout, ASElementMap *elementMap)
ASCollectionLayoutState *ASLayoutToCollectionContentAttributes(ASLayout *layout, ASElementMap *elementMap)
{
NSMapTable<ASCollectionElement *, UICollectionViewLayoutAttributes *> *attrsMap = [NSMapTable weakToStrongObjectsMapTable];
for (ASLayout *sublayout in layout.sublayouts) {
Expand All @@ -32,6 +32,6 @@
[attrsMap setObject:attrs forKey:element];
}

return [[ASCollectionContentAttributes alloc] initWithElementMap:elementMap contentSize:layout.size elementToLayoutArrtibutesMap:attrsMap];
return [[ASCollectionLayoutState alloc] initWithElementMap:elementMap contentSize:layout.size elementToLayoutArrtibutesMap:attrsMap];
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ASCollectionContentAttributes.h
// ASCollectionLayoutState.h
// AsyncDisplayKit
//
// Created by Huy Nguyen on 9/3/17.
Expand All @@ -15,7 +15,7 @@
NS_ASSUME_NONNULL_BEGIN

AS_SUBCLASSING_RESTRICTED
@interface ASCollectionContentAttributes : NSObject
@interface ASCollectionLayoutState : NSObject

/// The element map used to calculate this object
@property (nonatomic, weak, readonly) ASElementMap *elementMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//
// ASCollectionContentAttributes.m
// ASCollectionLayoutState.m
// AsyncDisplayKit
//
// Created by Huy Nguyen on 9/3/17.
// Copyright © 2017 Facebook. All rights reserved.
//

#import <AsyncDisplayKit/ASCollectionContentAttributes.h>
#import <AsyncDisplayKit/ASCollectionLayoutState.h>
#import <AsyncDisplayKit/ASAssert.h>
#import <AsyncDisplayKit/ASElementMap.h>

@implementation ASCollectionContentAttributes
@implementation ASCollectionLayoutState

- (instancetype)initWithElementMap:(ASElementMap *)elementMap contentSize:(CGSize)contentSize elementToLayoutArrtibutesMap:(NSMapTable<ASCollectionElement *,UICollectionViewLayoutAttributes *> *)attrsMap
{
Expand Down

0 comments on commit cb91a60

Please sign in to comment.