File tree Expand file tree Collapse file tree 7 files changed +91
-28
lines changed
common/cpp/react/renderer/components/multiplemodals Expand file tree Collapse file tree 7 files changed +91
-28
lines changed Original file line number Diff line number Diff line change 44
55namespace facebook ::react
66{
7- Size RNTModalViewSize (void );
7+ Size RNTModalViewSize (void );
88} // namespace facebook::react
Original file line number Diff line number Diff line change 33#import < Foundation/Foundation.h>
44#import < React/RCTUtils.h>
55
6+ #import " RNTModalWindowHelper.h"
7+
68namespace facebook ::react {
79
810Size RNTModalViewSize (void )
911{
10- CGSize screenSize = RCTScreenSize ();
11- return {screenSize.width , screenSize.height };
12+ __block CGSize screenSize = RCTScreenSize ();
13+
14+ dispatch_sync (dispatch_get_main_queue (), ^{
15+ RNTModalWindowHelper *windowHelper = [[RNTModalWindowHelper alloc ] init ];
16+ UIInterfaceOrientation orientation = [windowHelper getWindowOrientation ];
17+
18+ if (UIInterfaceOrientationIsLandscape (orientation)) {
19+ screenSize = CGSizeMake (screenSize.height , screenSize.width );
20+ }
21+ });
22+
23+ return { screenSize.width , screenSize.height };
1224}
1325
14- } // namespace facebook::react
26+ } // namespace facebook::react
Original file line number Diff line number Diff line change 55#import " RNTModalViewController.h"
66
77@protocol RNTModalMountingHelperProtocol <NSObject >
8- - ( instancetype _Nonnull) initWithViewController : (RNTModalViewController *_Nonnull) viewController ;
8+
99- (void )updatePropsTransaction : (void (^__nullable)(void ))completion ;
1010- (void )updateChildrenTransaction : (void (^__nullable)(void ))completion ;
1111- (void )mountIfNeeded ;
1212- (void )unmountIfNeeded ;
13+
1314@end
1415
1516@interface RNTModalMountingHelper : NSObject <RNTModalMountingHelperProtocol>
17+ - (instancetype _Nonnull)init NS_UNAVAILABLE;
18+
19+ - (instancetype _Nonnull)initWithViewController : (RNTModalViewController *_Nonnull)viewController NS_DESIGNATED_INITIALIZER;
1620
1721@property (nonatomic , assign ) BOOL isMounted;
1822@property (nonatomic , assign ) BOOL hasProps;
1923@property (nonatomic , assign ) BOOL hasChildren;
2024@property (nullable , weak ) RNTModalViewController *modal;
2125
22- - (UIWindow *_Nullable)getKeyWindow ;
23- - (UIViewController *_Nullable)getRootController ;
2426- (void )mount ;
2527- (void )unmount ;
2628
Original file line number Diff line number Diff line change 11#import < UIKit/UIKit.h>
22#import " RNTModalMountingHelper.h"
3+ #import " RNTModalWindowHelper.h"
34
45@implementation RNTModalMountingHelper
56
@@ -17,25 +18,6 @@ - (instancetype _Nonnull)initWithViewController:(RNTModalViewController * _Nonnu
1718 return self;
1819}
1920
20- - (UIWindow *)getKeyWindow {
21- for (UIScene *scene in [UIApplication sharedApplication ].connectedScenes ) {
22- if ([scene isKindOfClass: [UIWindowScene class ]]) {
23- UIWindowScene *windowScene = (UIWindowScene *)scene;
24- for (UIWindow *window in windowScene.windows ) {
25- if (window.isKeyWindow ) {
26- return window;
27- }
28- }
29- }
30- }
31-
32- return nil ;
33- }
34-
35- - (UIViewController *)getRootController {
36- return [self getKeyWindow ].rootViewController ;
37- }
38-
3921- (void )updateChildrenTransaction : (void (^ _Nullable)(void ))completion {
4022 dispatch_async (dispatch_get_main_queue (), ^{
4123 if (completion) {
@@ -70,7 +52,8 @@ - (void)unmountIfNeeded {
7052}
7153
7254- (void )mount {
73- UIViewController *rvc = [self getRootController ];
55+ RNTModalWindowHelper *windowHelper = [[RNTModalWindowHelper alloc ] init ];
56+ UIViewController *rvc = [windowHelper getRootController ];
7457
7558 if (!rvc) {
7659 NSLog (@" reactViewController not found" );
Original file line number Diff line number Diff line change 1+ #import < UIKit/UIKit.h>
2+ #import " RNTModalWindowHelper.h"
3+
4+ @implementation RNTModalWindowHelper
5+
6+ - (UIWindow *)getKeyWindow
7+ {
8+ for (UIScene *scene in [UIApplication sharedApplication ].connectedScenes )
9+ {
10+ if ([scene isKindOfClass: [UIWindowScene class ]])
11+ {
12+ UIWindowScene *windowScene = (UIWindowScene *)scene;
13+ for (UIWindow *window in windowScene.windows )
14+ {
15+ if (window.isKeyWindow )
16+ {
17+ return window;
18+ }
19+ }
20+ }
21+ }
22+
23+ return nil ;
24+ }
25+
26+ - (UIViewController *)getRootController
27+ {
28+ return [self getKeyWindow ].rootViewController ;
29+ }
30+
31+ - (UIInterfaceOrientation)getWindowOrientation
32+ {
33+ return [self getKeyWindow ].windowScene .interfaceOrientation ?: UIInterfaceOrientationPortrait;
34+ }
35+
36+ @end
Original file line number Diff line number Diff line change 1+ #ifndef RNTModalWindowHelper_h
2+ #define RNTModalWindowHelper_h
3+
4+ #import < UIKit/UIKit.h>
5+
6+ @protocol RNTModalWindowHelperProtocol <NSObject >
7+
8+ - (UIWindow *_Nullable)getKeyWindow ;
9+ - (UIViewController *_Nullable)getRootController ;
10+ - (UIInterfaceOrientation)getWindowOrientation ;
11+
12+ @end
13+
14+ @interface RNTModalWindowHelper : NSObject <RNTModalWindowHelperProtocol>
15+
16+ @end
17+
18+ #endif /* RNTModalWindowHelper_h */
Original file line number Diff line number Diff line change 33#import " RCTBridge.h"
44#import " RCTShadowView.h"
55#import " RCTUtils.h"
6+ #import " RNTModalWindowHelper.h"
67
78@implementation RNTModalShadowView
89
910- (void )insertReactSubview : (id <RCTComponent>)subview atIndex : (NSInteger )atIndex
1011{
1112 [super insertReactSubview: subview atIndex: atIndex];
1213 if ([subview isKindOfClass: [RCTShadowView class ]]) {
13- ((RCTShadowView *)subview).size = RCTScreenSize ();
14+ dispatch_sync (dispatch_get_main_queue (), ^{
15+ RNTModalWindowHelper *windowHelper = [[RNTModalWindowHelper alloc ] init ];
16+ UIInterfaceOrientation orientation = [windowHelper getWindowOrientation ];
17+
18+ CGSize screenSize = RCTScreenSize ();
19+
20+ if (UIInterfaceOrientationIsPortrait (orientation)) {
21+ ((RCTShadowView *)subview).size = screenSize;
22+ } else {
23+ ((RCTShadowView *)subview).size = CGSizeMake (screenSize.height , screenSize.width );
24+ }
25+ });
1426 }
1527}
1628
You can’t perform that action at this time.
0 commit comments