Skip to content

Commit

Permalink
fix(ios): navBar properties not working properly with extendEdges set…
Browse files Browse the repository at this point in the history
… to Ti.UI.EXTEND_EDGE_TOP (#11377)

* fix(ios): navBar properties not working properly

* fix(ios): revert unnecessary changes
  • Loading branch information
vijaysingh-axway authored and ssekhri committed Dec 12, 2019
1 parent b999f27 commit d673c36
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions iphone/TitaniumKit/TitaniumKit/Sources/Modules/TiUIWindowProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -410,15 +408,15 @@ - (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;
}
#endif
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;
}
Expand All @@ -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) {
Expand All @@ -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];

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit d673c36

Please sign in to comment.