Fix missing layout calls in full-screen when using built-in video controls on iOS

This commit is contained in:
Ash Mishra
2019-01-21 14:05:03 -08:00
parent 35e26427ea
commit b6ed6819f0
32 changed files with 83239 additions and 2 deletions

View File

@@ -137,7 +137,6 @@ static int const RCTVideoUnset = -1;
viewController.view.frame = self.bounds;
viewController.player = player;
viewController.view.frame = self.bounds;
return viewController;
}
@@ -564,6 +563,27 @@ static int const RCTVideoUnset = -1;
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
// when controls==true, this is a hack to reset the rootview when rotation happens in fullscreen
if (object == _playerViewController.contentOverlayView) {
if ([keyPath isEqualToString:@"frame"]) {
CGRect oldRect = [change[NSKeyValueChangeOldKey] CGRectValue];
CGRect newRect = [change[NSKeyValueChangeNewKey] CGRectValue];
if (!CGRectEqualToRect(oldRect, newRect)) {
if (CGRectEqualToRect(newRect, [UIScreen mainScreen].bounds)) {
NSLog(@"in fullscreen");
} else NSLog(@"not fullscreen");
[self.reactViewController.view setFrame:[UIScreen mainScreen].bounds];
[self.reactViewController.view setNeedsLayout];
}
return;
} else
return [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
if (object == _playerItem) {
// When timeMetadata is read the event onTimedMetadata is triggered
if ([keyPath isEqualToString:timedMetadata]) {
@@ -1214,7 +1234,14 @@ static int const RCTVideoUnset = -1;
// to prevent video from being animated when resizeMode is 'cover'
// resize mode must be set before subview is added
[self setResizeMode:_resizeMode];
[self addSubview:_playerViewController.view];
if (_controls) {
UIViewController *viewController = [self reactViewController];
[viewController addChildViewController:_playerViewController];
[self addSubview:_playerViewController.view];
}
[_playerViewController.contentOverlayView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:NULL];
}
}
@@ -1404,6 +1431,7 @@ static int const RCTVideoUnset = -1;
[self removePlayerLayer];
[_playerViewController.contentOverlayView removeObserver:self forKeyPath:@"frame"];
[_playerViewController.view removeFromSuperview];
_playerViewController = nil;