Skip to content

Commit 8cf14cc

Browse files
authored
Merge branch 'master' into add-defaultTextStyle-to-support-global-textalign
2 parents 5b3a44f + 0ccd09c commit 8cf14cc

File tree

6 files changed

+452
-303
lines changed

6 files changed

+452
-303
lines changed

HTMLView.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class HtmlView extends PureComponent {
6565
const {
6666
addLineBreaks,
6767
onLinkPress,
68+
onLinkLongPress,
6869
stylesheet,
6970
renderNode,
7071
onError,
@@ -77,6 +78,7 @@ class HtmlView extends PureComponent {
7778
const opts = {
7879
addLineBreaks,
7980
linkHandler: onLinkPress,
81+
linkLongPressHandler: onLinkLongPress,
8082
styles: {...baseStyles, ...stylesheet},
8183
customRenderer: renderNode,
8284
};
@@ -128,6 +130,7 @@ HtmlView.propTypes = {
128130
nodeComponentProps: PropTypes.object,
129131
onError: PropTypes.func,
130132
onLinkPress: PropTypes.func,
133+
onLinkLongPress: PropTypes.func,
131134
paragraphBreak: PropTypes.string,
132135
renderNode: PropTypes.func,
133136
RootComponent: PropTypes.func,
@@ -142,6 +145,7 @@ HtmlView.propTypes = {
142145
HtmlView.defaultProps = {
143146
addLineBreaks: true,
144147
onLinkPress: url => Linking.openURL(url),
148+
onLinkLongPress: null,
145149
onError: console.error.bind(console),
146150
RootComponent: View,
147151
};

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ props:
2424
- `value`: a string of HTML content to render
2525
- `onLinkPress`: a function which will be called with a url when a link is pressed.
2626
Passing this prop will override how links are handled (defaults to calling `Linking.openURL(url)`)
27+
- `onLinkLongPress`: a function which will be called with a url when a link is long pressed.
28+
The default is `null`.
2729
- `stylesheet`: a stylesheet object keyed by tag name, which will override the
2830
styles applied to those respective tags.
2931
- `renderNode`: a custom function to render HTML nodes however you see fit. If

__tests__/HTMLView-test.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22

33
import renderer from 'react-test-renderer';
44

5-
import {Text} from 'react-native';
5+
import {StyleSheet, Text} from 'react-native';
66

77
import HTMLView from '../HTMLView';
88

@@ -39,6 +39,17 @@ describe('<HTMLView/>', () => {
3939
).toMatchSnapshot();
4040
});
4141

42+
it('should handle additional text nodes between list items', () => {
43+
const htmlContent = `<ol>
44+
<li> a </li>
45+
<li> b </li>
46+
</ol>`;
47+
48+
expect(
49+
renderer.create(<HTMLView value={htmlContent} />).toJSON()
50+
).toMatchSnapshot();
51+
});
52+
4253
it('should render an <Image />, with default width/height of 1', () => {
4354
const imgSrc =
4455
'https://facebook.github.io/react-native/img/header_logo.png';
@@ -59,6 +70,21 @@ describe('<HTMLView/>', () => {
5970
).toMatchSnapshot();
6071
});
6172

73+
it('should render inherited styles correctly', () => {
74+
const htmlContent = '<b>RED<u>BLUE<i>GREEN</i></u></b>';
75+
const stylesheet = StyleSheet.create({
76+
b: {color: 'red'},
77+
u: {color: 'blue'},
78+
i: {color: 'green'},
79+
});
80+
81+
expect(
82+
renderer
83+
.create(<HTMLView value={htmlContent} stylesheet={stylesheet} />)
84+
.toJSON()
85+
).toMatchSnapshot();
86+
});
87+
6288
it('should render shoddy html including headings, links, bold, italic', () => {
6389
const htmlContent = `
6490
<div class="comment">

0 commit comments

Comments
 (0)