Skip to content

Commit c15f0b0

Browse files
authored
refactor: Update react-native-render-html to fix warning and adapt HTML component usage for link styling. (#418)
1 parent 16bbf32 commit c15f0b0

6 files changed

Lines changed: 163 additions & 49 deletions

File tree

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { StyleSheet } from "react-native";
22

3-
import { Layout } from "style";
3+
import { Colors, Layout } from "style";
44

55
export default StyleSheet.create({
66
container: {
77
...Layout.containerWithPadding,
88
},
9+
linkStyle: {
10+
color: Colors.primary,
11+
textDecorationLine: "underline",
12+
},
913
});

app/screens/ActDetail/ActDetailScreen.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ const ActDetailScreen: NavStatelessComponent = () => {
3333
<HTML
3434
source={{ html: body }}
3535
contentWidth={contentWidth}
36-
onLinkPress={ui.onHTMLBodyLinkPress}
37-
baseFontStyle={baseFontStyle}
36+
baseStyle={baseFontStyle}
37+
tagsStyles={{ a: styles.linkStyle }}
38+
renderersProps={{
39+
a: {
40+
onPress: ui.onHTMLBodyLinkPress,
41+
},
42+
}}
3843
renderers={{
3944
img: (attribs) => {
4045
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

app/screens/InfoModal/InfoModalScreen.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
import React from "react";
2-
import { ScrollView } from "react-native";
2+
import { ScrollView, StyleSheet } from "react-native";
33
import { useRoute } from "@react-navigation/native";
44
import HTML from "react-native-render-html";
55

66
import { ui } from "utils";
77
import { NavStatelessComponent } from "interfaces";
8+
import { Layout } from "constant";
9+
import { Colors } from "style";
810

911
import styles from "./InfoModalScreen.styles";
1012
import navigationOptions from "./InfoModal.navigationOptions";
1113
import methodology from "../../../assets/methodology/methodology.json";
1214
import emissionInfo from "../../../assets/emission-info/emission-info.json";
1315

1416
const InfoModalScreen: NavStatelessComponent = () => {
17+
const linkStyle = StyleSheet.create({
18+
a: {
19+
color: Colors.primary,
20+
textDecorationLine: "underline",
21+
},
22+
});
1523
const route = useRoute();
1624

1725
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -32,7 +40,17 @@ const InfoModalScreen: NavStatelessComponent = () => {
3240
style={styles.container}
3341
contentInsetAdjustmentBehavior="automatic"
3442
>
35-
<HTML source={{ html }} onLinkPress={ui.onHTMLBodyLinkPress} baseFontStyle={styles.text} />
43+
<HTML
44+
source={{ html }}
45+
contentWidth={Layout.screen.width}
46+
baseStyle={styles.text}
47+
tagsStyles={linkStyle}
48+
renderersProps={{
49+
a: {
50+
onPress: ui.onHTMLBodyLinkPress,
51+
},
52+
}}
53+
/>
3654
</ScrollView>
3755
);
3856
};

app/screens/InfoModal/__test__/__snapshots__/InfoModalScreen.test.tsx.snap

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ exports[`InfoModalScreen renders correctly 1`] = `
1313
}
1414
>
1515
<HTML
16-
baseFontStyle={
16+
baseStyle={
1717
{
1818
"fontSize": 18,
1919
}
2020
}
21-
onLinkPress={[Function]}
21+
contentWidth={375}
22+
renderersProps={
23+
{
24+
"a": {
25+
"onPress": [Function],
26+
},
27+
}
28+
}
2229
source={
2330
{
2431
"html": "<h1>How is your carbon footprint calculated?</h1>
@@ -45,6 +52,14 @@ exports[`InfoModalScreen renders correctly 1`] = `
4552
",
4653
}
4754
}
55+
tagsStyles={
56+
{
57+
"a": {
58+
"color": "#0F853B",
59+
"textDecorationLine": "underline",
60+
},
61+
}
62+
}
4863
/>
4964
</ScrollView>
5065
`;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"react-native-pager-view": "6.9.1",
7373
"react-native-progress": "5.0.1",
7474
"react-native-reanimated": "~4.1.1",
75-
"react-native-render-html": "5.1.0",
75+
"react-native-render-html": "^6.3.4",
7676
"react-native-safe-area-context": "~5.6.0",
7777
"react-native-screens": "^4.19.0",
7878
"react-native-svg": "15.12.1",
@@ -126,4 +126,4 @@
126126
},
127127
"name": "nmf-app",
128128
"version": "1.0.0"
129-
}
129+
}

0 commit comments

Comments
 (0)