I'm using react-navigation for navigate between screen.
In ios it display on center and working properly but in android it display left side and space between back button and title.
I want to remove space between back button and title on android.
My Code
class Detail extends Component {
.
.
.
static navigationOptions = ({ navigation }) => {
const {state} = navigation;
return {
headerTitle: "title",
headerStyle: {
borderBottomColor: 'transparent',
borderBottomWidth: 0,
backgroundColor: 'transparent',
elevation: 0 ,
shadowOpacity: 0,
shadowColor: 'transparent',
shadowRadius: 0,
shadowOffset: {
width: 0,
height: 0
}
},
headerTitleStyle: {
color: 'white',
width: width-72,
},
headerBackTitleStyle: {
color: 'white',
},
headerTintColor: 'white',
headerBackground: (
<LinearGradient
colors={[MyConstants.colorNavbarStart, MyConstants.colorNavbarEnd]}
style={{ flex: 1 ,padding: 0}}
start={{x: 0, y: 0.5}}
end={{x: 1, y: 0.5}} />
),
headerRight: (
<TouchableOpacity>
<View style={{padding: 8}}>
<Image source={MyConstants.imgShareArrow} style={{height:20, width: 20}} />
</View>
</TouchableOpacity>
),
headerLeft: (
<TouchableOpacity onPress={ () => {navigation.pop()}}>
<View style={{padding: 8}}>
<Image source={MyConstants.imgBackArrow} style={MyStyle.backButton} />
</View>
</TouchableOpacity>
)
};
};
}
In above code width is screen width and i'm using -72 because left and right button width.
I'm also using marginLeft in minus but it cut the title.
As of today, with the latest version of React Native Navigation, this issue still persists. In this thread there a number of "hacks" presented but the real issue is obvious in the library itself. Just to reiterate the problem; on Android, the title is not centered correctly when a button on the left is shown (like a Back button).
You can go back to an existing screen in the stack with navigation.navigate ('RouteName'), and you can go back to the first screen in the stack with navigation.popToTop (). The navigation prop is available to all screen components (components defined as screens in route configuration and rendered by React Navigation as a route).
The header provided by the native stack navigator will automatically include a back button when it is possible to go back from the active screen (if there is only one screen in the navigation stack, there is nothing that you can go back to, and so there is no back button).
Sometimes you'll want to be able to programmatically trigger this behavior, and for that you can use navigation.goBack ();. On Android, React Navigation hooks in to the hardware back button and fires the goBack () function for you when the user presses it, so it behaves as the user would expect.
to remove space between back button and title you can use:
headerTitleContainerStyle: {
left: 0,
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With