Skip to content

feat: lineHeight support for EnrichedText - #724

Open
kacperzolkiewski wants to merge 2 commits into
mainfrom
@kacperzolkiewski/feat-line-height
Open

feat: lineHeight support for EnrichedText#724
kacperzolkiewski wants to merge 2 commits into
mainfrom
@kacperzolkiewski/feat-line-height

Conversation

@kacperzolkiewski

@kacperzolkiewski kacperzolkiewski commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes: #608
Add support for lineHeight on mobile.
On web It is already supported.

Test Plan

  1. Display some content inside EnrichedText
  2. Change lineHeight in style prop for EnrichedText
  3. lineHeight should be applied properly

Screenshots / Videos

Compatibility

OS Implemented
iOS
Android
Web

Checklist

  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds lineHeight support to the native EnrichedText component so that style={{ lineHeight: ... }} influences both rendering and measurement on iOS/Android (web already has support via CSS conversion).

Changes:

  • Extend the EnrichedTextView native prop surface to include lineHeight (codegen spec + platform bindings).
  • Apply lineHeight in iOS config updates and Android rendering (EnrichedTextView) + measurement (MeasurementStore).
  • Include lineHeight in Android new-architecture prop serialization for measurement.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/spec/EnrichedTextNativeComponent.ts Adds lineHeight to the native prop spec for EnrichedText.
ios/EnrichedTextView.mm Applies lineHeight via EnrichedConfig during prop updates.
android/src/main/new_arch/react/renderer/components/ReactNativeEnrichedSpec/conversions.h Serializes lineHeight for Fabric measurement.
android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedLineHeightSpan.kt Changes how the line-height span behaves (notably for headings).
android/src/main/java/com/swmansion/enriched/text/MeasurementStore.kt Incorporates lineHeight into Android text measurement by applying the span.
android/src/main/java/com/swmansion/enriched/text/EnrichedTextViewManager.kt Exposes setLineHeight to the native view manager.
android/src/main/java/com/swmansion/enriched/text/EnrichedTextView.kt Applies/removes the line-height span when props/state change.
Comments suppressed due to low confidence (1)

android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedLineHeightSpan.kt:36

  • This change removes the previous guard that prevented EnrichedLineHeightSpan from affecting heading paragraphs (EnrichedHeadingSpan). Since this span is also used by EnrichedTextInput, this is a behavior change that will start applying lineHeight to headings in the input as well. If headings are still intended to keep their own metrics, reintroduce the heading check before applying the extra line height.
    val lineHeightPx = pixelFromSpOrDp(lineHeight, allowFontScaling)
    val currentHeight = (fm.descent - fm.ascent).toFloat()
    if (lineHeightPx <= currentHeight) return

    val extra = (lineHeightPx - currentHeight).toInt()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/spec/EnrichedTextNativeComponent.ts

@hejsztynx hejsztynx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well! 🚀

}

fun setLineHeight(height: Float) {
lineHeight = if (height == 0f) null else height

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lineHeight = if (height == 0f) null else height
lineHeight = if (height <= 0f) null else height

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I've noticed the same change would be applicable in EnrichedTextInputView.kt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature request] Support lineHeight in EnrichedText

3 participants