mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-05 04:10:16 +00:00
* Implement ASCollectionGalleryLayoutDelegate - It arranges items of the same size into a multi-line stack (say photo gallery or pager). It takes advantage of the fact that its items always have a fixed size to measure as few items as possible while still being able to track their positions at all time. This helps reduce startup/reloadData time, as well as memory footprint. - It then uses a measure range, which also works as a allocate range, to figure out which items to measure ahead of time. And it guarantees that each item is scheduled to measure only once. - Lastly, ASCollectionLayoutDelegate has some new methods that allow delegates to hook up and stay ahead of layout attributes requests from the backing view. ASCollectionGalleryLayoutDelegate for example uses these methods to ensure elements that have their layout attributes requested are always ready for consumption, and to measure more elements in the background. * Handle items that span multiple pages and other improvements in gallery delegate * Minor fixes * Fix failing tests * Fix custom collection example * Implement missing method in gallery layout delegate * Fix warnings * Some improvements - Collection layout delegates must have a crollable directions property. - Simplify gallery delegate by not storing unmeasured attributes since calling measure on already measured elements should be cache hits and super fast. - Abstact some code in gallery delegate to ASCollectionLayoutState+Private and _ASCollectionGalleryLayoutItem. - Other improvements in gallery delegate * Fix file licenses * Move measure range logic to ASCollectionLayout * Track unmeasured elements * Remove pending layout in ASCollectionLayout * Get back pending layout because the timing to latch new data is not ideal * Add ASCollectionLayoutCache * Fix file licenses * Fix xcodeproj * Add async collection layout to examples/ASCollectionView * Measure method in ASCollectionLayout to be a class method * Encourage more immutable states - Make -calculateLayoutWithContext: to be class methods in ASDataControllerLayoutDelegate and ASCollectionLayoutDelegate. - Add layout delegate class and layout cache to ASCollectionLayoutContext+Private, to be use by ASCollectionLayout only. - ASDataController no longer allocates all nodes but lets ASCollectionLayout determine. - Add scrollableDirections to the layout context since it's often needed by the layout pass. Otherwise users have to wrap it in an info object. - Update built-in layout delegates and CustomCollectionView example. - Publish ASHashing. It might be helpful for clients that implement custom collection info objects. * Remove additionalInfo property in ASCollectionLayoutState * ASCollectionLayoutState to correctly filter unmeasured elements * Add ASHashing to umbrella header * Fix file licenses * Add ASDispatchAsync and use it in ASCollectionLayout * Improve code comment in ASCollectionLayoutState
129 lines
4.1 KiB
Objective-C
129 lines
4.1 KiB
Objective-C
//
|
|
// ASPageTable.h
|
|
// Texture
|
|
//
|
|
// Copyright (c) 2017-present, Pinterest, Inc. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
|
|
#import <Foundation/Foundation.h>
|
|
#import <UIKit/UIKit.h>
|
|
#import <AsyncDisplayKit/ASAssert.h>
|
|
#import <AsyncDisplayKit/ASBaseDefines.h>
|
|
|
|
@class ASCollectionElement;
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
ASDISPLAYNODE_EXTERN_C_BEGIN
|
|
|
|
/**
|
|
* Represents x and y coordinates of a page.
|
|
*/
|
|
typedef uintptr_t ASPageCoordinate;
|
|
|
|
/**
|
|
* Returns a page coordinate with the given x and y values. Both of them must be less than 65,535.
|
|
*/
|
|
extern ASPageCoordinate ASPageCoordinateMake(uint16_t x, uint16_t y) AS_WARN_UNUSED_RESULT;
|
|
|
|
/**
|
|
* Returns coordinate of the page that contains the specified point.
|
|
* Similar to CGRectContainsPoint, a point is considered inside a page if its lie inside the page or on the minimum X or minimum Y edge.
|
|
*
|
|
* @param point The point that the page at the returned should contain. Any negative of the point will be corrected to 0.0
|
|
*
|
|
* @param pageSize The size of each page.
|
|
*/
|
|
extern ASPageCoordinate ASPageCoordinateForPageThatContainsPoint(CGPoint point, CGSize pageSize) AS_WARN_UNUSED_RESULT;
|
|
|
|
extern uint16_t ASPageCoordinateGetX(ASPageCoordinate pageCoordinate) AS_WARN_UNUSED_RESULT;
|
|
|
|
extern uint16_t ASPageCoordinateGetY(ASPageCoordinate pageCoordinate) AS_WARN_UNUSED_RESULT;
|
|
|
|
extern CGRect ASPageCoordinateGetPageRect(ASPageCoordinate pageCoordinate, CGSize pageSize) AS_WARN_UNUSED_RESULT;
|
|
|
|
/**
|
|
* Returns coordinate pointers for pages that intersect the specified rect. For each pointer, use ASPageCoordinateFromPointer() to get the original coordinate.
|
|
* The specified rect is restricted to the bounds of a content rect that has an origin of {0, 0} and a size of the given contentSize.
|
|
*
|
|
* @param rect The rect intersecting the target pages.
|
|
*
|
|
* @param contentSize The combined size of all pages.
|
|
*
|
|
* @param pageSize The size of each page.
|
|
*/
|
|
extern NSPointerArray * _Nullable ASPageCoordinatesForPagesThatIntersectRect(CGRect rect, CGSize contentSize, CGSize pageSize) AS_WARN_UNUSED_RESULT;
|
|
|
|
ASDISPLAYNODE_EXTERN_C_END
|
|
|
|
/**
|
|
* An alias for an NSMapTable created to store objects using ASPageCoordinates as keys.
|
|
*
|
|
* You should not call -objectForKey:, -setObject:forKey:, or -removeObjectForKey:
|
|
* on these objects.
|
|
*/
|
|
typedef NSMapTable ASPageTable;
|
|
|
|
/**
|
|
* A page to array of layout attributes table.
|
|
*/
|
|
typedef ASPageTable<id, NSMutableArray<UICollectionViewLayoutAttributes *> *> ASPageToLayoutAttributesTable;
|
|
|
|
/**
|
|
* A category for creating & using map tables meant for storing objects using ASPage as keys.
|
|
*/
|
|
@interface NSMapTable<id, ObjectType> (ASPageTableMethods)
|
|
|
|
/**
|
|
* Creates a new page table with (NSMapTableStrongMemory | NSMapTableObjectPointerPersonality) for values.
|
|
*/
|
|
+ (ASPageTable *)pageTableForStrongObjectPointers;
|
|
|
|
/**
|
|
* Creates a new page table with (NSMapTableWeakMemory | NSMapTableObjectPointerPersonality) for values.
|
|
*/
|
|
+ (ASPageTable *)pageTableForWeakObjectPointers;
|
|
|
|
/**
|
|
* Builds a new page to layout attributes from the given layout attributes.
|
|
*
|
|
* @param layoutAttributesEnumerator The layout attributes to build from
|
|
*
|
|
* @param contentSize The combined size of all pages.
|
|
*
|
|
* @param pageSize The size of each page.
|
|
*/
|
|
+ (ASPageToLayoutAttributesTable *)pageTableWithLayoutAttributes:(id<NSFastEnumeration>)layoutAttributesEnumerator contentSize:(CGSize)contentSize pageSize:(CGSize)pageSize;
|
|
|
|
/**
|
|
* Retrieves the object for a given page, or nil if the page is not found.
|
|
*
|
|
* @param page A page to lookup the object for.
|
|
*/
|
|
- (nullable ObjectType)objectForPage:(ASPageCoordinate)page;
|
|
|
|
/**
|
|
* Sets the given object for the associated page.
|
|
*
|
|
* @param object The object to store as value.
|
|
*
|
|
* @param page The page to use for the rect.
|
|
*/
|
|
- (void)setObject:(ObjectType)object forPage:(ASPageCoordinate)page;
|
|
|
|
/**
|
|
* Removes the object for the given page, if one exists.
|
|
*
|
|
* @param page The page to remove.
|
|
*/
|
|
- (void)removeObjectForPage:(ASPageCoordinate)page;
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|