mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Address further comments
This commit is contained in:
@@ -306,7 +306,6 @@ extern NSInteger const ASDefaultDrawingPriority;
|
|||||||
*/
|
*/
|
||||||
@property (nonatomic, readonly, assign) ASSizeRange constrainedSizeForCalculatedLayout;
|
@property (nonatomic, readonly, assign) ASSizeRange constrainedSizeForCalculatedLayout;
|
||||||
|
|
||||||
|
|
||||||
/** @name Managing the nodes hierarchy */
|
/** @name Managing the nodes hierarchy */
|
||||||
|
|
||||||
|
|
||||||
@@ -632,13 +631,18 @@ extern NSInteger const ASDefaultDrawingPriority;
|
|||||||
@interface ASDisplayNode (UIViewBridge)
|
@interface ASDisplayNode (UIViewBridge)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the view as needing display. Convenience for use whether the view / layer is loaded or not. Safe to call
|
* Marks the view as needing display. Convenience for use whether the view / layer is loaded or not. Safe to call from a background thread.
|
||||||
* from a background thread.
|
|
||||||
*/
|
*/
|
||||||
- (void)setNeedsDisplay;
|
- (void)setNeedsDisplay;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the node as needing layout. Convenience for use whether the view / layer is loaded or not. Safe to call from a background thread.
|
* Marks the node as needing layout. Convenience for use whether the view / layer is loaded or not. Safe to call from a background thread.
|
||||||
|
*
|
||||||
|
* If the node determines its own desired layout size will change in the next layout pass, it will propagate this
|
||||||
|
* information up the tree so its parents can have a chance to consider and apply if necessary the new size onto the node.
|
||||||
|
*
|
||||||
|
* Note: ASCellNode has special behavior in that calling this method will automatically notify
|
||||||
|
* the containing ASTableView / ASCollectionView that the cell should be resized, if necessary.
|
||||||
*/
|
*/
|
||||||
- (void)setNeedsLayout;
|
- (void)setNeedsLayout;
|
||||||
|
|
||||||
|
|||||||
@@ -704,7 +704,7 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
|||||||
|
|
||||||
#pragma mark - Layout
|
#pragma mark - Layout
|
||||||
|
|
||||||
- (void)invalidateSize
|
- (void)setNeedsLayoutFromAbove
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertThreadAffinity(self);
|
ASDisplayNodeAssertThreadAffinity(self);
|
||||||
|
|
||||||
@@ -718,7 +718,7 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
|||||||
__instanceLock__.unlock();
|
__instanceLock__.unlock();
|
||||||
// Cause supernode's layout to be invalidated
|
// Cause supernode's layout to be invalidated
|
||||||
// We need to release the lock to prevent a deadlock
|
// We need to release the lock to prevent a deadlock
|
||||||
[supernode invalidateSize];
|
[supernode setNeedsLayoutFromAbove];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -733,8 +733,13 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
|||||||
constrainedSize = _calculatedDisplayNodeLayout->constrainedSize;
|
constrainedSize = _calculatedDisplayNodeLayout->constrainedSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the returned layout has a different size as the current bounds
|
// Perform a measurement pass to get the current layout
|
||||||
|
// It's important to differentiate between layout and measure pass here. Calling `layoutThatFits:` just perform a
|
||||||
|
// measure pass and no layout pass immediately. If a layout pass wold be forced via `layoutIfNeeded` it could cause an
|
||||||
|
// infinite loop as in `__layout` we check if the size changed and we are just to inform the node that the size changed
|
||||||
ASLayout *layout = [self layoutThatFits:constrainedSize];
|
ASLayout *layout = [self layoutThatFits:constrainedSize];
|
||||||
|
|
||||||
|
// Check if the returned layout has a different size as the current bounds
|
||||||
if (CGSizeEqualToSize(oldSize, layout.size) == NO) {
|
if (CGSizeEqualToSize(oldSize, layout.size) == NO) {
|
||||||
// If the size of the layout changes inform our container (e.g ASTableView, ASCollectionView, ASViewController, ...)
|
// If the size of the layout changes inform our container (e.g ASTableView, ASCollectionView, ASViewController, ...)
|
||||||
// that we need it to change our bounds size.
|
// that we need it to change our bounds size.
|
||||||
@@ -1415,11 +1420,6 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
|||||||
[self invalidateCalculatedLayout];
|
[self invalidateCalculatedLayout];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)__layoutIfNeeded
|
|
||||||
{
|
|
||||||
// For now this is a no op.
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)__setNeedsDisplay
|
- (void)__setNeedsDisplay
|
||||||
{
|
{
|
||||||
BOOL nowDisplay = ASInterfaceStateIncludesDisplay(_interfaceState);
|
BOOL nowDisplay = ASInterfaceStateIncludesDisplay(_interfaceState);
|
||||||
@@ -1540,7 +1540,7 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
|||||||
// If the size of the new layout to apply did change from the current bounds, invalidate the whole tree up
|
// If the size of the new layout to apply did change from the current bounds, invalidate the whole tree up
|
||||||
// so the root node can handle a resizing if necessary
|
// so the root node can handle a resizing if necessary
|
||||||
if (CGSizeEqualToSize(ASCeilSizeValues(bounds.size), pendingLayout->layout.size) == NO) {
|
if (CGSizeEqualToSize(ASCeilSizeValues(bounds.size), pendingLayout->layout.size) == NO) {
|
||||||
[self invalidateSize];
|
[self setNeedsLayoutFromAbove];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (didCreateNewContext) {
|
if (didCreateNewContext) {
|
||||||
@@ -1570,7 +1570,8 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
|||||||
CGRect bounds = self.threadSafeBounds;
|
CGRect bounds = self.threadSafeBounds;
|
||||||
|
|
||||||
// Checkout if constrained size of pending or calculated display node layout can be used
|
// Checkout if constrained size of pending or calculated display node layout can be used
|
||||||
if (_pendingDisplayNodeLayout != nullptr && CGSizeEqualToSize(_pendingDisplayNodeLayout->layout.size, ASCeilSizeValues(bounds.size))) {
|
if (_pendingDisplayNodeLayout != nullptr &&
|
||||||
|
CGSizeEqualToSize(_pendingDisplayNodeLayout->layout.size, ASCeilSizeValues(bounds.size))) {
|
||||||
// We assume the size from the last returned layoutThatFits: layout was applied so use the pending display node
|
// We assume the size from the last returned layoutThatFits: layout was applied so use the pending display node
|
||||||
// layout constrained size
|
// layout constrained size
|
||||||
return _pendingDisplayNodeLayout->constrainedSize;
|
return _pendingDisplayNodeLayout->constrainedSize;
|
||||||
|
|||||||
@@ -1567,11 +1567,6 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (ASSizeRange)constrainedSizeForNode:(ASCellNode *)node
|
|
||||||
{
|
|
||||||
return [self dataController:self.dataController constrainedSizeForNodeAtIndexPath:[self indexPathForNode:node]];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)nodeDidRelayout:(ASCellNode *)node sizeChanged:(BOOL)sizeChanged
|
- (void)nodeDidRelayout:(ASCellNode *)node sizeChanged:(BOOL)sizeChanged
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertMainThread();
|
ASDisplayNodeAssertMainThread();
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ __unused static NSString * _Nonnull NSStringFromASHierarchyState(ASHierarchyStat
|
|||||||
* @discussion The size of a root node is determined by each subnode. Calling invalidateSize will let the root node know
|
* @discussion The size of a root node is determined by each subnode. Calling invalidateSize will let the root node know
|
||||||
* that the intrinsic size of the receiver node is no longer valid and a resizing of the root node needs to happen.
|
* that the intrinsic size of the receiver node is no longer valid and a resizing of the root node needs to happen.
|
||||||
*/
|
*/
|
||||||
- (void)invalidateSize;
|
- (void)setNeedsLayoutFromAbove;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @abstract Subclass hook for nodes that are acting as root nodes. This method is called if one of the subnodes
|
* @abstract Subclass hook for nodes that are acting as root nodes. This method is called if one of the subnodes
|
||||||
|
|||||||
@@ -84,7 +84,6 @@
|
|||||||
- (void)buttonPressed:(id)sender
|
- (void)buttonPressed:(id)sender
|
||||||
{
|
{
|
||||||
self.enabled = !self.enabled;
|
self.enabled = !self.enabled;
|
||||||
|
|
||||||
[self transitionLayoutWithAnimation:YES shouldMeasureAsync:NO measurementCompletion:nil];
|
[self transitionLayoutWithAnimation:YES shouldMeasureAsync:NO measurementCompletion:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,11 +105,12 @@
|
|||||||
|
|
||||||
- (void)updateButtonNodeLayout
|
- (void)updateButtonNodeLayout
|
||||||
{
|
{
|
||||||
[self.buttonNode sizeToFit];
|
//[self.buttonNode sizeToFit];
|
||||||
self.buttonNode.frame = CGRectMake((self.view.bounds.size.width - self.buttonNode.bounds.size.width) / 2.0,
|
CGSize size = [self.buttonNode layoutThatFits:ASSizeRangeMake(CGSizeZero, CGSizeMake(INFINITY, INFINITY))].size;
|
||||||
|
self.buttonNode.frame = CGRectMake((self.view.bounds.size.width - size.width) / 2.0,
|
||||||
100,
|
100,
|
||||||
self.buttonNode.bounds.size.width,
|
size.width,
|
||||||
self.buttonNode.bounds.size.height);
|
size.height);
|
||||||
|
|
||||||
//CGSize s = [self.buttonNode sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
|
//CGSize s = [self.buttonNode sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
|
||||||
//self.buttonNode.frame = CGRectMake(100, 100, s.width, s.height);
|
//self.buttonNode.frame = CGRectMake(100, 100, s.width, s.height);
|
||||||
@@ -141,7 +142,7 @@
|
|||||||
//return;
|
//return;
|
||||||
// Use the bounds of the view and get the fitting size
|
// Use the bounds of the view and get the fitting size
|
||||||
// This does not have any side effects, but can be called on the main thread without any problems
|
// This does not have any side effects, but can be called on the main thread without any problems
|
||||||
CGSize size = [self.sizingNode sizeThatFits:CGSizeMake(INFINITY, 100.0)];
|
CGSize size = [self.sizingNode layoutThatFits:ASSizeRangeMake(CGSizeZero, CGSizeMake(INFINITY, 100.0))].size;
|
||||||
//size.width -= 10;
|
//size.width -= 10;
|
||||||
//[self.sizingNode setNeedsLayout];
|
//[self.sizingNode setNeedsLayout];
|
||||||
self.sizingNode.frame = CGRectMake((CGRectGetWidth(self.view.bounds) - size.width) / 2.0,
|
self.sizingNode.frame = CGRectMake((CGRectGetWidth(self.view.bounds) - size.width) / 2.0,
|
||||||
|
|||||||
@@ -129,7 +129,7 @@
|
|||||||
/*if ([self.sizingDelegate respondsToSelector:@selector(displayNodeDidInvalidateSize:)]) {
|
/*if ([self.sizingDelegate respondsToSelector:@selector(displayNodeDidInvalidateSize:)]) {
|
||||||
[self.sizingDelegate performSelector:@selector(displayNodeDidInvalidateSize:) withObject:self];
|
[self.sizingDelegate performSelector:@selector(displayNodeDidInvalidateSize:) withObject:self];
|
||||||
}*/
|
}*/
|
||||||
[self invalidateSize];
|
//[self invalidateSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - ASDisplayNode
|
#pragma mark - ASDisplayNode
|
||||||
|
|||||||
Reference in New Issue
Block a user