Repository navigation
Open
Labels
enhancementNew feature or requestNew feature or request
Description
The current implementation of MarkdownLineHeightSpan is a bit tricky:
Lines 6 to 18 in b753c7a
| public class MarkdownLineHeightSpan implements MarkdownSpan, LineHeightSpan { | |
| private final float mLineHeight; | |
| public MarkdownLineHeightSpan(float lineHeight) { | |
| mLineHeight = lineHeight; | |
| } | |
| @Override | |
| public void chooseHeight(CharSequence text, int start, int end, int spanstartv, int lineHeight, Paint.FontMetricsInt fm) { | |
| fm.top -= mLineHeight / 4; | |
| fm.ascent -= mLineHeight / 4; | |
| } | |
| } |
Also, we need to obtain information about existing spans before applying MarkdownLineHeightSpan:
react-native-live-markdown/android/src/main/java/com/expensify/livemarkdown/MarkdownUtils.java
Lines 149 to 157 in b753c7a
| case "h1": | |
| setSpan(ssb, new MarkdownBoldSpan(), start, end); | |
| CustomLineHeightSpan[] spans = ssb.getSpans(0, ssb.length(), CustomLineHeightSpan.class); | |
| if (spans.length >= 1) { | |
| int lineHeight = spans[0].getLineHeight(); | |
| setSpan(ssb, new MarkdownLineHeightSpan(lineHeight * 1.5f), start, end); | |
| } | |
| // NOTE: size span must be set after line height span to avoid height jumps | |
| setSpan(ssb, new MarkdownFontSizeSpan(mMarkdownStyle.getH1FontSize()), start, end); |
The objective of this task is to eliminate division by 4 as well as calling .getSpans() method if needed.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Activity
[-]Eliminate weird logic related to `MarkdownLineHeightSpan`[/-][+]Simplfy `MarkdownLineHeightSpan` logic[/+][-]Simplfy `MarkdownLineHeightSpan` logic[/-][+]Simplify `MarkdownLineHeightSpan` logic[/+]tomekzaw commentedon Nov 4, 2024
Proposal: Add
h1.lineHeighttomarkdownStyle.If
style.lineHeightis undefined andmarkdownStyle.h1.lineHeightis undefined, we don't setCustomLineHeightSpanfor headings (the line height is calculated automatically by Android).If
style.lineHeightis defined andmarkdownStyle.h1.lineHeightis undefined, we don't setCustomLineHeightSpanfor headings (React Native appliesCustomLineHeightSpanfor whole text).If
markdownStyle.h1.lineHeightis defined, we setCustomLineHeightSpanfor headings.