Skip to content

Commit eda996e

Browse files
committed
fix anchor text can't show both underline and line through on iOS
1 parent d8361ee commit eda996e

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.tsx

+23-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ function AnchorRenderer({tnode, style, key}: AnchorRendererProps) {
5555
);
5656
}
5757

58+
const hasStrikethroughStyle = 'textDecorationLine' in parentStyle && parentStyle.textDecorationLine === 'line-through';
59+
const textDecorationLineStyle = hasStrikethroughStyle ? styles.underlineLineThrough : {};
60+
5861
return (
5962
<AnchorForCommentsOnly
6063
href={attrHref}
@@ -65,12 +68,30 @@ function AnchorRenderer({tnode, style, key}: AnchorRendererProps) {
6568
// eslint-disable-next-line react/jsx-props-no-multi-spaces
6669
target={htmlAttribs.target || '_blank'}
6770
rel={htmlAttribs.rel || 'noopener noreferrer'}
68-
style={[style, parentStyle, styles.textUnderlinePositionUnder, styles.textDecorationSkipInkNone]}
71+
style={[style, parentStyle, textDecorationLineStyle, styles.textUnderlinePositionUnder, styles.textDecorationSkipInkNone]}
6972
key={key}
7073
// Only pass the press handler for internal links. For public links or whitelisted internal links fallback to default link handling
7174
onPress={internalNewExpensifyPath || internalExpensifyPath ? () => Link.openLink(attrHref, environmentURL, isAttachment) : undefined}
7275
>
73-
<TNodeChildrenRenderer tnode={tnode} />
76+
<TNodeChildrenRenderer
77+
tnode={tnode}
78+
renderChild={(props) => {
79+
if (props.childTnode.tagName === 'br') {
80+
return <Text key={props.key}>{'\n'}</Text>;
81+
}
82+
if (props.childTnode.type === 'text') {
83+
return (
84+
<Text
85+
key={props.key}
86+
style={[props.childTnode.getNativeStyles(), parentStyle, textDecorationLineStyle, styles.textUnderlinePositionUnder, styles.textDecorationSkipInkNone]}
87+
>
88+
{props.childTnode.data}
89+
</Text>
90+
);
91+
}
92+
return props.childElement;
93+
}}
94+
/>
7495
</AnchorForCommentsOnly>
7596
);
7697
}

src/styles/utils/textDecorationLine.ts

+4
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ export default {
55
textDecorationLine: 'line-through',
66
textDecorationStyle: 'solid',
77
},
8+
underlineLineThrough: {
9+
textDecorationLine: 'underline line-through',
10+
textDecorationStyle: 'solid',
11+
},
812
} satisfies Record<string, TextStyle>;

0 commit comments

Comments
 (0)