Skip to content

Commit

Permalink
Merge pull request #1518 from FullstackJack/tvos-pip-regression
Browse files Browse the repository at this point in the history
Fix tvOS picture-in-picture compilation regression.
  • Loading branch information
cobarx authored Mar 13, 2019
2 parents f710df5 + 5dbf7e2 commit 9016d19
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions ios/Video/RCTVideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@class RCTEventDispatcher;
#if __has_include(<react-native-video/RCTVideoCache.h>)
@interface RCTVideo : UIView <RCTVideoPlayerViewControllerDelegate, DVAssetLoaderDelegatesDelegate>
#elif TARGET_OS_TV
@interface RCTVideo : UIView <RCTVideoPlayerViewControllerDelegate>
#else
@interface RCTVideo : UIView <RCTVideoPlayerViewControllerDelegate, AVPictureInPictureControllerDelegate>
#endif
Expand Down
29 changes: 20 additions & 9 deletions ios/Video/RCTVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ @implementation RCTVideo
AVPlayer *_player;
AVPlayerItem *_playerItem;
NSDictionary *_source;
AVPictureInPictureController *_pipController;
void (^__strong _Nonnull _restoreUserInterfaceForPIPStopCompletionHandler)(BOOL);
BOOL _playerItemObserversSet;
BOOL _playerBufferEmpty;
AVPlayerLayer *_playerLayer;
Expand Down Expand Up @@ -79,6 +77,10 @@ @implementation RCTVideo
#if __has_include(<react-native-video/RCTVideoCache.h>)
RCTVideoCache * _videoCache;
#endif
#if TARGET_OS_IOS
void (^__strong _Nonnull _restoreUserInterfaceForPIPStopCompletionHandler)(BOOL);
AVPictureInPictureController *_pipController;
#endif
}

- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
Expand All @@ -103,9 +105,11 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
_playInBackground = false;
_allowsExternalPlayback = YES;
_playWhenInactive = false;
_pictureInPicture = false;
_pictureInPicture = false;
_ignoreSilentSwitch = @"inherit"; // inherit, ignore, obey
_restoreUserInterfaceForPIPStopCompletionHandler = NULL;
#if TARGET_OS_IOS
_restoreUserInterfaceForPIPStopCompletionHandler = NULL;
#endif
#if __has_include(<react-native-video/RCTVideoCache.h>)
_videoCache = [RCTVideoCache sharedInstance];
#endif
Expand Down Expand Up @@ -793,6 +797,7 @@ - (void)setPlayWhenInactive:(BOOL)playWhenInactive

- (void)setPictureInPicture:(BOOL)pictureInPicture
{
#if TARGET_OS_IOS
if (_pictureInPicture == pictureInPicture) {
return;
}
Expand All @@ -807,8 +812,10 @@ - (void)setPictureInPicture:(BOOL)pictureInPicture
[_pipController stopPictureInPicture];
});
}
#endif
}

#if TARGET_OS_IOS
- (void)setRestoreUserInterfaceForPIPStopCompletionHandler:(BOOL)restore
{
if (_restoreUserInterfaceForPIPStopCompletionHandler != NULL) {
Expand All @@ -824,6 +831,7 @@ - (void)setupPipController {
_pipController.delegate = self;
}
}
#endif

- (void)setIgnoreSilentSwitch:(NSString *)ignoreSilentSwitch
{
Expand Down Expand Up @@ -1279,8 +1287,9 @@ - (void)usePlayerLayer

[self.layer addSublayer:_playerLayer];
self.layer.needsDisplayOnBoundsChange = YES;

#if TARGET_OS_IOS
[self setupPipController];
#endif
}
}

Expand Down Expand Up @@ -1539,19 +1548,20 @@ - (NSString *)cacheDirectoryPath {

#pragma mark - Picture in Picture

#if TARGET_OS_IOS
- (void)pictureInPictureControllerDidStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
if (self.onPictureInPictureStatusChanged) {
self.onPictureInPictureStatusChanged(@{
@"isActive": [NSNumber numberWithBool:false]
});
@"isActive": [NSNumber numberWithBool:false]
});
}
}

- (void)pictureInPictureControllerDidStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
if (self.onPictureInPictureStatusChanged) {
self.onPictureInPictureStatusChanged(@{
@"isActive": [NSNumber numberWithBool:true]
});
@"isActive": [NSNumber numberWithBool:true]
});
}
}

Expand All @@ -1574,5 +1584,6 @@ - (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPict
}
_restoreUserInterfaceForPIPStopCompletionHandler = completionHandler;
}
#endif

@end

0 comments on commit 9016d19

Please sign in to comment.