added a callback for initWithViewBlock/initWithLayerBlock

This commit is contained in:
rcancro
2015-09-14 20:36:08 -07:00
parent 6ce077be5a
commit 01be5acece
7 changed files with 85 additions and 27 deletions

View File

@@ -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 viewDidLoadBlock:nil];
}
- (id)initWithLayerBlock:(ASDisplayNodeLayerBlock)layerBlock
- (id)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock viewDidLoadBlock:(ASDisplayNodeViewLoadedBlock)viewLoadedBlock
{
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;
_viewLoadedBlock = viewLoadedBlock;
_flags.synchronous = YES;
_flags.layerBacked = YES;
return self;
}
- (id)initWithLayerBlock:(ASDisplayNodeLayerBlock)layerBlock
{
return [self initWithLayerBlock:layerBlock layerDidLoadBlock:nil];
}
- (id)initWithLayerBlock:(ASDisplayNodeLayerBlock)layerBlock layerDidLoadBlock:(ASDisplayNodeLayerLoadedBlock)layerLoadedBlock
{
if (!(self = [super init]))
return nil;
ASDisplayNodeAssertNotNil(layerBlock, @"should initialize with a valid block that returns a CALayer");
[self _initializeInstance];
_layerBlock = layerBlock;
_layerLoadedBlock = layerLoadedBlock;
_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,17 @@ static NSInteger incrementIfFound(NSInteger i) {
_flags.isMeasured = NO;
}
- (void)__didLoad
{
if (_viewLoadedBlock) {
_viewLoadedBlock(_view);
}
if (_layerLoadedBlock) {
_layerLoadedBlock(_layer);
}
[self didLoad];
}
- (void)didLoad
{
ASDisplayNodeAssertMainThread();