diff --git a/RCTVideo.m b/RCTVideo.m index 3c0fa291..7bd52933 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -524,6 +524,26 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; } } +#pragma mark - View Controller retrieval + +// http://stackoverflow.com/questions/1340434/get-to-uiviewcontroller-from-uiview/2596519 + +- (UIViewController *) firstAvailableUIViewController { + // convenience function for casting and to "mask" the recursive function + return (UIViewController *)[self traverseResponderChainForUIViewController]; +} + +- (id) traverseResponderChainForUIViewController { + id nextResponder = [self nextResponder]; + if ([nextResponder isKindOfClass:[UIViewController class]]) { + return nextResponder; + } else if ([nextResponder isKindOfClass:[UIView class]]) { + return [nextResponder traverseResponderChainForUIViewController]; + } else { + return nil; + } +} + #pragma mark - Lifecycle - (void)removeFromSuperview