How to implement soft hyphen in Android w/ React Native Text
Asked Answered
S

2

10
<Text>
Aufmerksamkeits{'\u00AD'}defizit
</Text>

This leads iOS to

Aufmerksamkeits-
defizit

But on Android to

Aufmerksamkeitsd
efizit

So it seems that Android ignores the given soft hyphen. How can I make this work on Android as well?

Scend answered 14/10, 2019 at 11:46 Comment(0)
B
4

If you want to use soft hyphen use \u00AD in strings, e.g.:

<string name="einzelfahrt_name">Einzelfahrrad\u00ADkarte</string>

In order to make this working though, in your TextView, you have to add:

android:hyphenationFrequency="full"
Blackheart answered 9/2, 2021 at 9:48 Comment(2)
where one need to add "android:hyphenationFrequency"? please provide exampleRosel
In React Native this option should be set as a property: <Text android_hyphenationFrequency="full">Einzelfahrrad\u00ADkarte</Text> This worked for me! But make sure you have React Native version above the 0.65.Blacksmith
S
1

I have the same problem and it seems that Android ignores soft hyphens.

The only workaround I could think of is, only on Android, to replace the \u00AD with \u200B. It's known as zero-width-space, and it would properly break the words where expected, although it would not show any hyphenation character. You would end up with:

Aufmerksamkeits
defizit

Not the perfect solution, but at least it will not break words at random positions.

Servo answered 15/1, 2020 at 10:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.