Sri
Sri

Reputation: 5845

React Native: "Auto" width for text node

I have a text element inside a view:

<View><Text>hello world foo bar</Text></View>

as part of a flex grid.

I want this view to have an auto width based on the content i.e. length of the text.

How do I achieve this?

Upvotes: 27

Views: 23064

Answers (2)

Audrius
Audrius

Reputation: 33

you can always set minWidth: some width and then align it to the center

Upvotes: 0

Ivan Chernykh
Ivan Chernykh

Reputation: 42166

You can achieve this if element will have alignSelf property, like:

alignSelf: 'flex-start'

or

alignSelf: 'center'

Upvotes: 64

Related Questions