Implement delegate in RCTVideo

This commit is contained in:
Stanisław Chmiela 2016-04-01 10:52:05 +02:00
parent 9fefa996f2
commit 931ea75edd
2 changed files with 25 additions and 8 deletions

View File

@ -3,14 +3,14 @@
#import "AVKit/AVKit.h"
#import "UIView+FindUIViewController.h"
#import "RCTVideoPlayerViewController.h"
#import "RCTVideoPlayerViewControllerDelegate.h"
@class RCTEventDispatcher;
@interface RCTVideo : UIView
@interface RCTVideo : UIView <RCTVideoPlayerViewControllerDelegate>
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER;
- (AVPlayerViewController*)createPlayerViewController:(AVPlayer*)player withPlayerItem:(AVPlayerItem*)playerItem;
- (void)setFullscreen:(BOOL)fullscreen;
@end

View File

@ -469,17 +469,13 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty";
}
else
{
[_eventDispatcher sendInputEventWithName:@"onVideoFullscreenPlayerWillDismiss" body:@{@"target": self.reactTag}];
[self videoPlayerViewControllerWillDismiss:_playerViewController];
[_presentingViewController dismissViewControllerAnimated:true completion:^{
_fullScreenPlayerPresented = fullscreen;
_presentingViewController = nil;
[self setControls:_controls];
[_eventDispatcher sendInputEventWithName:@"onVideoFullscreenPlayerDidDismiss" body:@{@"target": self.reactTag}];
[self videoPlayerViewControllerDidDismiss:_playerViewController];
}];
}
}
- (void)usePlayerViewController
{
if( _player )
@ -522,6 +518,27 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty";
}
}
#pragma mark - RCTVideoPlayerViewControllerDelegate
- (void)videoPlayerViewControllerWillDismiss:(AVPlayerViewController *)playerViewController
{
if (_playerViewController == playerViewController && _fullScreenPlayerPresented)
{
[_eventDispatcher sendInputEventWithName:@"onVideoFullscreenPlayerWillDismiss" body:@{@"target": self.reactTag}];
}
}
- (void)videoPlayerViewControllerDidDismiss:(AVPlayerViewController *)playerViewController
{
if (_playerViewController == playerViewController && _fullScreenPlayerPresented)
{
_fullScreenPlayerPresented = false;
_presentingViewController = nil;
[self setControls:_controls];
[_eventDispatcher sendInputEventWithName:@"onVideoFullscreenPlayerDidDismiss" body:@{@"target": self.reactTag}];
}
}
#pragma mark - React View Management
- (void)insertReactSubview:(UIView *)view atIndex:(NSInteger)atIndex