We are trying to center a title in React Native while also getting it pushed against the icons to the right and left as close as possible. As you can see from the image this version on this app doesn’t extend to do that. The developer is doing percentages on the right icons to handle the width of the center title. I am sure there is a better way to handle this situation. The icons on the right will be no more then two icons or less.
[![enter image description here][2]][2]<AppView style={[styles.titleAbsolute]}>
<AppView
useButton={dropDown}
onPress={onTitlePress}
flexDirection="row"
paddingLeft={title?.length > 30 ? 7 : 0}
justifyContent="center"
width={
headerLink?.length > 1
? (AppSizes.width * (dropDown ? 55 : 62)) / 100
: drawerHeader
? '85%'
: !headerLink
? '90%'
: headerLink.length === 1
? '84%'
: '90%'
}
2
Answers
It is achievable by wrapping all items inside a
View
withflexDirection: "row"
and placing the text inside aView
withflex: 1
.Text centre of Icons:
Text centre of screen:
Instead of using percentages, you can utilize flexbox to achieve the desired layout.
How To Align Things In CSS : https://www.smashingmagazine.com/2019/03/css-alignment/
Styling in React: 5 ways to style React apps : https://blog.logrocket.com/styling-react-5-ways-style-react-apps/
Advanced React-Native CSS Layout Techniques : https://zudemwango.medium.com/advanced-react-native-css-layout-techniques-9a6c4d59d9c7