Width and Height In react-native

please explain by what principle view sizes with element style are formed. I learned FlexBox however it breaks all my understanding.

code

export const App = () => {
  return (
    <SafeAreaView>
      <View style={styles.container}>
        <View style={styles.element}>
          <View style={styles.element1}></View>
        </View>
      </View>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  container: {
    width: '100%',
    height: '100%',
    backgroundColor: 'green',
  },
  element: {
    // width: '100%',
    // height: '100%',
    backgroundColor: 'yellow',
    // top: '5%',
  },
  element1: {
    width: '50%',
    height: '80%',
    backgroundColor: 'red',
  },
});

Upvotes: 1

Views: 150

Answers (1)

You can use flex: 1 instead of width: '100%', height: '100%',.

The Flex: 1 means the component (In case, the view) have a priority value of 1, wich means, if there'snt another component on the same view with flex: 1, the component will take the entire screen. If, there's two components with flex: 1, each one will take 50% of the entire screen.

Here's the documentation: React native flexbox

Upvotes: 1

Related Questions