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(ios): set navigation controller’s background color #11184

Merged
merged 8 commits into from
Sep 5, 2019
3 changes: 3 additions & 0 deletions iphone/Classes/TiUINavigationWindowProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ - (void)navigationController:(UINavigationController *)navigationController will
[theWindow windowWillOpen];
[theWindow windowDidOpen];
}
if ([TiUtils isIOSVersionOrGreater:@"13.0"]) {
navController.view.backgroundColor = theWindow.view.backgroundColor;
}
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
Expand Down
8 changes: 8 additions & 0 deletions iphone/Classes/TiUITabProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifdef USE_TI_UITAB

#import "TiUITabProxy.h"
#import "TiUITabGroup.h"
#import "TiUITabGroupProxy.h"
#import <TitaniumKit/ImageLoader.h>
#import <TitaniumKit/TiApp.h>
Expand Down Expand Up @@ -343,6 +344,13 @@ - (void)navigationController:(UINavigationController *)navigationController will
if (!transitionWithGesture) {
transitionIsAnimating = YES;
}
if ([TiUtils isIOSVersionOrGreater:@"13.0"] && [viewController isKindOfClass:[TiViewController class]]) {
TiViewController *toViewController = (TiViewController *)viewController;
if ([[toViewController proxy] isKindOfClass:[TiWindowProxy class]]) {
TiWindowProxy *windowProxy = (TiWindowProxy *)[toViewController proxy];
[((TiUITabGroup *)(tabGroup.view))tabController].view.backgroundColor = windowProxy.view.backgroundColor;
}
}
[self handleWillShowViewController:viewController animated:animated];
}

Expand Down
21 changes: 21 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/Modules/TiUIWindowProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,27 @@ - (void)preferredContentSizeDidChangeForChildContentContainer:(id<UIContentConta

- (void)viewWillAppear:(BOOL)animated; // Called when the view is about to made visible. Default does nothing
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if ([TiUtils isIOSVersionOrGreater:@"13.0"]) {
TiColor *newColor = [TiUtils colorValue:[self valueForKey:@"barColor"]];
if (controller != nil && !(controller.edgesForExtendedLayout == UIRectEdgeTop || controller.edgesForExtendedLayout == UIRectEdgeAll)) {
UINavigationBarAppearance *appearance = controller.navigationController.navigationBar.standardAppearance;
[appearance configureWithTransparentBackground];
if (newColor == nil) {
//Get from TabGroup
newColor = [TiUtils colorValue:[[self tabGroup] valueForKey:@"barColor"]];
}
if (newColor == nil) {
appearance.backgroundColor = self.view.backgroundColor;
} else {
appearance.backgroundColor = newColor.color;
}
controller.navigationController.navigationBar.standardAppearance = appearance;
controller.navigationController.navigationBar.scrollEdgeAppearance = appearance;
controller.navigationController.navigationBar.backgroundColor = UIColor.clearColor;
}
}
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very very hacky and I feel like it's not fixing the actual issue but only workarounding the visual glitches. I hope there can be found a proper fix for this issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, the navigation bar now shows a different color than the background color of the window.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hansemannn Yeah. It's kind of hack. In native apps as well people suggest same. See here. And this will work without any visual issue.

In context of property 'largeTitleEnabled' is 'true' in iOS 13-
A). As for as navigation bar color and transition similar to native behaviour is concerned. For that above SDK changes are not required. To make it work by default we have to make changes as per point C. If you want this to work in your app now, you have to modify your code-

  1. You have to set window's property 'extendEdges' to [Ti.UI.EXTEND_EDGE_TOP]. By default it is Ti.UI.EXTEND_EDGE_NONE.
  2. Set 'translucent' property to 'true'. By default it is 'true'
  3. If you are using tableview, listview or scrollview (basically view’s having scroll view) on window, it will work perfect.
  4. If you are using any other view other than views in point 3, you have to set ‘top’ property of view to height of navigation bar. Otherwise it will move up and overlap with navigation bar.

B). As you have mentioned navigation bar color is different than the bar color. I guess you are using "barColor" property to set. In SDK code barColor has preference over backgroundColor of window. See the attached examples in ticket, it is working fine. You always have option to set 'barColor'.

C). In native development, property 'edgesForExtendedLayout' is by default UIRectEdgeAll and default value of 'translucent' is 'true'. So it takes the background color of controller's view. If you use tableview or scrollview it will work perfect. If you want to create any other view with position (0, 0, width, height). It'll overlap with navigation bar. To avoid this problem there is option to use autolayout constraints.
In titanium auto layout is in beta. So we can not use that.
I'll create a new ticket to change default behaviour of window's property extendEdges to Ti.UI.EXTEND_EDGE_ALL, which apple recommends. And probably need to handle window's layout if there is navigation bar(which will need more work).

shouldUpdateNavBar = YES;
[self setupWindowDecorations];
[super viewWillAppear:animated];
Expand Down