[Android]Text's lineHeight should be float instead of int
See original GitHub issueGot this error on android when set a float lineHeight property to Text component,
E/unknown:ViewManager: Error while updating prop lineHeight
com.facebook.react.bridge.UnexpectedNativeTypeException: TypeError: expected dynamic type `int64', but had type `double'
at com.facebook.react.bridge.ReadableNativeMap.getInt(Native Method)
at com.facebook.react.uimanager.ReactStylesDiffMap.getInt(ReactStylesDiffMap.java:67)
at com.facebook.react.uimanager.ViewManagersPropertyCache$IntPropSetter.extractProperty(ViewManagersPropertyCache.java:133)
at com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter.updateShadowNodeProp(ViewManagersPropertyCache.java:98)
at com.facebook.react.uimanager.ViewManagerPropertyUpdater$FallbackShadowNodeSetter.setProperty(ViewManagerPropertyUpdater.java:150)
at com.facebook.react.uimanager.ViewManagerPropertyUpdater.updateProps(ViewManagerPropertyUpdater.java:52)
at com.facebook.react.uimanager.ReactShadowNode.updateProperties(ReactShadowNode.java:231)
at com.facebook.react.uimanager.UIImplementation.createView(UIImplementation.java:167)
at com.facebook.react.uimanager.UIManagerModule.createView(UIManagerModule.java:206)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.BaseJavaModule$JavaMethod.invoke(BaseJavaModule.java:322)
at com.facebook.react.cxxbridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:743)
at android.os.Handler.dispatchMessage(Handler.java:95)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
at android.os.Looper.loop(Looper.java:150)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196)
at java.lang.Thread.run(Thread.java:833)
RCT_EXPORT_SHADOW_PROPERTY(lineHeight, CGFloat)
Android ReactTextShadowNode.java
@ReactProp(name = ViewProps.LINE_HEIGHT, defaultInt = UNSET)
public void setLineHeight(int lineHeight) {
mLineHeight = lineHeight == UNSET ? Float.NaN : PixelUtil.toPixelFromSP(lineHeight);
markUpdated();
}
Change to float solves my problem:
@ReactProp(name = ViewProps.LINE_HEIGHT, defaultFloat = UNSET)
public void setLineHeight(float lineHeight) {
mLineHeight = lineHeight == UNSET ? Float.NaN : PixelUtil.toPixelFromSP(lineHeight);
markUpdated();
}
Is this a bug?
Additional Information
- React Native version: 0.33
- Platform: [FILL THIS OUT: iOS, Android, or both?] android
- Operating System: [FILL THIS OUT: MacOS, Linux, or Windows?] windows
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
How to properly set line height for Android? - Stack Overflow
I'll explain this from Android Developer perspective. Line height usually means text size + "padding" top/bottom.
Read more >TextView - Android Developers
android:lineHeight, Explicit height between lines of text. ... For floating windows, use LayoutParams#setFitInsetsTypes(int) with Type#statusBars() ()}.
Read more >float - CSS: Cascading Style Sheets - MDN Web Docs - Mozilla
The float CSS property places an element on the left or right side of its container, allowing text and inline elements to wrap...
Read more >Text - Litho
Text letter-spacing. Typical values for slight expansion will be around 0.05 ems. Negative values tighten text. Type: float. lineHeight. Controls ...
Read more >core/java/android/text/Layout.java - platform/frameworks/base
@param spacingAdd amount to add to the default line spacing. */. protected Layout(CharSequence text, TextPaint paint,. int width, Alignment align,. float ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We should just accept a line height of e.g. 3.5 sp (Scale-independent Pixels) rather than crashing. On iOS it won’t crash if you pass a float - platform parity is important.
Can you send a pull request with your change please? Good that
PixelUtil.toPixelFromSP
accepts floats already so doing this is easy.Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we’re automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.