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

View File

@ -469,17 +469,13 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty";
} }
else else
{ {
[_eventDispatcher sendInputEventWithName:@"onVideoFullscreenPlayerWillDismiss" body:@{@"target": self.reactTag}]; [self videoPlayerViewControllerWillDismiss:_playerViewController];
[_presentingViewController dismissViewControllerAnimated:true completion:^{ [_presentingViewController dismissViewControllerAnimated:true completion:^{
_fullScreenPlayerPresented = fullscreen; [self videoPlayerViewControllerDidDismiss:_playerViewController];
_presentingViewController = nil;
[self setControls:_controls];
[_eventDispatcher sendInputEventWithName:@"onVideoFullscreenPlayerDidDismiss" body:@{@"target": self.reactTag}];
}]; }];
} }
} }
- (void)usePlayerViewController - (void)usePlayerViewController
{ {
if( _player ) 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 #pragma mark - React View Management
- (void)insertReactSubview:(UIView *)view atIndex:(NSInteger)atIndex - (void)insertReactSubview:(UIView *)view atIndex:(NSInteger)atIndex