mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-21 13:50:29 +00:00
ASCollectionLayout to exclude content inset on scrollable directions from viewport size (#562)
This commit is contained in:
parent
fcee108af5
commit
7c7a4acf0e
@ -10,7 +10,7 @@
|
|||||||
- Negate iOS 11 automatic estimated table row heights. [Christian Selig](https://github.com/christianselig) [#485](https://github.com/TextureGroup/Texture/pull/485)
|
- Negate iOS 11 automatic estimated table row heights. [Christian Selig](https://github.com/christianselig) [#485](https://github.com/TextureGroup/Texture/pull/485)
|
||||||
- Add content inset and offset bridging properties to ASTableNode and ASCollectionNode. Deprecate related properties and methods in ASTableView and ASCollectionView [Huy Nguyen](https://github.com/nguyenhuy) [#460](https://github.com/TextureGroup/Texture/pull/460) [#560](https://github.com/TextureGroup/Texture/pull/560)
|
- Add content inset and offset bridging properties to ASTableNode and ASCollectionNode. Deprecate related properties and methods in ASTableView and ASCollectionView [Huy Nguyen](https://github.com/nguyenhuy) [#460](https://github.com/TextureGroup/Texture/pull/460) [#560](https://github.com/TextureGroup/Texture/pull/560)
|
||||||
- Remove re-entrant access to self.view when applying initial pending state. [Adlai Holler](https://github.com/Adlai-Holler) [#510](https://github.com/TextureGroup/Texture/pull/510)
|
- Remove re-entrant access to self.view when applying initial pending state. [Adlai Holler](https://github.com/Adlai-Holler) [#510](https://github.com/TextureGroup/Texture/pull/510)
|
||||||
- Small improvements in ASCollectionLayout [Huy Nguyen](https://github.com/nguyenhuy) [#509](https://github.com/TextureGroup/Texture/pull/509) [#513](https://github.com/TextureGroup/Texture/pull/513)
|
- Small improvements in ASCollectionLayout [Huy Nguyen](https://github.com/nguyenhuy) [#509](https://github.com/TextureGroup/Texture/pull/509) [#513](https://github.com/TextureGroup/Texture/pull/513) [#562]((https://github.com/TextureGroup/Texture/pull/562)
|
||||||
- Fix retain cycle between ASImageNode and PINAnimatedImage [Phil Larson](https://github.com/plarson) [#520](https://github.com/TextureGroup/Texture/pull/520)
|
- Fix retain cycle between ASImageNode and PINAnimatedImage [Phil Larson](https://github.com/plarson) [#520](https://github.com/TextureGroup/Texture/pull/520)
|
||||||
- Change the API for disabling logging from a compiler flag to a runtime C function ASDisableLogging(). [Adlai Holler](https://github.com/Adlai-Holler) [#528](https://github.com/TextureGroup/Texture/pull/528)
|
- Change the API for disabling logging from a compiler flag to a runtime C function ASDisableLogging(). [Adlai Holler](https://github.com/Adlai-Holler) [#528](https://github.com/TextureGroup/Texture/pull/528)
|
||||||
- Table and collection views to consider content inset when calculating (default) element size range [Huy Nguyen](https://github.com/nguyenhuy) [#525](https://github.com/TextureGroup/Texture/pull/525)
|
- Table and collection views to consider content inset when calculating (default) element size range [Huy Nguyen](https://github.com/nguyenhuy) [#525](https://github.com/TextureGroup/Texture/pull/525)
|
||||||
|
|||||||
@ -69,18 +69,35 @@ static const ASScrollDirection kASStaticScrollDirection = (ASScrollDirectionRigh
|
|||||||
- (ASCollectionLayoutContext *)layoutContextWithElements:(ASElementMap *)elements
|
- (ASCollectionLayoutContext *)layoutContextWithElements:(ASElementMap *)elements
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertMainThread();
|
ASDisplayNodeAssertMainThread();
|
||||||
CGSize viewportSize = [self _viewportSize];
|
|
||||||
CGPoint contentOffset = _collectionNode.contentOffset;
|
Class<ASCollectionLayoutDelegate> layoutDelegateClass = [_layoutDelegate class];
|
||||||
|
ASCollectionLayoutCache *layoutCache = _layoutCache;
|
||||||
|
ASCollectionNode *collectionNode = _collectionNode;
|
||||||
|
if (collectionNode == nil) {
|
||||||
|
return [[ASCollectionLayoutContext alloc] initWithViewportSize:CGSizeZero
|
||||||
|
initialContentOffset:CGPointZero
|
||||||
|
scrollableDirections:ASScrollDirectionNone
|
||||||
|
elements:[[ASElementMap alloc] init]
|
||||||
|
layoutDelegateClass:layoutDelegateClass
|
||||||
|
layoutCache:layoutCache
|
||||||
|
additionalInfo:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
ASScrollDirection scrollableDirections = [_layoutDelegate scrollableDirections];
|
||||||
|
CGSize viewportSize = [ASCollectionLayout _viewportSizeForCollectionNode:collectionNode scrollableDirections:scrollableDirections];
|
||||||
|
CGPoint contentOffset = collectionNode.contentOffset;
|
||||||
|
|
||||||
id additionalInfo = nil;
|
id additionalInfo = nil;
|
||||||
if (_layoutDelegateFlags.implementsAdditionalInfoForLayoutWithElements) {
|
if (_layoutDelegateFlags.implementsAdditionalInfoForLayoutWithElements) {
|
||||||
additionalInfo = [_layoutDelegate additionalInfoForLayoutWithElements:elements];
|
additionalInfo = [_layoutDelegate additionalInfoForLayoutWithElements:elements];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [[ASCollectionLayoutContext alloc] initWithViewportSize:viewportSize
|
return [[ASCollectionLayoutContext alloc] initWithViewportSize:viewportSize
|
||||||
initialContentOffset:contentOffset
|
initialContentOffset:contentOffset
|
||||||
scrollableDirections:[_layoutDelegate scrollableDirections]
|
scrollableDirections:scrollableDirections
|
||||||
elements:elements
|
elements:elements
|
||||||
layoutDelegateClass:[_layoutDelegate class]
|
layoutDelegateClass:layoutDelegateClass
|
||||||
layoutCache:_layoutCache
|
layoutCache:layoutCache
|
||||||
additionalInfo:additionalInfo];
|
additionalInfo:additionalInfo];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,21 +225,41 @@ static const ASScrollDirection kASStaticScrollDirection = (ASScrollDirectionRigh
|
|||||||
|
|
||||||
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
|
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
|
||||||
{
|
{
|
||||||
return (! CGSizeEqualToSize([self _viewportSize], newBounds.size));
|
return (! CGSizeEqualToSize([ASCollectionLayout _boundsForCollectionNode:_collectionNode], newBounds.size));
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Private methods
|
#pragma mark - Private methods
|
||||||
|
|
||||||
- (CGSize)_viewportSize
|
+ (CGSize)_boundsForCollectionNode:(nonnull ASCollectionNode *)collectionNode
|
||||||
{
|
{
|
||||||
ASCollectionNode *collectionNode = _collectionNode;
|
if (collectionNode == nil) {
|
||||||
if (collectionNode != nil && !collectionNode.isNodeLoaded) {
|
return CGSizeZero;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!collectionNode.isNodeLoaded) {
|
||||||
// TODO consider calculatedSize as well
|
// TODO consider calculatedSize as well
|
||||||
return collectionNode.threadSafeBounds.size;
|
return collectionNode.threadSafeBounds.size;
|
||||||
} else {
|
|
||||||
ASDisplayNodeAssertMainThread();
|
|
||||||
return self.collectionView.bounds.size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASDisplayNodeAssertMainThread();
|
||||||
|
return collectionNode.view.bounds.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (CGSize)_viewportSizeForCollectionNode:(nonnull ASCollectionNode *)collectionNode scrollableDirections:(ASScrollDirection)scrollableDirections
|
||||||
|
{
|
||||||
|
if (collectionNode == nil) {
|
||||||
|
return CGSizeZero;
|
||||||
|
}
|
||||||
|
|
||||||
|
CGSize result = [ASCollectionLayout _boundsForCollectionNode:collectionNode];
|
||||||
|
// TODO: Consider using adjustedContentInset on iOS 11 and later, to include the safe area of the scroll view
|
||||||
|
UIEdgeInsets contentInset = collectionNode.contentInset;
|
||||||
|
if (ASScrollDirectionContainsHorizontalDirection(scrollableDirections)) {
|
||||||
|
result.height -= (contentInset.top + contentInset.bottom);
|
||||||
|
} else {
|
||||||
|
result.width -= (contentInset.left + contentInset.right);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user