mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-15 16:36:36 +00:00
[ASScrollNode] Add .scrollDirection property so that internal content sizing can be easily "unlimited" in the direction of scrolling. (#3001)
This commit is contained in:
parent
ada553c5a7
commit
ca8fcdfe49
@ -9,6 +9,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <AsyncDisplayKit/ASDisplayNode.h>
|
#import <AsyncDisplayKit/ASDisplayNode.h>
|
||||||
|
#import <AsyncDisplayKit/ASScrollDirection.h>
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@ -33,6 +34,18 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
*/
|
*/
|
||||||
@property (nonatomic, assign) BOOL automaticallyManagesContentSize;
|
@property (nonatomic, assign) BOOL automaticallyManagesContentSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @abstract This property controls how the constrainedSize is interpreted when sizing the content.
|
||||||
|
* if you are using automaticallyManagesContentSize, it can be crucial to ensure that the sizing is
|
||||||
|
* done how you expect.
|
||||||
|
* Vertical: The constrainedSize is interpreted as having unbounded .height (CGFLOAT_MAX), allowing
|
||||||
|
* stacks and other content in the layout spec to expand and result in scrollable content.
|
||||||
|
* Horizontal: The constrainedSize is interpreted as having unbounded .width (CGFLOAT_MAX), ...
|
||||||
|
* Vertical & Horizontal: the constrainedSize is interpreted as unbounded in both directions.
|
||||||
|
* @default ASScrollDirectionVerticalDirections
|
||||||
|
*/
|
||||||
|
@property (nonatomic, assign) ASScrollDirection scrollableDirections;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
@ -56,6 +56,7 @@
|
|||||||
|
|
||||||
@implementation ASScrollNode
|
@implementation ASScrollNode
|
||||||
{
|
{
|
||||||
|
ASScrollDirection _scrollableDirections;
|
||||||
BOOL _automaticallyManagesContentSize;
|
BOOL _automaticallyManagesContentSize;
|
||||||
CGSize _contentCalculatedSizeFromLayout;
|
CGSize _contentCalculatedSizeFromLayout;
|
||||||
}
|
}
|
||||||
@ -70,12 +71,20 @@
|
|||||||
restrictedToSize:(ASLayoutElementSize)size
|
restrictedToSize:(ASLayoutElementSize)size
|
||||||
relativeToParentSize:(CGSize)parentSize
|
relativeToParentSize:(CGSize)parentSize
|
||||||
{
|
{
|
||||||
ASLayout *layout = [super calculateLayoutThatFits:constrainedSize
|
ASDN::MutexLocker l(__instanceLock__); // Lock for using our instance variables.
|
||||||
|
|
||||||
|
ASSizeRange contentConstrainedSize = constrainedSize;
|
||||||
|
if (ASScrollDirectionContainsVerticalDirection(_scrollableDirections)) {
|
||||||
|
contentConstrainedSize.max.height = CGFLOAT_MAX;
|
||||||
|
}
|
||||||
|
if (ASScrollDirectionContainsHorizontalDirection(_scrollableDirections)) {
|
||||||
|
contentConstrainedSize.max.width = CGFLOAT_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASLayout *layout = [super calculateLayoutThatFits:contentConstrainedSize
|
||||||
restrictedToSize:size
|
restrictedToSize:size
|
||||||
relativeToParentSize:parentSize];
|
relativeToParentSize:parentSize];
|
||||||
|
|
||||||
ASDN::MutexLocker l(__instanceLock__); // Lock for using our two instance variables.
|
|
||||||
|
|
||||||
if (_automaticallyManagesContentSize) {
|
if (_automaticallyManagesContentSize) {
|
||||||
// To understand this code, imagine we're containing a horizontal stack set within a vertical table node.
|
// To understand this code, imagine we're containing a horizontal stack set within a vertical table node.
|
||||||
// Our parentSize is fixed ~375pt width, but 0 - INF height. Our stack measures 1000pt width, 50pt height.
|
// Our parentSize is fixed ~375pt width, but 0 - INF height. Our stack measures 1000pt width, 50pt height.
|
||||||
@ -124,6 +133,25 @@
|
|||||||
{
|
{
|
||||||
ASDN::MutexLocker l(__instanceLock__);
|
ASDN::MutexLocker l(__instanceLock__);
|
||||||
_automaticallyManagesContentSize = automaticallyManagesContentSize;
|
_automaticallyManagesContentSize = automaticallyManagesContentSize;
|
||||||
|
if (_automaticallyManagesContentSize == YES
|
||||||
|
&& ASScrollDirectionContainsVerticalDirection(_scrollableDirections) == NO
|
||||||
|
&& ASScrollDirectionContainsHorizontalDirection(_scrollableDirections) == NO) {
|
||||||
|
// Set the @default value, for more user-friendly behavior of the most
|
||||||
|
// common use cases of .automaticallyManagesContentSize.
|
||||||
|
_scrollableDirections = ASScrollDirectionVerticalDirections;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (ASScrollDirection)scrollableDirections
|
||||||
|
{
|
||||||
|
ASDN::MutexLocker l(__instanceLock__);
|
||||||
|
return _scrollableDirections;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setScrollableDirections:(ASScrollDirection)scrollableDirections
|
||||||
|
{
|
||||||
|
ASDN::MutexLocker l(__instanceLock__);
|
||||||
|
_scrollableDirections = scrollableDirections;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user