Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Mobile
react-native-autolink
Commits
223b7a33
Commit
223b7a33
authored
6 years ago
by
Mike ไมค์ Thuchchai.J
Browse files
Options
Download
Patches
Plain Diff
fixed nested text
parent
7c2c1e06
feature/fixed_nested_text_props
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/index.js
+25
-20
src/index.js
with
25 additions
and
20 deletions
+25
-20
src/index.js
+
25
−
20
View file @
223b7a33
...
...
@@ -6,7 +6,7 @@
* https://github.com/joshswan/react-native-autolink/blob/master/LICENSE
*/
import
React
,
{
Component
,
createElement
}
from
'
react
'
;
import
React
,
{
Component
,
createElement
,
Fragment
}
from
'
react
'
;
import
PropTypes
from
'
prop-types
'
import
Autolinker
from
'
autolinker
'
;
import
{
Alert
,
Linking
,
Platform
,
StyleSheet
,
Text
}
from
'
react-native
'
;
...
...
@@ -18,14 +18,6 @@ const styles = StyleSheet.create({
});
export
default
class
Autolink
extends
Component
{
constructor
(
props
)
{
super
(
props
)
if
(
Text
.
defaultProps
==
null
)
{
Text
.
defaultProps
=
{};
}
Text
.
defaultProps
.
allowFontScaling
=
false
;
}
onPress
(
match
,
alertShown
)
{
// Check if alert needs to be shown
if
(
this
.
props
.
showAlert
&&
!
alertShown
)
{
...
...
@@ -110,15 +102,16 @@ export default class Autolink extends Component {
}
}
renderLink
(
text
,
match
,
index
)
{
renderLink
(
text
,
match
,
index
,
textProps
)
{
const
truncated
=
(
this
.
props
.
truncate
>
0
)
?
Autolinker
.
truncate
.
TruncateSmart
(
text
,
this
.
props
.
truncate
,
this
.
props
.
truncateChars
)
:
text
;
return
(
<
Text
{...
textProps
}
key
=
{
index
}
style
=
{
[
styles
.
link
,
this
.
props
.
linkStyle
]
}
style
=
{
this
.
props
.
linkStyle
||
styles
.
link
}
onPress
=
{()
=>
this
.
onPress
(
match
)}
>
{
truncated
}
...
...
@@ -126,6 +119,17 @@ export default class Autolink extends Component {
);
}
renderNormalText
(
text
,
index
,
textProps
)
{
return
(
<
Text
{...
textProps
}
key
=
{
index
}
>
{
text
}
<
/Text
>
);
}
render
()
{
// Destructure props
/* eslint-disable no-unused-vars */
...
...
@@ -146,7 +150,7 @@ export default class Autolink extends Component {
twitter
,
url
,
webFallback
,
...
other
...
other
Props
}
=
this
.
props
;
// Backwards compatibility for Twitter prop
...
...
@@ -194,7 +198,7 @@ export default class Autolink extends Component {
.
map
((
part
,
index
)
=>
{
const
match
=
matches
[
part
];
if
(
!
match
)
return
part
;
if
(
!
match
)
return
this
.
renderNormalText
(
part
,
index
,
otherProps
)
;
switch
(
match
.
getType
())
{
case
'
email
'
:
...
...
@@ -203,17 +207,18 @@ export default class Autolink extends Component {
case
'
phone
'
:
case
'
url
'
:
return
(
renderLink
)
?
renderLink
(
match
.
getAnchorText
(),
match
,
index
)
:
this
.
renderLink
(
match
.
getAnchorText
(),
match
,
index
);
renderLink
(
match
.
getAnchorText
(),
match
,
index
,
otherProps
)
:
this
.
renderLink
(
match
.
getAnchorText
(),
match
,
index
,
otherProps
);
default
:
return
part
;
return
this
.
renderNormalText
(
part
,
index
,
otherProps
)
;
}
});
return
createElement
(
Text
,
{
ref
:
(
component
)
=>
{
this
.
_root
=
component
;
},
// eslint-disable-line no-underscore-dangle
...
other
,
},
...
nodes
);
return
(
<
Fragment
>
{
nodes
}
<
/Fragment
>
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets