Split fullscreen options into separate props

This commit is contained in:
Hampton Maxwell 2018-10-07 20:24:50 -07:00
parent 5336d4f866
commit 0646dca071
4 changed files with 54 additions and 60 deletions

View File

@ -254,7 +254,8 @@ var styles = StyleSheet.create({
* [bufferConfig](#bufferconfig) * [bufferConfig](#bufferconfig)
* [controls](#controls) * [controls](#controls)
* [fullscreen](#fullscreen) * [fullscreen](#fullscreen)
* [fullscreenOptions](#fullscreenOptions) * [fullscreenAutorotate](#fullscreenautorotate)
* [fullscreenOrientation](#fullscreenorientation)
* [headers](#headers) * [headers](#headers)
* [ignoreSilentSwitch](#ignoresilentswitch) * [ignoreSilentSwitch](#ignoresilentswitch)
* [muted](#muted) * [muted](#muted)
@ -346,9 +347,20 @@ Platforms: DOM, iOS
#### fullscreen #### fullscreen
Controls whether the player enters fullscreen on play. Use fullscreenOptions for extended behaviour. Controls whether the player enters fullscreen on play. Use fullscreenOptions for extended behaviour.
* **false (default)** - Don't display the video in fullscreen
* **true** - Display the video in fullscreen
Platforms: iOS Platforms: iOS
#### fullscreenAutorotate
If a preferred [fullscreenOrientation](#fullscreenorientation) is set, causes the video to rotate to that orientation when the video enters fullscreen.
#### fullscreenOrientation
* **all (default)** -
* **landscape**
* **portrait**
#### fullscreenOptions #### fullscreenOptions
Controls behaviour of the player entering fullscreen, such as forcing landscape playback on portrait devices Controls behaviour of the player entering fullscreen, such as forcing landscape playback on portrait devices

View File

@ -282,11 +282,6 @@ Video.propTypes = {
PropTypes.object PropTypes.object
]), ]),
fullscreen: PropTypes.bool, fullscreen: PropTypes.bool,
fullscreenOptions: PropTypes.shape({
enabled: PropTypes.bool,
preferredOrientation: PropTypes.string,
autorotate: PropTypes.bool
}),
onVideoLoadStart: PropTypes.func, onVideoLoadStart: PropTypes.func,
onVideoLoad: PropTypes.func, onVideoLoad: PropTypes.func,
onVideoBuffer: PropTypes.func, onVideoBuffer: PropTypes.func,
@ -359,6 +354,8 @@ Video.propTypes = {
controls: PropTypes.bool, controls: PropTypes.bool,
audioOnly: PropTypes.bool, audioOnly: PropTypes.bool,
currentTime: PropTypes.number, currentTime: PropTypes.number,
fullscreenAutorotate: PropTypes.bool,
fullscreenOrientation: PropTypes.string,
progressUpdateInterval: PropTypes.number, progressUpdateInterval: PropTypes.number,
useTextureView: PropTypes.bool, useTextureView: PropTypes.bool,
onLoadStart: PropTypes.func, onLoadStart: PropTypes.func,

View File

@ -30,7 +30,7 @@ static int const RCTVideoUnset = -1;
BOOL _playerBufferEmpty; BOOL _playerBufferEmpty;
AVPlayerLayer *_playerLayer; AVPlayerLayer *_playerLayer;
BOOL _playerLayerObserverSet; BOOL _playerLayerObserverSet;
AVPlayerViewController *_playerViewController; RCTVideoPlayerViewController *_playerViewController;
NSURL *_videoURL; NSURL *_videoURL;
/* Required to publish events */ /* Required to publish events */
@ -64,7 +64,8 @@ static int const RCTVideoUnset = -1;
NSString * _ignoreSilentSwitch; NSString * _ignoreSilentSwitch;
NSString * _resizeMode; NSString * _resizeMode;
BOOL _fullscreen; BOOL _fullscreen;
NSDictionary* _fullscreenOptions; BOOL _fullscreenAutorotate;
NSString * _fullscreenOrientation;
BOOL _fullscreenPlayerPresented; BOOL _fullscreenPlayerPresented;
UIViewController * _presentingViewController; UIViewController * _presentingViewController;
#if __has_include(<react-native-video/RCTVideoCache.h>) #if __has_include(<react-native-video/RCTVideoCache.h>)
@ -83,6 +84,8 @@ static int const RCTVideoUnset = -1;
_rate = 1.0; _rate = 1.0;
_volume = 1.0; _volume = 1.0;
_resizeMode = @"AVLayerVideoGravityResizeAspectFill"; _resizeMode = @"AVLayerVideoGravityResizeAspectFill";
_fullscreenAutorotate = YES;
_fullscreenOrientation = @"default";
_pendingSeek = false; _pendingSeek = false;
_pendingSeekTime = 0.0f; _pendingSeekTime = 0.0f;
_lastSeekTime = 0.0f; _lastSeekTime = 0.0f;
@ -120,21 +123,18 @@ static int const RCTVideoUnset = -1;
return self; return self;
} }
- (AVPlayerViewController*)createPlayerViewController:(AVPlayer*)player withPlayerItem:(AVPlayerItem*)playerItem { - (RCTVideoPlayerViewController*)createPlayerViewController:(AVPlayer*)player
withPlayerItem:(AVPlayerItem*)playerItem {
RCTVideoPlayerViewController* viewController = [[RCTVideoPlayerViewController alloc] init];
viewController.showsPlaybackControls = YES;
viewController.rctDelegate = self;
viewController.autorotate = _fullscreenAutorotate;
viewController.preferredOrientation = _fullscreenOrientation;
RCTVideoPlayerViewController* playerLayer= [[RCTVideoPlayerViewController alloc] init]; viewController.view.frame = self.bounds;
playerLayer.showsPlaybackControls = YES; viewController.player = player;
playerLayer.rctDelegate = self; viewController.view.frame = self.bounds;
return viewController;
if (_fullscreenOptions) {
playerLayer.preferredOrientation = [RCTConvert NSString:[_fullscreenOptions objectForKey:@"preferredOrientation"]];
playerLayer.autorotate = [RCTConvert BOOL:[_fullscreenOptions objectForKey:@"autorotate"]];
}
playerLayer.view.frame = self.bounds;
playerLayer.player = player;
playerLayer.view.frame = self.bounds;
return playerLayer;
} }
/* --------------------------------------------------------- /* ---------------------------------------------------------
@ -361,8 +361,6 @@ static int const RCTVideoUnset = -1;
[self addPlayerTimeObserver]; [self addPlayerTimeObserver];
[self setFullscreenOptions:_fullscreenOptions];
//Perform on next run loop, otherwise onVideoLoadStart is nil //Perform on next run loop, otherwise onVideoLoadStart is nil
if (self.onVideoLoadStart) { if (self.onVideoLoadStart) {
id uri = [source objectForKey:@"uri"]; id uri = [source objectForKey:@"uri"];
@ -380,17 +378,15 @@ static int const RCTVideoUnset = -1;
} }
- (NSURL*) urlFilePath:(NSString*) filepath { - (NSURL*) urlFilePath:(NSString*) filepath {
if ([filepath containsString:@"file://"]) {
// check if the file exists at the specified location return [NSURL URLWithString:filepath];
if ([[NSFileManager defaultManager] fileExistsAtPath:filepath]) {
return [NSURL fileURLWithPath:filepath];
} }
// if no file found, check if the file exists in the Document directory // if no file found, check if the file exists in the Document directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* relativeFilePath = [filepath lastPathComponent]; NSString* relativeFilePath = [filepath lastPathComponent];
// the file may be multiple levels below the documents directory // the file may be multiple levels below the documents directory
NSArray* fileComponents = [filepath componentsSeparatedByString:@"/Documents/"]; NSArray* fileComponents = [filepath componentsSeparatedByString:@"Documents/"];
if (fileComponents.count > 1) { if (fileComponents.count > 1) {
relativeFilePath = [fileComponents objectAtIndex:1]; relativeFilePath = [fileComponents objectAtIndex:1];
} }
@ -1113,33 +1109,7 @@ static int const RCTVideoUnset = -1;
} }
- (void)setFullscreen:(BOOL) fullscreen { - (void)setFullscreen:(BOOL) fullscreen {
_fullscreen = fullscreen; if( fullscreen && !_fullscreenPlayerPresented )
NSString* enabled = _fullscreen ? @"1" : @"0";
if (!_fullscreenOptions) {
[self setFullscreenOptions:
@{
@"enabled": enabled,
@"autorotate": @"0",
@"preferredOrientation": @"default"
}];
}
else {
[_fullscreenOptions setValue:enabled forKey:@"enabled"];
[self setFullscreenOptions:_fullscreenOptions];
}
}
- (void)setFullscreenOptions:(NSDictionary*) fullscreenOptions
{
_fullscreenOptions = fullscreenOptions;
if (!_fullscreenOptions) return;
BOOL fullscreenEnabled = [RCTConvert BOOL:[_fullscreenOptions objectForKey:@"enabled"]];
if( fullscreenEnabled && !_fullscreenPlayerPresented && _player )
{ {
// Ensure player view controller is not null // Ensure player view controller is not null
if( !_playerViewController ) if( !_playerViewController )
@ -1168,14 +1138,14 @@ static int const RCTVideoUnset = -1;
} }
[viewController presentViewController:_playerViewController animated:true completion:^{ [viewController presentViewController:_playerViewController animated:true completion:^{
_playerViewController.showsPlaybackControls = YES; _playerViewController.showsPlaybackControls = YES;
_fullscreenPlayerPresented = fullscreenEnabled; _fullscreenPlayerPresented = fullscreen;
if(self.onVideoFullscreenPlayerDidPresent) { if(self.onVideoFullscreenPlayerDidPresent) {
self.onVideoFullscreenPlayerDidPresent(@{@"target": self.reactTag}); self.onVideoFullscreenPlayerDidPresent(@{@"target": self.reactTag});
} }
}]; }];
} }
} }
else if ( !fullscreenEnabled && _fullscreenPlayerPresented ) else if ( !fullscreen && _fullscreenPlayerPresented )
{ {
[self videoPlayerViewControllerWillDismiss:_playerViewController]; [self videoPlayerViewControllerWillDismiss:_playerViewController];
[_presentingViewController dismissViewControllerAnimated:true completion:^{ [_presentingViewController dismissViewControllerAnimated:true completion:^{
@ -1184,6 +1154,20 @@ static int const RCTVideoUnset = -1;
} }
} }
- (void)setFullscreenAutorotate:(BOOL)autorotate {
_fullscreenAutorotate = autorotate;
if (_fullscreenPlayerPresented) {
_playerViewController.autorotate = autorotate;
}
}
- (void)setFullscreenOrientation:(NSString *)orientation {
_fullscreenOrientation = orientation;
if (_fullscreenPlayerPresented) {
_playerViewController.preferredOrientation = orientation;
}
}
- (void)usePlayerViewController - (void)usePlayerViewController
{ {
if( _player ) if( _player )

View File

@ -36,8 +36,9 @@ RCT_EXPORT_VIEW_PROPERTY(ignoreSilentSwitch, NSString);
RCT_EXPORT_VIEW_PROPERTY(rate, float); RCT_EXPORT_VIEW_PROPERTY(rate, float);
RCT_EXPORT_VIEW_PROPERTY(seek, NSDictionary); RCT_EXPORT_VIEW_PROPERTY(seek, NSDictionary);
RCT_EXPORT_VIEW_PROPERTY(currentTime, float); RCT_EXPORT_VIEW_PROPERTY(currentTime, float);
RCT_EXPORT_VIEW_PROPERTY(fullscreen, BOOL); // deprecated property RCT_EXPORT_VIEW_PROPERTY(fullscreen, BOOL);
RCT_EXPORT_VIEW_PROPERTY(fullscreenOptions, NSDictionary); RCT_EXPORT_VIEW_PROPERTY(fullscreenAutorotate, BOOL);
RCT_EXPORT_VIEW_PROPERTY(fullscreenOrientation, NSString);
RCT_EXPORT_VIEW_PROPERTY(progressUpdateInterval, float); RCT_EXPORT_VIEW_PROPERTY(progressUpdateInterval, float);
/* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */ /* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */
RCT_EXPORT_VIEW_PROPERTY(onVideoLoadStart, RCTBubblingEventBlock); RCT_EXPORT_VIEW_PROPERTY(onVideoLoadStart, RCTBubblingEventBlock);