Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
483 views
in Technique[技术] by (71.8m points)

react native text justify and center

In react native we have textAlign property with the options to either "justify" (and the last line will follow default text direction) or "center" (where the text is centered but lines are not justified) I want to know if there is a way to combine both (i.e. center the text and also have the lines start and end uniformly)?

Edit: Here is the code import React from "react"; import { StyleSheet, Text, View, ScrollView, StatusBar } from "react-native";

export default function App() {
 return (
  <View style={styles.background}>
  <View style={styles.pageContainer}>
    <ScrollView
      contentContainerStyle={{
        alignItems: "center",
        justifyContent: "center",
      }}
    >
      <Text style={styles.arabicText}>
        ??? ????? ?????? (1) ??? ????? ?????? (1) ??? ????? ?????? (1) ???
        ????? ?????? (1) ??? ????? ?????? (1) ??? ????? ?????? (1) ??? ?????
        ?????? (1) ??? ????? ?????? (1) ??? ????? ?????? (1) ??? ?????
        ?????? (1) ??? ????? ?????? (1) ??? ????? ?????? (1) ??? ?????
        ?????? (1) ??? ????? ?????? (1) ??? ????? ?????? (1) ??? ?????
        ?????? (1) ??? ????? ?????? (1) ??? ????? ?????? (1) ??? ?????
        ?????? (1) ??? ????? ?????? (1)
        </Text>
       </ScrollView>
     </View>
    </View>
  );
 }

  const styles = StyleSheet.create({
  background: {
  flex: 1,
  justifyContent: "space-evenly",
  alignItems: "center",
  backgroundColor: "white",
  },
  pageContainer: {
  alignItems: "center",
  width: "100%",
  flex: 1,
  backgroundColor: "#FFFAF1",
},
 arabicText: {
 direction: "rtl",
 marginRight: 8,
 marginLeft: 8,
 marginTop: 5,
 marginBottom: 5,
 flexDirection: "row",
 textAlign: "justify",
 fontSize: 26,
  padding: 2,
  },
});

question from:https://stackoverflow.com/questions/66047067/react-native-text-justify-and-center

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes you can put your Text tag inside View tag and give your View alignItems:'center' property

 <View style={{ alignItems: 'center' }}>
    <Text style={{ textAlign: 'justify' }}>
         Enter your text here
    </Text>
 </View>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...