mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-25 01:22:41 +00:00
Merge pull request #651 from rcancro/viewBlock
added a callback for initWithViewBlock/initWithLayerBlock
This commit is contained in:
commit
a9f2bda345
@ -31,13 +31,13 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock
|
||||
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
||||
{
|
||||
ASDisplayNodeAssertNotSupported();
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock
|
||||
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
||||
{
|
||||
ASDisplayNodeAssertNotSupported();
|
||||
return nil;
|
||||
|
||||
@ -15,15 +15,23 @@
|
||||
|
||||
#import <AsyncDisplayKit/ASLayoutable.h>
|
||||
|
||||
@class ASDisplayNode;
|
||||
|
||||
/**
|
||||
* UIView creation block. Used to create the backing view of a new display node.
|
||||
*/
|
||||
typedef UIView *(^ASDisplayNodeViewBlock)();
|
||||
|
||||
/**
|
||||
* CALayer creation block. Used to create the backing layer of a new display node.
|
||||
*/
|
||||
typedef CALayer *(^ASDisplayNodeLayerBlock)();
|
||||
|
||||
/**
|
||||
* ASDisplayNode loaded callback block. Used for any additional setup after node's layer/view has been loaded
|
||||
*/
|
||||
typedef void (^ASDisplayNodeDidLoadBlock)(ASDisplayNode *node);
|
||||
|
||||
/**
|
||||
* An `ASDisplayNode` is an abstraction over `UIView` and `CALayer` that allows you to perform calculations about a view
|
||||
* hierarchy off the main thread, and could do rendering off the main thread as well.
|
||||
@ -65,6 +73,17 @@ typedef CALayer *(^ASDisplayNodeLayerBlock)();
|
||||
*/
|
||||
- (id)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock;
|
||||
|
||||
/**
|
||||
* @abstract Alternative initializer with a block to create the backing view.
|
||||
*
|
||||
* @param viewBlock The block that will be used to create the backing view.
|
||||
* @param didLoadBlock The block that will be called after the view created by the viewBlock is loaded
|
||||
*
|
||||
* @return An ASDisplayNode instance that loads its view with the given block that is guaranteed to run on the main
|
||||
* queue. The view will render synchronously and -layout and touch handling methods on the node will not be called.
|
||||
*/
|
||||
- (id)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock;
|
||||
|
||||
/**
|
||||
* @abstract Alternative initializer with a block to create the backing layer.
|
||||
*
|
||||
@ -73,7 +92,18 @@ typedef CALayer *(^ASDisplayNodeLayerBlock)();
|
||||
* @return An ASDisplayNode instance that loads its layer with the given block that is guaranteed to run on the main
|
||||
* queue. The layer will render synchronously and -layout and touch handling methods on the node will not be called.
|
||||
*/
|
||||
- (id)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock;
|
||||
- (id)initWithLayerBlock:(ASDisplayNodeLayerBlock)layerBlock;
|
||||
|
||||
/**
|
||||
* @abstract Alternative initializer with a block to create the backing layer.
|
||||
*
|
||||
* @param viewBlock The block that will be used to create the backing layer.
|
||||
* @param didLoadBlock The block that will be called after the layer created by the layerBlock is loaded
|
||||
*
|
||||
* @return An ASDisplayNode instance that loads its layer with the given block that is guaranteed to run on the main
|
||||
* queue. The layer will render synchronously and -layout and touch handling methods on the node will not be called.
|
||||
*/
|
||||
- (id)initWithLayerBlock:(ASDisplayNodeLayerBlock)layerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock;
|
||||
|
||||
|
||||
/** @name Properties */
|
||||
|
||||
@ -256,33 +256,47 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
||||
|
||||
- (id)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock
|
||||
{
|
||||
if (!(self = [super init]))
|
||||
return nil;
|
||||
|
||||
ASDisplayNodeAssertNotNil(viewBlock, @"should initialize with a valid block that returns a UIView");
|
||||
|
||||
[self _initializeInstance];
|
||||
_viewBlock = viewBlock;
|
||||
_flags.synchronous = YES;
|
||||
|
||||
return self;
|
||||
return [self initWithViewBlock:viewBlock didLoadBlock:nil];
|
||||
}
|
||||
|
||||
- (id)initWithLayerBlock:(ASDisplayNodeLayerBlock)layerBlock
|
||||
- (id)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
||||
{
|
||||
if (!(self = [super init]))
|
||||
return nil;
|
||||
|
||||
ASDisplayNodeAssertNotNil(layerBlock, @"should initialize with a valid block that returns a CALayer");
|
||||
|
||||
|
||||
ASDisplayNodeAssertNotNil(viewBlock, @"should initialize with a valid block that returns a UIView");
|
||||
|
||||
[self _initializeInstance];
|
||||
_layerBlock = layerBlock;
|
||||
_viewBlock = viewBlock;
|
||||
_nodeLoadedBlock = didLoadBlock;
|
||||
_flags.synchronous = YES;
|
||||
_flags.layerBacked = YES;
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (id)initWithLayerBlock:(ASDisplayNodeLayerBlock)layerBlock
|
||||
{
|
||||
return [self initWithLayerBlock:layerBlock didLoadBlock:nil];
|
||||
}
|
||||
|
||||
- (id)initWithLayerBlock:(ASDisplayNodeLayerBlock)layerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
||||
{
|
||||
if (!(self = [super init]))
|
||||
return nil;
|
||||
|
||||
ASDisplayNodeAssertNotNil(layerBlock, @"should initialize with a valid block that returns a CALayer");
|
||||
|
||||
[self _initializeInstance];
|
||||
_layerBlock = layerBlock;
|
||||
_nodeLoadedBlock = didLoadBlock;
|
||||
_flags.synchronous = YES;
|
||||
_flags.layerBacked = YES;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
ASDisplayNodeAssertMainThread();
|
||||
@ -424,7 +438,7 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
||||
}
|
||||
{
|
||||
TIME_SCOPED(_debugTimeForDidLoad);
|
||||
[self didLoad];
|
||||
[self __didLoad];
|
||||
}
|
||||
|
||||
if (self.placeholderEnabled) {
|
||||
@ -1482,6 +1496,15 @@ static NSInteger incrementIfFound(NSInteger i) {
|
||||
_flags.isMeasured = NO;
|
||||
}
|
||||
|
||||
- (void)__didLoad
|
||||
{
|
||||
if (_nodeLoadedBlock) {
|
||||
_nodeLoadedBlock(self);
|
||||
_nodeLoadedBlock = nil;
|
||||
}
|
||||
[self didLoad];
|
||||
}
|
||||
|
||||
- (void)didLoad
|
||||
{
|
||||
ASDisplayNodeAssertMainThread();
|
||||
|
||||
@ -86,13 +86,13 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock
|
||||
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
||||
{
|
||||
ASDisplayNodeAssertNotSupported();
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock
|
||||
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
||||
{
|
||||
ASDisplayNodeAssertNotSupported();
|
||||
return nil;
|
||||
|
||||
@ -96,13 +96,13 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock
|
||||
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
||||
{
|
||||
ASDisplayNodeAssertNotSupported();
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock
|
||||
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
||||
{
|
||||
ASDisplayNodeAssertNotSupported();
|
||||
return nil;
|
||||
|
||||
@ -149,13 +149,13 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock
|
||||
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
||||
{
|
||||
ASDisplayNodeAssertNotSupported();
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock
|
||||
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
||||
{
|
||||
ASDisplayNodeAssertNotSupported();
|
||||
return nil;
|
||||
|
||||
@ -60,6 +60,7 @@ typedef NS_OPTIONS(NSUInteger, ASDisplayNodeMethodOverrides) {
|
||||
|
||||
ASDisplayNodeViewBlock _viewBlock;
|
||||
ASDisplayNodeLayerBlock _layerBlock;
|
||||
ASDisplayNodeDidLoadBlock _nodeLoadedBlock;
|
||||
Class _viewClass;
|
||||
Class _layerClass;
|
||||
UIView *_view;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user