Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 99c5021

Browse files
nguyenhuyappleguy
authored andcommitted
Remove duplicated _delegate ivar in ASVideoNode (#2844)
1 parent 2f79255 commit 99c5021

2 files changed

Lines changed: 23 additions & 35 deletions

File tree

AsyncDisplayKit/ASVideoNode.mm

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ static UIViewContentMode ASContentModeFromVideoGravity(NSString *videoGravity) {
4040

4141
@interface ASVideoNode ()
4242
{
43-
__weak id<ASVideoNodeDelegate> _delegate;
4443
struct {
4544
unsigned int delegateVideNodeShouldChangePlayerStateTo:1;
4645
unsigned int delegateVideoDidPlayToEnd:1;
@@ -85,6 +84,8 @@ @interface ASVideoNode ()
8584

8685
@implementation ASVideoNode
8786

87+
@dynamic delegate;
88+
8889
// TODO: Support preview images with HTTP Live Streaming videos.
8990

9091
#pragma mark - Construction and Layout
@@ -160,7 +161,7 @@ - (void)prepareToPlayAsset:(AVAsset *)asset withKeys:(NSArray<NSString *> *)requ
160161
}
161162

162163
if (_delegateFlags.delegateVideoNodeDidSetCurrentItem) {
163-
[_delegate videoNode:self didSetCurrentItem:playerItem];
164+
[self.delegate videoNode:self didSetCurrentItem:playerItem];
164165
}
165166

166167
if (self.image == nil && self.URL == nil) {
@@ -331,7 +332,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
331332
}
332333
if (_shouldBePlaying && (_shouldAggressivelyRecoverFromStall || likelyToKeepUp) && ASInterfaceStateIncludesVisible(self.interfaceState)) {
333334
if (self.playerState == ASVideoNodePlayerStateLoading && _delegateFlags.delegateVideoNodeDidRecoverFromStall) {
334-
[_delegate videoNodeDidRecoverFromStall:self];
335+
[self.delegate videoNodeDidRecoverFromStall:self];
335336
}
336337
[self play]; // autoresume after buffer catches up
337338
}
@@ -356,7 +357,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
356357
- (void)tapped
357358
{
358359
if (_delegateFlags.delegateDidTapVideoNode) {
359-
[_delegate didTapVideoNode:self];
360+
[self.delegate didTapVideoNode:self];
360361

361362
} else {
362363
if (_shouldBePlaying) {
@@ -380,14 +381,14 @@ - (void)didEnterPreloadState
380381

381382
self.playerState = ASVideoNodePlayerStateLoading;
382383
if (_delegateFlags.delegateVideoNodeDidStartInitialLoading) {
383-
[_delegate videoNodeDidStartInitialLoading:self];
384+
[self.delegate videoNodeDidStartInitialLoading:self];
384385
}
385386

386387
NSArray<NSString *> *requestedKeys = @[@"playable"];
387388
[asset loadValuesAsynchronouslyForKeys:requestedKeys completionHandler:^{
388389
ASPerformBlockOnMainThread(^{
389390
if (_delegateFlags.delegateVideoNodeDidFinishInitialLoading) {
390-
[_delegate videoNodeDidFinishInitialLoading:self];
391+
[self.delegate videoNodeDidFinishInitialLoading:self];
391392
}
392393
[self prepareToPlayAsset:asset withKeys:requestedKeys];
393394
});
@@ -402,7 +403,7 @@ - (void)periodicTimeObserver:(CMTime)time
402403
}
403404

404405
if (_delegateFlags.delegateVideoNodeDidPlayToTimeInterval) {
405-
[_delegate videoNode:self didPlayToTimeInterval:timeInSeconds];
406+
[self.delegate videoNode:self didPlayToTimeInterval:timeInSeconds];
406407

407408
}
408409
}
@@ -462,7 +463,7 @@ - (void)setPlayerState:(ASVideoNodePlayerState)playerState
462463
}
463464

464465
if (_delegateFlags.delegateVideoNodeWillChangePlayerStateToState) {
465-
[_delegate videoNode:self willChangePlayerState:oldState toState:playerState];
466+
[self.delegate videoNode:self willChangePlayerState:oldState toState:playerState];
466467
}
467468

468469
_playerState = playerState;
@@ -561,28 +562,23 @@ - (AVPlayerLayer *)playerLayer
561562
return (AVPlayerLayer *)_playerNode.layer;
562563
}
563564

564-
- (id<ASVideoNodeDelegate>)delegate{
565-
return _delegate;
566-
}
567-
568565
- (void)setDelegate:(id<ASVideoNodeDelegate>)delegate
569566
{
570567
[super setDelegate:delegate];
571-
_delegate = delegate;
572568

573-
if (_delegate == nil) {
569+
if (delegate == nil) {
574570
memset(&_delegateFlags, 0, sizeof(_delegateFlags));
575571
} else {
576-
_delegateFlags.delegateVideNodeShouldChangePlayerStateTo = [_delegate respondsToSelector:@selector(videoNode:shouldChangePlayerStateTo:)];
577-
_delegateFlags.delegateVideoDidPlayToEnd = [_delegate respondsToSelector:@selector(videoDidPlayToEnd:)];
578-
_delegateFlags.delegateDidTapVideoNode = [_delegate respondsToSelector:@selector(didTapVideoNode:)];
579-
_delegateFlags.delegateVideoNodeWillChangePlayerStateToState = [_delegate respondsToSelector:@selector(videoNode:willChangePlayerState:toState:)];
580-
_delegateFlags.delegateVideoNodeDidPlayToTimeInterval = [_delegate respondsToSelector:@selector(videoNode:didPlayToTimeInterval:)];
581-
_delegateFlags.delegateVideoNodeDidStartInitialLoading = [_delegate respondsToSelector:@selector(videoNodeDidStartInitialLoading:)];
582-
_delegateFlags.delegateVideoNodeDidFinishInitialLoading = [_delegate respondsToSelector:@selector(videoNodeDidFinishInitialLoading:)];
583-
_delegateFlags.delegateVideoNodeDidSetCurrentItem = [_delegate respondsToSelector:@selector(videoNode:didSetCurrentItem:)];
584-
_delegateFlags.delegateVideoNodeDidStallAtTimeInterval = [_delegate respondsToSelector:@selector(videoNode:didStallAtTimeInterval:)];
585-
_delegateFlags.delegateVideoNodeDidRecoverFromStall = [_delegate respondsToSelector:@selector(videoNodeDidRecoverFromStall:)];
572+
_delegateFlags.delegateVideNodeShouldChangePlayerStateTo = [delegate respondsToSelector:@selector(videoNode:shouldChangePlayerStateTo:)];
573+
_delegateFlags.delegateVideoDidPlayToEnd = [delegate respondsToSelector:@selector(videoDidPlayToEnd:)];
574+
_delegateFlags.delegateDidTapVideoNode = [delegate respondsToSelector:@selector(didTapVideoNode:)];
575+
_delegateFlags.delegateVideoNodeWillChangePlayerStateToState = [delegate respondsToSelector:@selector(videoNode:willChangePlayerState:toState:)];
576+
_delegateFlags.delegateVideoNodeDidPlayToTimeInterval = [delegate respondsToSelector:@selector(videoNode:didPlayToTimeInterval:)];
577+
_delegateFlags.delegateVideoNodeDidStartInitialLoading = [delegate respondsToSelector:@selector(videoNodeDidStartInitialLoading:)];
578+
_delegateFlags.delegateVideoNodeDidFinishInitialLoading = [delegate respondsToSelector:@selector(videoNodeDidFinishInitialLoading:)];
579+
_delegateFlags.delegateVideoNodeDidSetCurrentItem = [delegate respondsToSelector:@selector(videoNode:didSetCurrentItem:)];
580+
_delegateFlags.delegateVideoNodeDidStallAtTimeInterval = [delegate respondsToSelector:@selector(videoNode:didStallAtTimeInterval:)];
581+
_delegateFlags.delegateVideoNodeDidRecoverFromStall = [delegate respondsToSelector:@selector(videoNodeDidRecoverFromStall:)];
586582
}
587583
}
588584

@@ -674,7 +670,7 @@ - (BOOL)isPlaying
674670
- (BOOL)isStateChangeValid:(ASVideoNodePlayerState)state
675671
{
676672
if (_delegateFlags.delegateVideNodeShouldChangePlayerStateTo) {
677-
if (![_delegate videoNode:self shouldChangePlayerStateTo:state]) {
673+
if (![self.delegate videoNode:self shouldChangePlayerStateTo:state]) {
678674
return NO;
679675
}
680676
}
@@ -701,7 +697,7 @@ - (void)didPlayToEnd:(NSNotification *)notification
701697
{
702698
self.playerState = ASVideoNodePlayerStateFinished;
703699
if (_delegateFlags.delegateVideoDidPlayToEnd) {
704-
[_delegate videoDidPlayToEnd:self];
700+
[self.delegate videoDidPlayToEnd:self];
705701
}
706702

707703
if (_shouldAutorepeat) {
@@ -716,7 +712,7 @@ - (void)videoNodeDidStall:(NSNotification *)notification
716712
{
717713
self.playerState = ASVideoNodePlayerStateLoading;
718714
if (_delegateFlags.delegateVideoNodeDidStallAtTimeInterval) {
719-
[_delegate videoNode:self didStallAtTimeInterval:CMTimeGetSeconds(_player.currentItem.currentTime)];
715+
[self.delegate videoNode:self didStallAtTimeInterval:CMTimeGetSeconds(_player.currentItem.currentTime)];
720716
}
721717
}
722718

AsyncDisplayKitTests/ASVideoNodeTests.m

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ @interface ASVideoNodeTests : XCTestCase <ASVideoNodeDelegate>
2525
}
2626
@end
2727

28-
@interface ASNetworkImageNode () {
29-
@public __weak id<ASNetworkImageNodeDelegate> _delegate;
30-
}
31-
@end
32-
33-
3428
@interface ASVideoNode () {
3529
ASDisplayNode *_playerNode;
3630
AVPlayer *_player;
@@ -419,11 +413,9 @@ - (void)testDelegateProperlySetForClassHierarchy
419413
XCTAssertTrue([_videoNode.delegate conformsToProtocol:@protocol(ASVideoNodeDelegate)]);
420414
XCTAssertTrue([_videoNode.delegate conformsToProtocol:@protocol(ASNetworkImageNodeDelegate)]);
421415
XCTAssertTrue([((ASNetworkImageNode*)_videoNode).delegate conformsToProtocol:@protocol(ASNetworkImageNodeDelegate)]);
422-
XCTAssertTrue([((ASNetworkImageNode*)_videoNode)->_delegate conformsToProtocol:@protocol(ASNetworkImageNodeDelegate)]);
423416

424417
XCTAssertEqual(_videoNode.delegate, self);
425418
XCTAssertEqual(((ASNetworkImageNode*)_videoNode).delegate, self);
426-
XCTAssertEqual(((ASNetworkImageNode*)_videoNode)->_delegate, self);
427419
}
428420

429421
@end

0 commit comments

Comments
 (0)