Muhammad Jamali
Muhammad Jamali

Reputation: 44

I want my text to flow to my next line but flex is not letting me do it?

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"
  }
});

Upvotes: 0

Views: 86

Answers (2)

Ajith
Ajith

Reputation: 2666

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"
  },
});

Upvotes: 1

user12319280
user12319280

Reputation:

I think that you use to much Vieuw elements. You should for example use a Text for where your text need to print out.

But I think I have it. You wrapped everything into a View with a style of;

flexDirection: "row",

Not that good if you don't want to have the whole View on one line.... Issue solved?

Upvotes: 0

Related Questions