Search code examples
cssreact-nativeflexboxreact-flexbox-grid

How can I have flex elements shrink to their contents with react-native and align?


I have:

        <StyledSurface style={{ flex: 1, flexDirection: 'row', flexWrap: 'wrap' }}>
            {conversations.map((c, i) => (
                <Surface style={{ backgroundColor: 'red', width: '46%', margin: '2%', flexDirection: 'column', flexShrink: 1, alignSelf: 'flex-start'}} key={i}>
                    <Text style={{flex: 1}}>{c.title}</Text>
                </Surface>
            ))}
        </StyledSurface>

and this ends up looking like:

enter image description here

But I want each red box to shrink (vertically) to fit the contents and have equal spacing?

What am I missing?


Solution

  • On the View container add this:

    alignSelf: 'flex-start',
    

    Should do the trick