fix: web paragraph styles not working #2716
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've tried to use the paragraph api on the web, however the paragraph didn't render and show up on the canvas.
After debugging I found out that
paragraph.getHeight()
returned0
and thestyle.textStyle.fontSize
was-1
andstyle.textStyle.fontFamilies
was undefined.I've tried to directly create the style using
new CanvasKit.ParagraphStyle(...)
and that returned a style object with correct fontSize/fontFamily and when used also returned the correct paragraph height.That means the issue lies in the
JsiSkParagraphStyle.toParagraphStyle()
function:react-native-skia/packages/skia/src/skia/web/JsiSkParagraphStyle.ts
Lines 7 to 65 in 4a2d7af
Inside of the
toParagraphStyle()
function I've changed the assignments from strutStyle to textStyle (except forleading
,forceStrutHeight
andstrutEnabled
) and also added some properties liketextDecoration
,backgroundColor
andshadows
.This fixed the issue and now the paragraph correctly renders: