diff --git a/RCTVideo.h b/RCTVideo.h index ba43d89c..6f8aeab2 100644 --- a/RCTVideo.h +++ b/RCTVideo.h @@ -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 - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER; - (AVPlayerViewController*)createPlayerViewController:(AVPlayer*)player withPlayerItem:(AVPlayerItem*)playerItem; -- (void)setFullscreen:(BOOL)fullscreen; @end diff --git a/RCTVideo.m b/RCTVideo.m index a32778a8..a57f67d9 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -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