Skip to content

Commit 467dac2

Browse files
author
Adrien Thiery
committed
Added ability to pass props to Text Children components (+ bump to v0.0.17)
1 parent d7dc4d6 commit 467dac2

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ All the props are passed down to a new `Text` Component if there is a matching t
1515

1616
`renderText`: Function called to change the displayed children.
1717

18+
`childrenProps` : Properties to pass to the children elements generated by react-native-parsed-text.
19+
1820
eg:
1921
Your str is ```'Mention [@michel:5455345]'``` where 5455345 is ID of this user and @michel the value to display on interface.
2022
Your pattern for ID & username extraction : ```/\[(@[^:]+):([^\]]+)\]/i```
@@ -76,6 +78,7 @@ class Example extends React.Component {
7678
{pattern: /#(\w+)/, style: styles.hashTag},
7779
]
7880
}
81+
childrenProps={{allowFontScaling: false}}
7982
>
8083
Hello this is an example of the ParsedText, links like http://www.google.com or http://www.facebook.com are clickable and phone number 444-555-6666 can call too.
8184
But you can also do more with this package, for example Bob will change style and David too. foo@gmail.com

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-parsed-text",
3-
"version": "0.0.16",
3+
"version": "0.0.17",
44
"description": "Parse text and make them into multiple React Native Text elements",
55
"main": "src/ParsedText.js",
66
"scripts": {

src/ParsedText.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ class ParsedText extends React.Component {
2828
parse: React.PropTypes.arrayOf(
2929
React.PropTypes.oneOfType([defaultParseShape, customParseShape]),
3030
),
31+
childrenProps: React.PropTypes.shape(ReactNative.Text.propTypes),
3132
};
3233

3334
static defaultProps = {
3435
parse: null,
36+
childrenProps: {},
3537
};
3638

3739
setNativeProps(nativeProps) {
@@ -62,6 +64,7 @@ class ParsedText extends React.Component {
6264
return (
6365
<ReactNative.Text
6466
key={`parsedText-${index}`}
67+
{...this.props.childrenProps}
6568
{...props}
6669
/>
6770
);
@@ -72,7 +75,8 @@ class ParsedText extends React.Component {
7275
return (
7376
<ReactNative.Text
7477
ref={ref => this._root = ref}
75-
{...this.props}>
78+
{...this.props}
79+
>
7680
{this.getParsedText()}
7781
</ReactNative.Text>
7882
);

0 commit comments

Comments
 (0)