Skip to content

Commit 971b866

Browse files
author
Pawan
committed
implements #18
1 parent e9d4154 commit 971b866

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ export const defaultLink = () =>
3434
</Hyperlink>
3535

3636
export const regularText = () =>
37-
<Hyperlink onPress={ url => alert(url) }>
37+
<Hyperlink onPress={ (url, text) => alert(url + ", " + text) }>
3838
<Text style={ { fontSize: 15 } }>
3939
This text will be parsed to check for clickable strings like https://github.com/obipawan/hyperlink and made clickable.
4040
</Text>
4141
</Hyperlink>
4242

4343
export const regularTextLongPress = () =>
44-
<Hyperlink onLongPress={ url => alert(url) }>
44+
<Hyperlink onLongPress={ (url, text) => alert(url + ", " + text) }>
4545
<Text style={ { fontSize: 15 } }>
4646
This text will be parsed to check for clickable strings like https://github.com/obipawan/hyperlink and made clickable for long click.
4747
</Text>
4848
</Hyperlink>
4949

5050
export const nestedText = () =>
51-
<Hyperlink onPress={ url => alert(url) }>
51+
<Hyperlink onPress={ (url, text) => alert(url + ", " + text) }>
5252
<View>
5353
<Text style={ { fontSize: 15 } }>
5454
A nested Text component https://facebook.github.io/react-native/docs/text.html works equally well <Text>with https://github.com/obipawan/hyperlink</Text>
@@ -82,4 +82,4 @@ PRs highly appreciated
8282

8383
License
8484
----
85-
MIT License
85+
MIT License

dist/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ var Hyperlink = function (_Component) {
112112

113113
if (OS !== 'web') {
114114
componentProps.onLongPress = function () {
115-
return _this2.props.onLongPress && _this2.props.onLongPress(url);
115+
return _this2.props.onLongPress && _this2.props.onLongPress(url, text);
116116
};
117117
}
118118

@@ -122,7 +122,7 @@ var Hyperlink = function (_Component) {
122122
key: url + index,
123123
style: [component.props.style, _this2.props.linkStyle],
124124
onPress: function onPress() {
125-
return _this2.props.onPress && _this2.props.onPress(url);
125+
return _this2.props.onPress && _this2.props.onPress(url, text);
126126
}
127127
}),
128128
text

src/Hyperlink.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,31 @@ class Hyperlink extends Component {
3030
const { ...viewProps } = this.props
3131
delete viewProps.onPress
3232
delete viewProps.linkDefault
33-
delete viewProps.onLongPress
34-
delete viewProps.linkStyle
33+
delete viewProps.onLongPress
34+
delete viewProps.linkStyle
3535

3636
return (
37-
<View {...viewProps} style={this.props.style}>
38-
{!this.props.onPress && !this.props.onLongPress && !this.props.linkStyle
37+
<View { ...viewProps } style={ this.props.style }>
38+
{ !this.props.onPress && !this.props.onLongPress && !this.props.linkStyle
3939
? this.props.children
40-
: this.parse(this).props.children}
40+
: this.parse(this).props.children }
4141
</View>
4242
)
4343
}
4444

4545
isTextNested(component) {
46-
if (!React.isValidElement(component))
47-
throw new Error('Invalid component')
46+
if (!React.isValidElement(component))
47+
throw new Error('Invalid component')
4848
let { type: { displayName } = {} } = component
49-
if (displayName !== 'Text')
50-
throw new Error('Not a Text component')
49+
if (displayName !== 'Text')
50+
throw new Error('Not a Text component')
5151
return typeof component.props.children !== 'string'
5252
}
5353

5454
linkify(component){
5555
if (
56-
!this.linkifyIt.pretest(component.props.children)
57-
|| !this.linkifyIt.test(component.props.children)
56+
!this.linkifyIt.pretest(component.props.children)
57+
|| !this.linkifyIt.test(component.props.children)
5858
)
5959
return component
6060

@@ -78,15 +78,15 @@ class Hyperlink extends Component {
7878
: this.props.linkText
7979

8080
if (OS !== 'web') {
81-
componentProps.onLongPress = () => this.props.onLongPress && this.props.onLongPress(url)
81+
componentProps.onLongPress = () => this.props.onLongPress && this.props.onLongPress(url, text)
8282
}
8383

8484
elements.push(
8585
<Text
8686
{ ...componentProps }
8787
key={ url + index }
8888
style={ [ component.props.style, this.props.linkStyle ] }
89-
onPress={ () => this.props.onPress && this.props.onPress(url) }
89+
onPress={ () => this.props.onPress && this.props.onPress(url, text) }
9090
>
9191
{ text }
9292
</Text>
@@ -101,8 +101,8 @@ class Hyperlink extends Component {
101101

102102
parse (component) {
103103
let { props: { children} = {}, type: { displayName } = {} } = component
104-
if (!children)
105-
return component
104+
if (!children)
105+
return component
106106

107107
const componentProps = {
108108
...component.props,
@@ -111,13 +111,13 @@ class Hyperlink extends Component {
111111
}
112112

113113
return React.cloneElement(component, componentProps, React.Children.map(children, child => {
114-
let { type : { displayName } = {} } = child
115-
if (typeof child === 'string' && this.linkifyIt.pretest(child))
116-
return this.linkify(<Text { ...componentProps } style={ component.props.style }>{ child }</Text>)
117-
if (displayName === 'Text' && !this.isTextNested(child))
118-
return this.linkify(child)
119-
return this.parse(child)
120-
}))
114+
let { type : { displayName } = {} } = child
115+
if (typeof child === 'string' && this.linkifyIt.pretest(child))
116+
return this.linkify(<Text { ...componentProps } style={ component.props.style }>{ child }</Text>)
117+
if (displayName === 'Text' && !this.isTextNested(child))
118+
return this.linkify(child)
119+
return this.parse(child)
120+
}))
121121
}
122122
}
123123

@@ -126,8 +126,8 @@ Hyperlink.propTypes = {
126126
linkify: PropTypes.object,
127127
linkStyle: textPropTypes.style,
128128
linkText: PropTypes.oneOfType([
129-
PropTypes.string,
130-
PropTypes.func,
129+
PropTypes.string,
130+
PropTypes.func,
131131
]),
132132
onPress: PropTypes.func,
133133
onLongPress: PropTypes.func,

0 commit comments

Comments
 (0)