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

feat: add support for transparent large header on iOS #2501

Merged
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
18 changes: 17 additions & 1 deletion ios/RNSScreenStackHeaderConfig.mm
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,16 @@ + (UINavigationBarAppearance *)buildAppearance:(UIViewController *)vc
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];

if (config.backgroundColor && CGColorGetAlpha(config.backgroundColor.CGColor) == 0.) {
// Preserve the shadow properties in case the user wants to show the shadow on scroll.
UIColor *shadowColor = appearance.shadowColor;
UIImage *shadowImage = appearance.shadowImage;
// transparent background color
[appearance configureWithTransparentBackground];

if (!config.hideShadow) {
appearance.shadowColor = shadowColor;
appearance.shadowImage = shadowImage;
}
} else {
[appearance configureWithOpaqueBackground];
}
Expand Down Expand Up @@ -671,7 +679,15 @@ + (void)updateViewController:(UIViewController *)vc
UINavigationBarAppearance *scrollEdgeAppearance =
[[UINavigationBarAppearance alloc] initWithBarAppearance:appearance];
if (config.largeTitleBackgroundColor != nil) {
scrollEdgeAppearance.backgroundColor = config.largeTitleBackgroundColor;
// Add support for using a fully transparent bar when the backgroundColor is set to transparent.
if (CGColorGetAlpha(config.largeTitleBackgroundColor.CGColor) == 0.) {
// This will also remove the background blur effect in the large title which is otherwise inherited from the standard appearance.
[scrollEdgeAppearance configureWithTransparentBackground];
// This must be set to nil otherwise a default view will be added to the navigation bar background with an opaque background.
scrollEdgeAppearance.backgroundColor = nil;
} else {
scrollEdgeAppearance.backgroundColor = config.largeTitleBackgroundColor;
}
}
if (config.largeTitleHideShadow) {
scrollEdgeAppearance.shadowColor = nil;
Expand Down
Loading