Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make method for checking if trait is set #1155

Merged
merged 2 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ios/RNSScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ typedef NS_ENUM(NSInteger, RNSWindowTrait) {

- (instancetype)initWithView:(UIView *)view;
- (void)notifyFinishTransitioning;
- (UIViewController *)findChildVCForConfigAndTrait:(RNSWindowTrait)trait includingModals:(BOOL)includingModals;

@end

Expand Down
2 changes: 2 additions & 0 deletions ios/RNSScreenContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

@interface RNScreensViewController : UIViewController <RNScreensViewControllerDelegate>

- (UIViewController *)findActiveChildVC;

@end

@interface RNSScreenContainerManager : RCTViewManager
Expand Down
5 changes: 5 additions & 0 deletions ios/RNSScreenWindowTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@
+ (UIInterfaceOrientationMask)maskFromOrientation:(UIInterfaceOrientation)orientation;
#endif

+ (BOOL)shouldAskScreensForTrait:(RNSWindowTrait)trait
includingModals:(BOOL)includingModals
inViewController:(UIViewController *)vc;
+ (BOOL)shouldAskScreensForScreenOrientationInViewController:(UIViewController *)vc;

@end
29 changes: 29 additions & 0 deletions ios/RNSScreenWindowTraits.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#import "RNSScreenWindowTraits.h"
#import "RNSScreen.h"
#import "RNSScreenContainer.h"
#import "RNSScreenStack.h"

@implementation RNSScreenWindowTraits

Expand Down Expand Up @@ -190,4 +192,31 @@ + (UIInterfaceOrientation)interfaceOrientation
}
#endif

// method to be used in Expo for checking if RNScreens have trait set
+ (BOOL)shouldAskScreensForTrait:(RNSWindowTrait)trait
includingModals:(BOOL)includingModals
inViewController:(UIViewController *)vc
{
UIViewController *lastViewController = [[vc childViewControllers] lastObject];
if ([lastViewController conformsToProtocol:@protocol(RNScreensViewControllerDelegate)]) {
UIViewController *vc = nil;
if ([lastViewController isKindOfClass:[RNScreensViewController class]]) {
vc = [(RNScreensViewController *)lastViewController findActiveChildVC];
} else if ([lastViewController isKindOfClass:[RNScreensNavigationController class]]) {
vc = [(RNScreensNavigationController *)lastViewController topViewController];
}
return [vc isKindOfClass:[RNSScreen class]] &&
[(RNSScreen *)vc findChildVCForConfigAndTrait:trait includingModals:includingModals] != nil;
}
return NO;
}

// same method as above, but directly for orientation
+ (BOOL)shouldAskScreensForScreenOrientationInViewController:(UIViewController *)vc
{
return [RNSScreenWindowTraits shouldAskScreensForTrait:RNSWindowTraitOrientation
includingModals:YES
inViewController:vc];
}

@end