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

Separate iOS specific code (Fix tvOS build) #598

Merged
merged 5 commits into from
Aug 26, 2020
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
4 changes: 4 additions & 0 deletions ios/RNSScreen.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ - (void)setStackPresentation:(RNSScreenStackPresentation)stackPresentation
case RNSScreenStackPresentationFullScreenModal:
_controller.modalPresentationStyle = UIModalPresentationFullScreen;
break;
#if (TARGET_OS_IOS)
case RNSScreenStackPresentationFormSheet:
_controller.modalPresentationStyle = UIModalPresentationFormSheet;
break;
#endif
case RNSScreenStackPresentationTransparentModal:
_controller.modalPresentationStyle = UIModalPresentationOverFullScreen;
break;
Expand Down Expand Up @@ -128,9 +130,11 @@ - (void)setStackAnimation:(RNSScreenStackAnimation)stackAnimation
case RNSScreenStackAnimationFade:
_controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
break;
#if (TARGET_OS_IOS)
case RNSScreenStackAnimationFlip:
_controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
break;
#endif
case RNSScreenStackAnimationNone:
case RNSScreenStackAnimationDefault:
// Default
Expand Down
2 changes: 2 additions & 0 deletions ios/RNSScreenStack.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ - (void)reactAddControllerToClosestParent:(UIViewController *)controller
if (parentView.reactViewController) {
[parentView.reactViewController addChildViewController:controller];
[self addSubview:controller.view];
#if (TARGET_OS_IOS)
_controller.interactivePopGestureRecognizer.delegate = self;
#endif
[controller didMoveToParentViewController:parentView.reactViewController];
// On iOS pre 12 we observed that `willShowViewController` delegate method does not always
// get triggered when the navigation controller is instantiated. As the only thing we do in
Expand Down
21 changes: 17 additions & 4 deletions ios/RNSScreenStackHeaderConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ + (void)setAnimatedConfig:(UIViewController *)vc withConfig:(RNSScreenStackHeade
[navbar setTintColor:[config.color colorWithAlphaComponent:CGColorGetAlpha(config.color.CGColor) - 0.01]];
[navbar setTintColor:config.color];

#ifdef __IPHONE_13_0
#if defined(__IPHONE_13_0) && TARGET_OS_IOS
if (@available(iOS 13.0, *)) {
// font customized on the navigation item level, so nothing to do here
} else
Expand Down Expand Up @@ -161,6 +161,7 @@ + (void)setAnimatedConfig:(UIViewController *)vc withConfig:(RNSScreenStackHeade
[navbar setTitleTextAttributes:attrs];
}

#if (TARGET_OS_IOS)
if (@available(iOS 11.0, *)) {
if (config.largeTitle && (config.largeTitleFontFamily || config.largeTitleFontSize || config.largeTitleColor || config.titleColor)) {
NSMutableDictionary *largeAttrs = [NSMutableDictionary new];
Expand All @@ -176,6 +177,7 @@ + (void)setAnimatedConfig:(UIViewController *)vc withConfig:(RNSScreenStackHeade
[navbar setLargeTitleTextAttributes:largeAttrs];
}
}
#endif
}
}

Expand Down Expand Up @@ -244,7 +246,9 @@ + (UIImage*)loadBackButtonImageInViewController:(UIViewController *)vc
// in order for new back button image to be loaded we need to trigger another change
// in back button props that'd make UIKit redraw the button. Otherwise the changes are
// not reflected. Here we change back button visibility which is then immediately restored
#if (TARGET_OS_IOS)
vc.navigationItem.hidesBackButton = YES;
#endif
[config updateViewControllerIfNeeded];
}];
}
Expand All @@ -262,7 +266,7 @@ + (void)willShowViewController:(UIViewController *)vc animated:(BOOL)animated wi
[self updateViewController:vc withConfig:config animated:animated];
}

#ifdef __IPHONE_13_0
#if defined(__IPHONE_13_0) && TARGET_OS_IOS
+ (UINavigationBarAppearance*)buildAppearance:(UIViewController *)vc withConfig:(RNSScreenStackHeaderConfig *)config
{
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
Expand Down Expand Up @@ -357,6 +361,7 @@ + (void)updateViewController:(UIViewController *)vc withConfig:(RNSScreenStackHe
}

navitem.title = config.title;
#if (TARGET_OS_IOS)
if (config.backTitle != nil || config.backTitleFontFamily || config.backTitleFontSize) {
prevItem.backBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:config.backTitle ?: prevItem.title
Expand All @@ -383,7 +388,9 @@ + (void)updateViewController:(UIViewController *)vc withConfig:(RNSScreenStackHe
}
navitem.largeTitleDisplayMode = config.largeTitle ? UINavigationItemLargeTitleDisplayModeAlways : UINavigationItemLargeTitleDisplayModeNever;
}
#ifdef __IPHONE_13_0
#endif

#if defined(__IPHONE_13_0) && TARGET_OS_IOS
if (@available(iOS 13.0, *)) {
UINavigationBarAppearance *appearance = [self buildAppearance:vc withConfig:config];
navitem.standardAppearance = appearance;
Expand All @@ -400,6 +407,7 @@ + (void)updateViewController:(UIViewController *)vc withConfig:(RNSScreenStackHe
} else
#endif
{
#if (TARGET_OS_IOS)
// updating backIndicatotImage does not work when called during transition. On iOS pre 13 we need
// to update it before the navigation starts.
UIImage *backButtonImage = [self loadBackButtonImageInViewController:vc withConfig:config];
Expand All @@ -410,15 +418,20 @@ + (void)updateViewController:(UIViewController *)vc withConfig:(RNSScreenStackHe
navctr.navigationBar.backIndicatorImage = nil;
navctr.navigationBar.backIndicatorTransitionMaskImage = nil;
}
#endif
}
#if (TARGET_OS_IOS)
navitem.hidesBackButton = config.hideBackButton;
#endif
navitem.leftBarButtonItem = nil;
navitem.rightBarButtonItem = nil;
navitem.titleView = nil;
for (RNSScreenStackHeaderSubview *subview in config.reactSubviews) {
switch (subview.type) {
case RNSScreenStackHeaderSubviewTypeLeft: {
#if (TARGET_OS_IOS)
navitem.leftItemsSupplementBackButton = config.backButtonInCustomView;
#endif
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:subview];
navitem.leftBarButtonItem = buttonItem;
break;
Expand Down Expand Up @@ -521,7 +534,7 @@ + (NSMutableDictionary *)blurEffectsForIOSVersion

}];
}
#ifdef __IPHONE_13_0
#if defined(__IPHONE_13_0) && TARGET_OS_IOS
if (@available(iOS 13.0, *)) {
[blurEffects addEntriesFromDictionary:@{
@"systemUltraThinMaterial": @(UIBlurEffectStyleSystemUltraThinMaterial),
Expand Down