diff --git a/iphone/TitaniumKit/TitaniumKit/Sources/Modules/TiUIWindowProxy.m b/iphone/TitaniumKit/TitaniumKit/Sources/Modules/TiUIWindowProxy.m index 544dce4727e..3a092ec3dd5 100644 --- a/iphone/TitaniumKit/TitaniumKit/Sources/Modules/TiUIWindowProxy.m +++ b/iphone/TitaniumKit/TitaniumKit/Sources/Modules/TiUIWindowProxy.m @@ -276,30 +276,28 @@ - (void)viewWillAppear:(BOOL)animated; // Called when the view is about to made { #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 // TO DO: Refactor navigation bar customisation iOS 13 - if ([TiUtils isIOSVersionOrGreater:@"13.0"]) { + if ([self shouldUseNavBarApperance]) { TiColor *newColor = [TiUtils colorValue:[self valueForKey:@"barColor"]]; if (newColor == nil) { newColor = [TiUtils colorValue:[[self tabGroup] valueForKey:@"barColor"]]; } - if (controller != nil && !(controller.edgesForExtendedLayout == UIRectEdgeTop || controller.edgesForExtendedLayout == UIRectEdgeAll)) { - UINavigationBarAppearance *appearance = controller.navigationController.navigationBar.standardAppearance; - if ([TiUtils boolValue:[self valueForKey:@"largeTitleEnabled"] def:NO]) { - [appearance configureWithTransparentBackground]; - if (newColor == nil) { - appearance.backgroundColor = self.view.backgroundColor; - } else { - appearance.backgroundColor = newColor.color; - } + UINavigationBarAppearance *appearance = controller.navigationController.navigationBar.standardAppearance; + if ([TiUtils boolValue:[self valueForKey:@"largeTitleEnabled"] def:NO]) { + [appearance configureWithTransparentBackground]; + if (newColor == nil) { + appearance.backgroundColor = self.view.backgroundColor; } else { - [appearance configureWithDefaultBackground]; - if (newColor != nil) { - appearance.backgroundColor = newColor.color; - } + appearance.backgroundColor = newColor.color; + } + } else { + [appearance configureWithDefaultBackground]; + if (newColor != nil) { + appearance.backgroundColor = newColor.color; } - controller.navigationController.navigationBar.standardAppearance = appearance; - controller.navigationController.navigationBar.scrollEdgeAppearance = appearance; - controller.navigationController.navigationBar.backgroundColor = UIColor.clearColor; } + controller.navigationController.navigationBar.standardAppearance = appearance; + controller.navigationController.navigationBar.scrollEdgeAppearance = appearance; + controller.navigationController.navigationBar.backgroundColor = UIColor.clearColor; } #endif shouldUpdateNavBar = YES; @@ -410,7 +408,7 @@ - (void)setTitleAttributes:(id)args UINavigationBar *navigationBar = controller.navigationController.navigationBar; if ([TiUtils isIOSVersionOrGreater:@"11.0"] && [TiUtils boolValue:[self valueForKey:@"largeTitleEnabled"] def:NO]) { #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 - if ([TiUtils isIOSVersionOrGreater:@"13.0"]) { + if ([self shouldUseNavBarApperance]) { navigationBar.standardAppearance.largeTitleTextAttributes = theAttributes; navigationBar.scrollEdgeAppearance.largeTitleTextAttributes = theAttributes; } @@ -418,7 +416,7 @@ - (void)setTitleAttributes:(id)args navigationBar.largeTitleTextAttributes = theAttributes; } #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 - if ([TiUtils isIOSVersionOrGreater:@"13.0"]) { + if ([self shouldUseNavBarApperance]) { navigationBar.standardAppearance.titleTextAttributes = theAttributes; navigationBar.scrollEdgeAppearance.titleTextAttributes = theAttributes; } @@ -427,6 +425,11 @@ - (void)setTitleAttributes:(id)args } } +- (BOOL)shouldUseNavBarApperance +{ + return ([TiUtils isIOSVersionOrGreater:@"13.0"] && (controller != nil) && !(controller.edgesForExtendedLayout == UIRectEdgeTop || controller.edgesForExtendedLayout == UIRectEdgeAll)); +} + - (void)updateBarImage { if (controller == nil || [controller navigationController] == nil || !shouldUpdateNavBar) { @@ -445,12 +448,11 @@ - (void)updateBarImage UIImage *resizableImage = [theImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeStretch]; #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 - if ([TiUtils isIOSVersionOrGreater:@"13.0"]) { + if ([self shouldUseNavBarApperance]) { ourNB.standardAppearance.backgroundImage = resizableImage; ourNB.scrollEdgeAppearance.backgroundImage = resizableImage; } #endif - [ourNB setBackgroundImage:resizableImage forBarMetrics:UIBarMetricsDefault]; @@ -462,7 +464,7 @@ - (void)updateBarImage UIImage *resizableImage = [theImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeStretch]; ourNB.shadowImage = resizableImage; #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 - if ([TiUtils isIOSVersionOrGreater:@"13.0"]) { + if ([self shouldUseNavBarApperance]) { ourNB.standardAppearance.shadowImage = resizableImage; ourNB.scrollEdgeAppearance.shadowImage = resizableImage; } @@ -473,7 +475,7 @@ - (void)updateBarImage //Set an empty Image. ourNB.shadowImage = [[[UIImage alloc] init] autorelease]; #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 - if ([TiUtils isIOSVersionOrGreater:@"13.0"]) { + if ([self shouldUseNavBarApperance]) { ourNB.standardAppearance.shadowColor = nil; ourNB.scrollEdgeAppearance.shadowColor = nil; }