From 9be76e3674b2c30853065d8d6bc075b64b4661c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Thu, 31 Mar 2016 20:34:08 +0200 Subject: [PATCH] Add view controller finding functions We need them to be able to present another view controller --- RCTVideo.m | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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