Ad

I Want My Text To Flow To My Next Line But Flex Is Not Letting Me Do It?

- 1 answer

I want my app to add text underneath the goal section but flex is not letting me do that even if I create new components in native P.S Still a beginner

import React, { useState } from "react";
import { StyleSheet, View, TextInput, Button, Text } from "react-native";

export default function App() {
  return (
    <View style={styles.Container}>
      <View style={styles.GoalInp}>
        <TextInput
          placeholder="Course Goal"
          style={{ overflow: "scroll" }}
          onChangeText={goalInputHandler}
          value={enteredGoal}
        />
      </View>
      <View>
        <Button title="ADD" onPress={addGoalHandler} />
      </View>
      <View>
        {couseGoals.map(goal => (
          <Text>{goal}</Text>
        ))}
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  Container: {
    padding: 50,
    flexDirection: "row",
    justifyContent: "space-between",
    alignItems: "center"
  },
  GoalInp: {
    borderWidth: 1,
    width: "80%",
    padding: 10,
    borderColor: "black"
  }
});
Ad

Answer

You need to bring the listing outside the Container View, as the flex-direction of Container is row, all items will be in a row including form.

My modified code is given below

  <View style={styles.wrapper}>

    <View style={styles.Container}>
      <View style={styles.GoalInp}>
        <TextInput
          placeholder="Course Goal"
          style={{ overflow: "scroll" }}
        />
      </View>
      <View>
        <Button title="ADD" onPress={this.addGoalHandler} />
      </View>
    </View>

    <View>
      {this.state.couseGoals.map(goal => (
        <Text>{goal}</Text>
      ))}
    </View>

  </View>



const styles = StyleSheet.create({
  wrapper:{
    flex:1,
  },
  Container: {
    padding: 50,
    flexDirection: "row",
    justifyContent: "space-between",
    alignItems: "center"
  },
  GoalInp: {
    borderWidth: 1,
    width: "80%",
    padding: 10,
    borderColor: "black"
  },
});
Ad
source: stackoverflow.com
Ad