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?
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.
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.
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.
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.
I'd had problem of text cut horizontally.
by using lineHeight
to text components, and boom, my problem solved
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
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With