Commit 6ab72c4c authored by Stanisław Chmiela's avatar Stanisław Chmiela
Browse files

Move View Controller retrieval to external UIView category

parent 8ebfa6e4
Loading
Loading
Loading
Loading
+0 −20
Changes for RCTVideo.m: 0 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -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
+6 −0
Changes for RCTVideo.xcodeproj/project.pbxproj: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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 = "<group>"; };
		31CAFB201CADA8CD009BCF6F /* UIView+FindUIViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+FindUIViewController.m"; sourceTree = "<group>"; };
		BBD49E391AC8DEF000610F8E /* RCTVideo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTVideo.h; sourceTree = "<group>"; };
		BBD49E3A1AC8DEF000610F8E /* RCTVideo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTVideo.m; sourceTree = "<group>"; };
		BBD49E3B1AC8DEF000610F8E /* RCTVideoManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTVideoManager.h; sourceTree = "<group>"; };
@@ -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 */,
			);
+15 −0
Changes for UIView+FindUIViewController.h: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
//
//  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 <UIKit/UIKit.h>

@interface UIView (FindUIViewController)
- (UIViewController *) firstAvailableUIViewController;
- (id) traverseResponderChainForUIViewController;
@end
+28 −0
Changes for UIView+FindUIViewController.m: 28 added lines, 0 removed lines.
Original line number Diff line number Diff line
//
//  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