1 | #import "RNSScreenContainer.h"
|
2 | #import "UIViewController+RNScreens.h"
|
3 |
|
4 | #import <objc/runtime.h>
|
5 |
|
6 | @implementation UIViewController (RNScreens)
|
7 |
|
8 | #if !TARGET_OS_TV
|
9 | - (UIViewController *)reactNativeScreensChildViewControllerForStatusBarStyle
|
10 | {
|
11 | UIViewController *childVC = [self findChildRNSScreensViewController];
|
12 | return childVC ?: [self reactNativeScreensChildViewControllerForStatusBarStyle];
|
13 | }
|
14 |
|
15 | - (UIViewController *)reactNativeScreensChildViewControllerForStatusBarHidden
|
16 | {
|
17 | UIViewController *childVC = [self findChildRNSScreensViewController];
|
18 | return childVC ?: [self reactNativeScreensChildViewControllerForStatusBarHidden];
|
19 | }
|
20 |
|
21 | - (UIStatusBarAnimation)reactNativeScreensPreferredStatusBarUpdateAnimation
|
22 | {
|
23 | UIViewController *childVC = [self findChildRNSScreensViewController];
|
24 | return childVC ? childVC.preferredStatusBarUpdateAnimation
|
25 | : [self reactNativeScreensPreferredStatusBarUpdateAnimation];
|
26 | }
|
27 |
|
28 | - (UIInterfaceOrientationMask)reactNativeScreensSupportedInterfaceOrientations
|
29 | {
|
30 | UIViewController *childVC = [self findChildRNSScreensViewController];
|
31 | return childVC ? childVC.supportedInterfaceOrientations : [self reactNativeScreensSupportedInterfaceOrientations];
|
32 | }
|
33 |
|
34 | - (UIViewController *)reactNativeScreensChildViewControllerForHomeIndicatorAutoHidden
|
35 | {
|
36 | UIViewController *childVC = [self findChildRNSScreensViewController];
|
37 | return childVC ?: [self reactNativeScreensChildViewControllerForHomeIndicatorAutoHidden];
|
38 | }
|
39 |
|
40 | - (UIViewController *)findChildRNSScreensViewController
|
41 | {
|
42 | UIViewController *lastViewController = [[self childViewControllers] lastObject];
|
43 | if ([lastViewController conformsToProtocol:@protocol(RNSViewControllerDelegate)]) {
|
44 | return lastViewController;
|
45 | }
|
46 | return nil;
|
47 | }
|
48 |
|
49 | + (void)load
|
50 | {
|
51 | static dispatch_once_t once_token;
|
52 | dispatch_once(&once_token, ^{
|
53 | Class uiVCClass = [UIViewController class];
|
54 |
|
55 | method_exchangeImplementations(
|
56 | class_getInstanceMethod(uiVCClass, @selector(childViewControllerForStatusBarStyle)),
|
57 | class_getInstanceMethod(uiVCClass, @selector(reactNativeScreensChildViewControllerForStatusBarStyle)));
|
58 |
|
59 | method_exchangeImplementations(
|
60 | class_getInstanceMethod(uiVCClass, @selector(childViewControllerForStatusBarHidden)),
|
61 | class_getInstanceMethod(uiVCClass, @selector(reactNativeScreensChildViewControllerForStatusBarHidden)));
|
62 |
|
63 | method_exchangeImplementations(
|
64 | class_getInstanceMethod(uiVCClass, @selector(preferredStatusBarUpdateAnimation)),
|
65 | class_getInstanceMethod(uiVCClass, @selector(reactNativeScreensPreferredStatusBarUpdateAnimation)));
|
66 |
|
67 | method_exchangeImplementations(
|
68 | class_getInstanceMethod(uiVCClass, @selector(supportedInterfaceOrientations)),
|
69 | class_getInstanceMethod(uiVCClass, @selector(reactNativeScreensSupportedInterfaceOrientations)));
|
70 |
|
71 | method_exchangeImplementations(
|
72 | class_getInstanceMethod(uiVCClass, @selector(childViewControllerForHomeIndicatorAutoHidden)),
|
73 | class_getInstanceMethod(uiVCClass, @selector(reactNativeScreensChildViewControllerForHomeIndicatorAutoHidden)));
|
74 | });
|
75 | }
|
76 | #endif
|
77 |
|
78 | @end
|