diff --git a/RCTVideo.m b/RCTVideo.m index 268c4dab..277b8247 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -574,26 +574,6 @@ 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 diff --git a/RCTVideo.xcodeproj/project.pbxproj b/RCTVideo.xcodeproj/project.pbxproj index 9a65aa45..a8d2cddf 100644 --- a/RCTVideo.xcodeproj/project.pbxproj +++ b/RCTVideo.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 31CAFB211CADA8CD009BCF6F /* UIView+FindUIViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 31CAFB201CADA8CD009BCF6F /* UIView+FindUIViewController.m */; }; BBD49E3F1AC8DEF000610F8E /* RCTVideo.m in Sources */ = {isa = PBXBuildFile; fileRef = BBD49E3A1AC8DEF000610F8E /* RCTVideo.m */; }; BBD49E401AC8DEF000610F8E /* RCTVideoManager.m in Sources */ = {isa = PBXBuildFile; fileRef = BBD49E3C1AC8DEF000610F8E /* RCTVideoManager.m */; }; /* End PBXBuildFile section */ @@ -25,6 +26,8 @@ /* Begin PBXFileReference section */ 134814201AA4EA6300B7C361 /* libRCTVideo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTVideo.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 31CAFB1F1CADA8CD009BCF6F /* UIView+FindUIViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+FindUIViewController.h"; sourceTree = ""; }; + 31CAFB201CADA8CD009BCF6F /* UIView+FindUIViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+FindUIViewController.m"; sourceTree = ""; }; BBD49E391AC8DEF000610F8E /* RCTVideo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTVideo.h; sourceTree = ""; }; BBD49E3A1AC8DEF000610F8E /* RCTVideo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTVideo.m; sourceTree = ""; }; BBD49E3B1AC8DEF000610F8E /* RCTVideoManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTVideoManager.h; sourceTree = ""; }; @@ -53,6 +56,8 @@ 58B511D21A9E6C8500147676 = { isa = PBXGroup; children = ( + 31CAFB1F1CADA8CD009BCF6F /* UIView+FindUIViewController.h */, + 31CAFB201CADA8CD009BCF6F /* UIView+FindUIViewController.m */, BBD49E391AC8DEF000610F8E /* RCTVideo.h */, BBD49E3A1AC8DEF000610F8E /* RCTVideo.m */, BBD49E3B1AC8DEF000610F8E /* RCTVideoManager.h */, @@ -117,6 +122,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 31CAFB211CADA8CD009BCF6F /* UIView+FindUIViewController.m in Sources */, BBD49E3F1AC8DEF000610F8E /* RCTVideo.m in Sources */, BBD49E401AC8DEF000610F8E /* RCTVideoManager.m in Sources */, ); diff --git a/UIView+FindUIViewController.h b/UIView+FindUIViewController.h new file mode 100644 index 00000000..09214261 --- /dev/null +++ b/UIView+FindUIViewController.h @@ -0,0 +1,15 @@ +// +// UIView+FindUIViewController.h +// RCTVideo +// +// Created by Stanisław Chmiela on 31.03.2016. +// Copyright © 2016 Facebook. All rights reserved. +// +// Source: http://stackoverflow.com/a/3732812/1123156 + +#import + +@interface UIView (FindUIViewController) +- (UIViewController *) firstAvailableUIViewController; +- (id) traverseResponderChainForUIViewController; +@end diff --git a/UIView+FindUIViewController.m b/UIView+FindUIViewController.m new file mode 100644 index 00000000..bc721b96 --- /dev/null +++ b/UIView+FindUIViewController.m @@ -0,0 +1,28 @@ +// +// UIView+FindUIViewController.m +// RCTVideo +// +// Created by Stanisław Chmiela on 31.03.2016. +// Copyright © 2016 Facebook. All rights reserved. +// +// Source: http://stackoverflow.com/a/3732812/1123156 + +#import "UIView+FindUIViewController.h" + +@implementation UIView (FindUIViewController) +- (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; + } +} +@end