Search code examples
javascriptcssreact-nativeflexboxreact-native-web

Flexbox generator does not display well in my react application


I am testing https://yogalayout.com/playground and have created that template:

import React, {Component} from 'react';
import {View} from 'react-native';

export default class MyLayout extends Component {
  render() {
    return (
      <View style={{
        flex: 1,
        width: 500,
        height: 500,
        justifyContent: 'space-between',
      backgroundColor: 'red',
      }}>
        <View style={{
          flex: 1,
          width: 100,
          height: 100,
          backgroundColor: 'blue',
        }} />
        <View style={{
          flex: 1,
          width: 100,
          height: 100,
          backgroundColor: 'green',
        }} />
        <View style={{
          flex: 1,
          width: 100,
          height: 100,
          backgroundColor: 'purple',
        }} />
      </View>
    );
  }
};

I expect to have this result:

flexbox normal

Instead, I have this:

flexbox broken

What could have break my flexbox layout?


Solution

  • The default flexDirection is column in React Native. So, try setting it to row in your container View.

    <View style={{
            flex: 1,
            width: 500,
            height: 500,
            justifyContent: 'space-between',
            backgroundColor: 'red',
            flexDirection: "row"
          }}>
      .
      .
      .