react-native-navigation icon indicating copy to clipboard operation
react-native-navigation copied to clipboard

[v2] `topBar.buttonColor` is ignored for back button

Open ilovett opened this issue 8 years ago • 21 comments

topBar: {
  buttonColor: 'red'
}

Did not work, but

backButton: {
  color: 'red'
}

Did

ilovett avatar Jun 27 '18 19:06 ilovett

This seems to be a difference between iOS and android. On android, I need to use

backButton: {
  color: 'red'
}

on iOS, I need to use:

buttonColor: 'red'

ujwal-setlur avatar Jul 05 '18 08:07 ujwal-setlur

Where are you specifying:

backButton: {
  color: 'red'
}

within topBar? within the screen's static options object? I've tried that everywhere I can think to try and I'm not having any luck affecting the color of the Android back button.

derrh avatar Jul 16 '18 21:07 derrh

I set it in the default options:

 // default options for navigation bar
  Navigation.setDefaultOptions({
    topBar: {
      backButton: { // android
        color: "rgba(60, 109, 240, 0.87)"
      },
      buttonColor: "rgba(60, 109, 240, 0.87)", // iOS
      title: {
        color: "rgba(60, 109, 240, 0.87)",
        fontFamily: "Nunito-Bold",
        fontSize: 18
      }
    },
    bottomTab: {
      iconColor: "black",
      selectedIconColor: "#3c6df0",
      backgroundColor: "white",
      fontFamily: "Nunito",
      fontSize: 10
    }
  });

ujwal-setlur avatar Jul 16 '18 21:07 ujwal-setlur

thanks @ujwal-setlur using both of the button options you set worked for me :)

oldtinroof avatar Jul 22 '18 17:07 oldtinroof

Sadly it isn't working for me. It makes the Android back button (topBar) the color I want, but ios is greyed out instead of the color I set.

HoogsterInc avatar Aug 02 '18 21:08 HoogsterInc

@guyca These two params should be easy to merge to one? Now I have to use two different params like @ujwal-setlur showed us

henrikra avatar Aug 09 '18 12:08 henrikra

@ujwal-setlur Looks like your solution is not working 2.0.2462 onwards. Ref: https://github.com/wix/react-native-navigation/issues/3731

henrikra avatar Aug 10 '18 08:08 henrikra

@henrikra Unfortunately, that seems to be the case :-(. For me, it works on Android, but on iOS, it is ignored.

ujwal-setlur avatar Aug 10 '18 10:08 ujwal-setlur

Here is a patch that will address it:

--- a/node_modules/react-native-navigation/lib/ios/RNNBackButtonOptions.h
+++ b/node_modules/react-native-navigation/lib/ios/RNNBackButtonOptions.h
@@ -8,5 +8,7 @@
 @property (nonatomic, strong) NSString* transition;
 @property (nonatomic, strong) NSNumber* showTitle;
 @property (nonatomic, strong) NSNumber* color;
+@property (nonatomic, strong) NSString* fontFamily;
+@property (nonatomic, strong) NSNumber* fontSize;
 
 @end
--- a/node_modules/react-native-navigation/lib/ios/RNNBackButtonOptions.m
+++ b/node_modules/react-native-navigation/lib/ios/RNNBackButtonOptions.m
@@ -11,12 +11,46 @@ - (void)applyOn:(UIViewController *)viewController {
 		
 		UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:nil action:nil];
 		viewController.navigationItem.backBarButtonItem = backItem;
-	} else if (self.title) {
-		UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:self.title
+	} else {
+		NSString *title;
+		
+		if(self.title) {
+			title = self.title;			
+		} else {
+			title = viewController.navigationItem.title;
+		}
+        
+		UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:title
 																	 style:UIBarButtonItemStylePlain
 																	target:nil
 																	action:nil];
 		
+		if (self.color) {
+			[backItem setTintColor:[RCTConvert UIColor:self.color]];
+		}
+		
+		if(self.fontFamily || self.fontSize) {
+			NSNumber* fontSize = self.fontSize;
+			NSString* fontFamily = self.fontFamily;
+			NSMutableDictionary* textAttributes = [[NSMutableDictionary alloc] init];
+			UIFont *font = nil;
+
+			
+			if (!fontSize) {
+				fontSize = [[NSNumber alloc] initWithInt: 18];
+			}
+			
+			if (fontFamily) {
+				font = [UIFont fontWithName:fontFamily size:[fontSize floatValue]];}
+			else {
+				font = [UIFont systemFontOfSize:[fontSize floatValue]];
+			}
+			[textAttributes setObject:font forKey:NSFontAttributeName];
+	
+			[backItem setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
+			[backItem setTitleTextAttributes:textAttributes forState:UIControlStateHighlighted];
+		}
+		
 		viewController.navigationItem.backBarButtonItem = backItem;
 	}
 	

This will allow you to specify:

  Navigation.setDefaultOptions({
    topBar: {
      backButton: {
        color: "red",
        fontFamily: "Nunito",
        fontSize: 12,
        title: "boo"
      },
      title: {
        color: "red",
        fontFamily: "Nunito-Bold",
        fontSize: 18
      }
    }
  });

ujwal-setlur avatar Aug 11 '18 08:08 ujwal-setlur

Is it still supposed to work? This does not change topBar button back button color on iOS for me. react-native-navigation 2.0.2485.

terreb avatar Aug 21 '18 09:08 terreb

Please check PR #3755

ujwal-setlur avatar Aug 21 '18 09:08 ujwal-setlur

This is fixed in version 2.0.2567. Please close and reopen if the bug is still there :)

henrikra avatar Sep 27 '18 11:09 henrikra

I'm not able to change colors in Navigation.push. It works only with setDefaultOptions. Using 2.0.2569

ricocrescenzio95 avatar Sep 29 '18 21:09 ricocrescenzio95

@henrikra Not working for me, 2.0.2577 only for iOS On android works fine

DenisBogatirov avatar Oct 08 '18 14:10 DenisBogatirov

Still not working on iOS, v. 2.0.2582

terreb avatar Oct 15 '18 15:10 terreb

Still not working on IOS, v.2.0.2584

GibranPolonsky avatar Oct 17 '18 22:10 GibranPolonsky

@ujwal-setlur setDefaultOptions is working fine on v2.1.2

immortalx avatar Nov 07 '18 08:11 immortalx

For me this works on iOS only once I use:

backButton: {
  color: COLOR.WHITE, // For back button text
},
buttonColor: COLOR.WHITE, // For custom top bar buttons

The only issue I see here is that backButton.coloris not documented

alexcoady avatar Dec 03 '18 20:12 alexcoady

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

stale[bot] avatar Jan 04 '19 00:01 stale[bot]

The issue has been closed for inactivity.

stale[bot] avatar Jan 12 '19 19:01 stale[bot]