Riku
Riku

Reputation: 758

react native flexwrap with alignItems: center is not working

I am working on a responsive design using flex on react-native

<View
    style={{
        flexDirection: 'row',
        alignItems: 'center',
        flexWrap: 'wrap',
        justifyContent: 'space-between',
        paddingHorizontal: 10 
    }}>
    <View style={{ flex: 0, backgroundColor: 'red'}}>
        <Text style={{ fontSize: 22 }}>
            { moment().format('LL') }                               
        </Text>
    </View>
    
    <View style={{flex: 0, backgroundColor: 'blue'}}>
        <Text style={{ fontSize: 22,flex: 1, alignSelf: 'flex-end'}}>
            # 123123123123123
        </Text>
    </View>
</View>

This is working properly on a normal scale font. The output is like this enter image description here

Then, when the device uses a larger scale of font. The output is like this enter image description here

The blue component overflows on the container.

But, when I removed the alignItems: center from the style. It is working fine.

enter image description here

Any other solution or work around for this?

Upvotes: 0

Views: 931

Answers (1)

Kartikey
Kartikey

Reputation: 4992

I think you should design it like this

Working Example Here

<View style={{ width: '100%', flexDirection: 'row' }}>
  <View style={{ flex: 1 }}>
    <Text
      style={{ fontSize: 22 }}
      adjustsFontSizeToFit={true}
      numberOfLines={1}>
      June 23, 2021
    </Text>
  </View>

  <View style={{ flex: 1, alignItems: 'flex-end', justifyContent: 'center' }}>
    <Text
      style={{ fontSize: 22 }}
      adjustsFontSizeToFit={true}
      numberOfLines={1}>
      # 123123123123123
    </Text>
  </View>
</View>

Upvotes: 1

Related Questions