Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native avoid {width: '100%'} by default

My code is pretty simple: (relevant parts shown only)

<ScrollView style={{/* padding, centering... */}>
  <Text>SHARE WITH YOU FRIENDS</Text>
</ScrollView>

Yet, when I inspect the Text node, its width is 100% of its container, and the grey background goes all the width.

Is there a layout setting to make this Text's width as small as possible? I.e. only until the end of the Text.

demo

like image 355
jeanpaul62 Avatar asked Jul 10 '26 04:07

jeanpaul62


2 Answers

You can use alignSelf property:

<View style={{alignSelf: 'flex-start'}}> 
    <Text>SHARE WITH YOU FRIENDS</Text>
</View>
like image 110
M Reza Avatar answered Jul 18 '26 14:07

M Reza


For Scroll view you can try like

<ScrollView contentContainerStyle={{ alignItems: 'flex-start'}}>
    <Text >SHARE WITH YOU FRIENDS</Text>
</ScrollView>

Hope this will help!

like image 41
Prasun Avatar answered Jul 18 '26 13:07

Prasun