Skip to content

Feature/presentation style #92

New issue

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

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

Already on GitHub? # to your account

Closed
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: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,9 @@ All styles are optional, this is the format of the style object:
tabBarHidden: false, // make the screen content hide the tab bar (remembered across pushes)
statusBarHideWithNavBar: false // hide the status bar if the nav bar is also hidden, useful for navBarHidden:true
statusBarHidden: false, // make the status bar hidden regardless of nav bar state
statusBarTextColorScheme: 'dark' // text color of status bar, 'dark' / 'light' (remembered across pushes)
statusBarTextColorScheme: 'dark', // text color of status bar, 'dark' / 'light' (remembered across pushes),
backgroundColor: '#ffffff', // background color of the view controller contained in the navigation bar
modalPresentationStyle: 'fullScreen' // How the view controller should be presented
}
```

Expand Down
38 changes: 38 additions & 0 deletions ios/RCCManagerModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ @implementation RCTConvert (RCCManagerModuleErrorCode)
(@{@"RCCManagerModuleCantCreateControllerErrorCode": @(RCCManagerModuleCantCreateControllerErrorCode),
@"RCCManagerModuleCantFindTabControllerErrorCode": @(RCCManagerModuleCantFindTabControllerErrorCode),
}), RCCManagerModuleCantCreateControllerErrorCode, integerValue)

@end

@implementation RCTConvert (UIModalPresentationStyle)

RCT_ENUM_CONVERTER(UIModalPresentationStyle,
(@{@"fullScreen": @(UIModalPresentationFullScreen),
@"pageSheet": @(UIModalPresentationPageSheet),
@"formSheet": @(UIModalPresentationFormSheet),
@"currentContext": @(UIModalPresentationCurrentContext),
@"custom": @(UIModalPresentationCustom),
@"overFullScreen": @(UIModalPresentationOverFullScreen),
@"overCurrentContext": @(UIModalPresentationOverCurrentContext),
@"popover": @(UIModalPresentationPopover),
@"none": @(UIModalPresentationNone)
}), UIModalPresentationFullScreen, integerValue)

@end

@implementation RCCManagerModule
Expand All @@ -35,10 +52,20 @@ @implementation RCCManagerModule

- (NSDictionary *)constantsToExport
{

return @{
//Error codes
@"RCCManagerModuleCantCreateControllerErrorCode" : @(RCCManagerModuleCantCreateControllerErrorCode),
@"RCCManagerModuleCantFindTabControllerErrorCode" : @(RCCManagerModuleCantFindTabControllerErrorCode),
@"PresentFullScreen": @"fullScreen",
@"PresentPageSheet": @"pageSheet",
@"PresentFormSheet": @"formSheet",
@"PresentCurrentContext": @"currentContext",
@"PresentCustom": @"custom",
@"PresentOverFullScreen": @"overFullScreen",
@"PresentOverCurrentContext": @"overCurrentContext",
@"PresentPopover": @"popover",
@"PresentNone": @"none"
};
}

Expand Down Expand Up @@ -300,6 +327,17 @@ -(void)performSetRootController:(NSDictionary*)layout animationType:(NSString*)a
error:[RCCManagerModule rccErrorWithCode:RCCManagerModuleCantCreateControllerErrorCode description:@"could not create controller"]];
return;
}

if (layout[@"props"] && [layout[@"props"] isKindOfClass:[NSDictionary class]] && layout[@"props"][@"style"] && [layout[@"props"][@"style"] isKindOfClass: [NSDictionary class]]) {

NSDictionary *style = layout[@"props"][@"style"];
if (style[@"modalPresentationStyle"] && [style[@"modalPresentationStyle"] isKindOfClass:[NSString class]]) {

NSString *presentationStyle = style[@"modalPresentationStyle"];
UIModalPresentationStyle modalPresentationStyle = [RCTConvert UIModalPresentationStyle:presentationStyle];
controller.modalPresentationStyle = modalPresentationStyle;
}
}

[[RCCManagerModule lastModalPresenterViewController] presentViewController:controller
animated:![animationType isEqualToString:@"none"]
Expand Down
7 changes: 7 additions & 0 deletions ios/RCCViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ -(void)setStyleOnAppearForViewController:(UIViewController*)viewController
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
}

NSString *backgroundColor = self.navigatorStyle[@"backgroundColor"];
if (backgroundColor)
{
UIColor *color = backgroundColor != (id)[NSNull null] ? [RCTConvert UIColor:backgroundColor] : nil;
viewController.view.backgroundColor = color;
}
}

-(void)storeOriginalNavBarImages {
Expand Down