Swiftgram/Source/Details/ASCollectionLayoutState.h
appleguy 465abb1ded [License] Simplify the Texture license to be pure Apache 2 (removing ASDK-Licenses). (#1077)
* [License] Simplify the Texture license to be pure Apache 2 (removing ASDK-Licenses)

With permission of the Facebook Open Source team, we are simplifying the Texture
license so that clients can rely on the Apache 2 terms that most of Texture is
already covered by. This means that code originally forked from AsyncDisplayKit
will be re-licensed from "BSD 3-clause + PATENTS v2" to Apache 2 without a
PATENTS file.

After getting confirmation that the updates to these core files look good, we'll
propagate this new license header to all files (in this same PR) and get sign-off
from all parties before landing.

* [License] Update all Texture source files to be pure Apache 2.

* Changelog entry for Apache 2 license update.

* Revert "[License] Update all Texture source files to be pure Apache 2."

This reverts commit ffa0fbbba9717d871dd16c4b07539f2f8208fc2b.

* [License] Update all Texture source files to be pure Apache 2, maintaining copyrights.

* [License] Update CONTRIBUTING, README, Podspec & Dangerfile.
2018-08-28 07:39:18 -07:00

112 lines
3.6 KiB
Objective-C

//
// ASCollectionLayoutState.h
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <AsyncDisplayKit/ASBaseDefines.h>
@class ASCollectionLayoutContext, ASLayout, ASCollectionElement;
NS_ASSUME_NONNULL_BEGIN
typedef ASCollectionElement * _Nullable (^ASCollectionLayoutStateGetElementBlock)(ASLayout *);
@interface NSMapTable (ASCollectionLayoutConvenience)
+ (NSMapTable<ASCollectionElement *, UICollectionViewLayoutAttributes *> *)elementToLayoutAttributesTable;
@end
AS_SUBCLASSING_RESTRICTED
/// An immutable state of the collection layout
@interface ASCollectionLayoutState : NSObject
/// The context used to calculate this object
@property (readonly) ASCollectionLayoutContext *context;
/// The final content size of the collection's layout
@property (readonly) CGSize contentSize;
- (instancetype)init NS_UNAVAILABLE;
/**
* Designated initializer.
*
* @param context The context used to calculate this object
*
* @param contentSize The content size of the collection's layout
*
* @param table A map between elements to their layout attributes. It must contain all elements.
* It should have NSMapTableObjectPointerPersonality and NSMapTableWeakMemory as key options.
*/
- (instancetype)initWithContext:(ASCollectionLayoutContext *)context
contentSize:(CGSize)contentSize
elementToLayoutAttributesTable:(NSMapTable<ASCollectionElement *, UICollectionViewLayoutAttributes *> *)table NS_DESIGNATED_INITIALIZER;
/**
* Convenience initializer. Returns an object with zero content size and an empty table.
*
* @param context The context used to calculate this object
*/
- (instancetype)initWithContext:(ASCollectionLayoutContext *)context;
/**
* Convenience initializer.
*
* @param context The context used to calculate this object
*
* @param layout The layout describes size and position of all elements.
*
* @param getElementBlock A block that can retrieve the collection element from a sublayout of the root layout.
*/
- (instancetype)initWithContext:(ASCollectionLayoutContext *)context
layout:(ASLayout *)layout
getElementBlock:(ASCollectionLayoutStateGetElementBlock)getElementBlock;
/**
* Returns all layout attributes present in this object.
*/
- (NSArray<UICollectionViewLayoutAttributes *> *)allLayoutAttributes;
/**
* Returns layout attributes of elements in the specified rect.
*
* @param rect The rect containing the target elements.
*/
- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect;
/**
* Returns layout attributes of the element at the specified index path.
*
* @param indexPath The index path of the item.
*/
- (nullable UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath;
/**
* Returns layout attributes of the specified supplementary element.
*
* @param kind A string that identifies the type of the supplementary element.
*
* @param indexPath The index path of the element.
*/
- (nullable UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath;
/**
* Returns layout attributes of the specified element.
*
* @element The element.
*/
- (nullable UICollectionViewLayoutAttributes *)layoutAttributesForElement:(ASCollectionElement *)element;
@end
NS_ASSUME_NONNULL_END