Home > database >  How can I add space Inbetween text as in react native gap css is not working
How can I add space Inbetween text as in react native gap css is not working

Time:08-18

Here I want space between test1 and test2.

import React from "react";
import { StyleSheet, View } from "react-native";

function App() {
  const data = ["test1", "test2", "test3"];

  return (
    <View style={styles.app}>
      {data.map((text) => (
        <span style={styles.span}>{text}</span>
      ))}
    </View>
  );
}

const styles = StyleSheet.create({
  app: {
    marginTop: 30,
    position: "absolute",
    backgroundColor: "yellow",
    left: "8px",
    widht: "auto",
    flexDirection: "row",
    alignItems: "center",
    justifyContent: "space-between"
  },
  span: {
    gap: 20
  }
});

export default App;

But currently it look like this

enter image description here

enter image description here

CodePudding user response:

You need to add the gap property alongside display: flex inside the class app.

import React from "react";
import { StyleSheet, View } from "react-native";

function App() {
  const data = ["test1", "test2", "test3"];

  return (
    <View style={styles.app}>
      {data.map((text) => (
        <span>{text}</span>
      ))}
    </View>
  );
}

const styles = StyleSheet.create({
  app: {
    marginTop: 30,
    position: "absolute",
    backgroundColor: "yellow",
    left: "8px",
    widht: "auto",
    flexDirection: "row",
    display: "flex",
    gap: 10,
    alignItems: "center",
    justifyContent: "space-between"
  }
});

export default App;

enter image description here https://codesandbox.io/s/upbeat-chebyshev-22kuqd?file=/src/App.js:0-573

  • Related