Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

https://codesandbox.io/s/blissful-sea-tlbjso?file=/src/App.js
How can I achive this through css ?

Updated——————————————————

if I add marginRight in span then it will add extra space at the end of the text.
enter image description here

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading