Expensify / react-native-live-markdown

Drop-in replacement for React Native's TextInput component with Markdown formatting.
https://www.npmjs.com/package/@expensify/react-native-live-markdown
MIT License
670 stars 45 forks source link

Fix TextInput vertical alignment issue when using lineHeight prop on iOS without changing Text baseline (Fabric - new arch) #350

Closed fabOnReact closed 1 month ago

fabOnReact commented 1 month ago

Details

Sets the NSBaselineOffsetAttributeName of the attributedText based on the following formula:

CGFloat baseLineOffset = (maximumLineHeight - maximumFontLineHeight) / 2.0;

The text is vertically centered in the lineHeight of the TextInput (which corresponds to the height of the cursor). The solution was already added in facebook/react-native:

Related Issues

fixes https://github.com/Expensify/App/issues/17767 fixes https://github.com/Expensify/App/issues/14445 fixes https://github.com/Expensify/App/issues/15640 Related https://github.com/facebook/react-native/issues/35741 https://github.com/facebook/react-native/issues/31112 https://github.com/facebook/react-native/issues/28012 https://github.com/facebook/react-native/issues/33986

Manual Tests

Linked PRs

github-actions[bot] commented 1 month ago

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

fabOnReact commented 1 month ago

I have read the CLA Document and I hereby sign the CLA

fabOnReact commented 1 month ago

Expensify Composer (When moving to another line, the word and emoji are close to each other):

The difference of baseline is 1.15 (barely noticeable), maximumLineHeight 20, maximumFontLineHeight 17.69

Before After
Before After
fabOnReact commented 1 month ago

Expensify Composer (increasing lineHeight to display more clearly differences in the screenshots):

The result is achieved after setting textInputCompose.lineHeight: 40.

Before After
Before After
Before After
fabOnReact commented 1 month ago

iOS - Chat - Cursor in the second and following lines touches the symbols of the previous line #15640

Fixes issue https://github.com/Expensify/App/issues/15640

Before After
tomekzaw commented 1 month ago

Thanks @fabOnReact for this amazing PR!

tomekzaw commented 1 month ago

@fabOnReact We've reviewed the changes and we'd like to merge this PR but it's still marked as draft

fabOnReact commented 1 month ago

@tomekzaw Thanks a lot. I moved the PR to ready for review.

hungvu193 commented 1 month ago

@fabOnReact I think this PR introduced this regression. Do we have any plan to fix it or should we create an issue for that?

fabOnReact commented 1 month ago

@hungvu193 did you test it?

hungvu193 commented 1 month ago

@hungvu193 did you test it?

  • Remove that line of code from Expensify
  • You need to build Expensify and run it on Android
  • Does the bug disappear?

Because the bug is Android only, while this PR introduces changes only to iOS. Thanks a lot!

My apologize for this confusion. I think I mentioned wrong PR here :(

fabOnReact commented 1 month ago

@hungvu193 Thanks for the clarification. No problem about that. 🙏