Reputation: 361
I could not align the inner tags of Touchable component here is my code:
render(){
return(
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<TouchablewithoutFeedback onPress={()=> this.incrementCount()}>
<Text style={{alignslef: 'center'>
Count
</Text>
</TouchablewithoutFeedback>
);}
Upvotes: 0
Views: 291
Reputation: 361
This is the answer of my query previously.
render(){
return(
<TouchablewithoutFeedback>
<Text style={{**textAlign:'center'**}}>click here</Text>
</TouchablewithoutFeedback>
);
}
However, I discovered a complete way to style the button properly because the former answer did not fully recover my styling, the text was aligned to the center horizontally successfully but not vertically.
so here is the complete answer:
render(){
return(
<TouchablewithoutFeedback style={styles.btn}>
<Text style={styles.btnText}>
Click me
<Text>
</TouchablewithoutFeedback>
);
}
const styles = StyleSheet.create({
btn:{
width: 200,
height: 200,
justifyContent: 'center',
alignItems: 'center'
},
btnText:{
fontSize: 25,
color: 'red'
}
})
Upvotes: 0
Reputation: 1356
You can include a style prop for TouchableWithoutFeedback
that is alignItems: ‘center’
, or use textAlign
instead of alignSelf
inside Text
’s styles
Upvotes: 1