Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text is getting cut off in android for react native

I am working on React native and I am new to this. I am trying to display text, But, It's showing in an android end of the text ... and not showing complete text. It's only happening in android, working fine in iOS.

I have written following code

<Text
  numberOfLines={1}
  adjustsFontSizeToFit
  minimumFontScale={0.1}
  style={labelStyle} //labelStyle nothing I have written
></Text>

Can anyone suggest me, where I am doing wrong in the code?

enter image description here

like image 803
Anilkumar iOS - ReactNative Avatar asked Feb 18 '19 15:02

Anilkumar iOS - ReactNative


People also ask

How do I fix text size in React Native?

You need to use fontSize attribute/property of stylesheet design, in order to set text font size in your Text component. Set Fontsize in react native application : Using below CSS properties you can set font size in your react native application.

Is Android Studio good for React Native?

You will need Node, Watchman, the React Native command line interface, a JDK, and Android Studio. While you can use any editor of your choice to develop your app, you will need to install Android Studio in order to set up the necessary tooling to build your React Native app for Android.

Is React Native slow on Android?

React Native application are really slow most of the times. Large sets of the list, images, assets, API responses and multiple rendering, profiling, memorization, lazy-loading, I was thrown this many terms during the process of improving our application performance.

How do you know if text is overflowing React Native?

The width of a text container can be obtained similarly via onLayout or computed based on flex. Then we only need to compare the text width with the container width to determine whether there is overflow.


4 Answers

I'd had problem of text cut horizontally. by using lineHeight to text components, and boom, my problem solved

like image 113
Mourad Karoudi Avatar answered Sep 17 '22 11:09

Mourad Karoudi


This usually happens when you have this: fontWeight:bold and your android device is for example a Oneplus or Oppo (there are some other brands tho), it's a conflict with your system font.
To fix, you can add some other fontFamily or put 2 blank spaces in front of the word seems to work too.
See: https://github.com/facebook/react-native/issues/15114

Edit

Setting textBreakStrategy to simple on the Text element also seems to work for some devices like Samsung galaxy s10, Google Pixel

like image 38
MPN7 Avatar answered Oct 12 '22 10:10

MPN7


For anyone who found provided solutions not working like in my case here's my solution to text being cut on OnePlus phones:

just set component style with these properties

alignSelf: 'stretch',
textAlign: 'center',

this is probably an equivalent to android match_parent setting. Did not test how it will affect iOS though as I don't have that possibility right now.

like image 5
laszlo Avatar answered Oct 12 '22 10:10

laszlo


After struggling with it for a long time, I finally figured it out.

Seems like for default, the Text sets the property textBreakStrategy to * highQuality*.

Changing it to * simple* solved my problem.

Link here: https://reactnative.dev/docs/0.56/text#textbreakstrategy

like image 4
Jordan Avatar answered Oct 12 '22 10:10

Jordan