Skip to content

Commit

Permalink
Replacing ASVideoNode's playButton now cleans-up the previous button'…
Browse files Browse the repository at this point in the history
…s state
  • Loading branch information
ejensen committed Apr 18, 2016
1 parent cdb926c commit 983c2f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion AsyncDisplayKit/ASVideoNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ - (void)visibilityDidChange:(BOOL)isVisible
- (void)setPlayButton:(ASButtonNode *)playButton
{
ASDN::MutexLocker l(_videoLock);


[_playButton removeTarget:self action:@selector(tapped) forControlEvents:ASControlNodeEventTouchUpInside];
[_playButton removeFromSupernode];

_playButton = playButton;

[self addSubnode:playButton];
Expand Down Expand Up @@ -565,6 +568,7 @@ - (BOOL)shouldBePlaying

- (void)dealloc
{
[_playButton removeTarget:self action:@selector(tapped) forControlEvents:ASControlNodeEventTouchUpInside];
[self removePlayerItemObservers];

@try {
Expand Down
15 changes: 15 additions & 0 deletions AsyncDisplayKitTests/ASVideoNodeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,19 @@ - (void)testSettingVideoGravityChangesPlaceholderContentMode
XCTAssertEqual(UIViewContentModeScaleAspectFill, _videoNode.placeholderImageNode.contentMode);
}

- (void)testChangingPlayButtonPerformsProperCleanup
{
ASButtonNode *firstButton = _videoNode.playButton;
XCTAssertTrue([firstButton.allTargets containsObject:_videoNode]);

ASButtonNode *secondButton = [[ASButtonNode alloc] init];
_videoNode.playButton = secondButton;

XCTAssertTrue([secondButton.allTargets containsObject:_videoNode]);
XCTAssertEqual(_videoNode, secondButton.supernode);

XCTAssertFalse([firstButton.allTargets containsObject:_videoNode]);
XCTAssertNotEqual(_videoNode, firstButton.supernode);
}

@end

0 comments on commit 983c2f1

Please sign in to comment.