question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android]Text's lineHeight should be float instead of int

See original GitHub issue

Got 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)

iOS RCTTextManager.m

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:closed
  • Created 7 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mkonicekcommented, Nov 2, 2016

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.

0reactions
hramoscommented, Jul 21, 2017

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:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found