5

I am making an app to read Quran, using react native (expo). I am having some problems formatting the text.

Problems:

  • Random spacing
  • Text resize automatically
  • Text aligns on the left side at the end.

Here is my code:

function Read(){
    return (
    <SafeAreaView style={styles.container}>
      <HeaderSurahScreen navigation={navigation} route={route} />
      <Divider
        orientation="vertical"
        width={5}
        style={{ borderBottomColor: "#545353" }}
      />

      {/* create a logic here to display tranlition or arabic */}
      <ScrollView style={styles.scroll}>
        <Text style={styles.surahPage} adjustsFontSizeToFit>
          {surah &&
            surah.map((ayat, index) => (
              <Text key={index} allowFontScaling={false} selectable={true}>
                <Text selectable={true} style={styles.ayat}>
                  {ayat.text}
                </Text>
                <Text style={styles.number}>{toArabic(ayat.id)}&#1757;</Text>
              </Text>
            ))}
        </Text>
      </ScrollView>
      <StatusBar style="auto" />
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: DEFAULT_BACKGROUND_COLOR_THEME,
  },
  scroll: {
    flex: 1,
    padding: 7,
  },
  surahPage: {
    flex: 1,
    marginTop: 15,
    textAlign: "justify",
  },

  ayat: {
    flex: 1,
    fontFamily: ARABIC_FONT,
    color: DEFAULT_COLOR_THEME,
    fontSize: 30,
  },

  number: {
    fontSize: 18,
    color: DEFAULT_COLOR_THEME,
  },
});

Screenshots(3):

Random spacing Text resize randomly Text align on left side at the end

The result I am looking for:

styling I am looking for

TylerH
  • 20,799
  • 66
  • 75
  • 101
Anas Ikhlas
  • 75
  • 11

2 Answers2

0

To make the text align in your text, you need to use justify to make all the lines have the same length, but also you need to add one attribute direction to make the justification to the right side.

direction: "rtl";
textAlign: "justify"

You may want to have a look at this: http://jsfiddle.net/aew75/

Unfortunately, I fear I know no way of fixing the problem of the spaces between words coming from justify. There is no way to expand the letters size and width as in the mushaf. This can be a revolutionary idea of arabic fonts usage on the web and dispalys in general. Maybe give it a shot and have other muslim / arab developers contribute :)

Ikdemm
  • 1,804
  • 1
  • 11
  • 25
  • 1
    I have tried this textAlign: "justify" is working fine but the direction "rtl" is not working, textAlign: "justify" is resizing text. Thanks for the help brother. – Anas Ikhlas Oct 24 '21 at 08:03
  • is there any way to fix text resizing? – Anas Ikhlas Oct 24 '21 at 08:39
  • I think in React Native you should force it or pass it to the view as props. Take a look at this https://stackoverflow.com/questions/59319997/how-to-set-direction-property-of-a-view-to-rtl-in-react-native – Ikdemm Oct 24 '21 at 08:39
  • Quran in Mushaf is originally hand written. The writer would adapt the space and style of the letter depending on the space he has left in the page. This can not be achieved with code, as far as I know. Applications that you run on mobile and web to read quran use images or pdf versions of scanned mushafs, not text as an html element. – Ikdemm Oct 24 '21 at 08:43
0

justify will do the job (except the last line) ,i think this what you are asking for

To solve this you should import I18nManager library from react-native,then:

In useEffect write this line :

I18nManager.forceRTL(true);

considering big spaces between words , i used to manage it as possible in styling the text like this :

    letterSpacing: -3

change -3 to any other values below 0 ,this will narrow spaces between words as possible

that worked for me

  • Thanks for commenting, I found a workaround to this problem. but I will definitely try your solution in the next update. – Anas Ikhlas Apr 23 '22 at 13:39
  • @AnasIkhlas can you give as what is the workaround for this issue because I am facing the same issue. – Hamza Hmem Nov 26 '22 at 12:12
  • @HamzaHmem I start working on this project again and I am also looking for a solution. In the previous version of the app, I displayed each ayah on a separate line. For the newer version of the app, I am planning to use images since I can't find a working solution. – Anas Ikhlas Nov 27 '22 at 13:55
  • @AnasIkhlas May ALLAH help you brother, Thanks for your reply – Hamza Hmem Nov 27 '22 at 16:54