-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[web] Added support for Expo web #58
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,7 @@ | |
'use strict'; | ||
|
||
import React from 'react'; | ||
import ReactNative from 'react-native'; | ||
const { | ||
AppRegistry, | ||
StyleSheet, | ||
View, | ||
} = ReactNative; | ||
import { AppRegistry, StyleSheet, View } from 'react-native'; | ||
|
||
import ParsedText from 'react-native-parsed-text'; | ||
|
||
|
@@ -45,22 +40,39 @@ class Example extends React.Component { | |
<View style={styles.container}> | ||
<ParsedText | ||
style={styles.text} | ||
parse={ | ||
[ | ||
{type: 'url', style: styles.url, onPress: this.handleUrlPress}, | ||
{type: 'phone', style: styles.phone, onPress: this.handlePhonePress}, | ||
{type: 'email', style: styles.email, onPress: this.handleEmailPress}, | ||
{pattern: /Bob|David/, style: styles.name, onPress: this.handleNamePress}, | ||
{pattern: /\[(@[^:]+):([^\]]+)\]/i, style: styles.username, onPress: this.handleNamePress, renderText: this.renderText}, | ||
{pattern: /42/, style: styles.magicNumber}, | ||
{pattern: /#(\w+)/, style: styles.hashTag}, | ||
] | ||
} | ||
parse={[ | ||
{ type: 'url', style: styles.url, onPress: this.handleUrlPress }, | ||
{ | ||
type: 'phone', | ||
style: styles.phone, | ||
onPress: this.handlePhonePress, | ||
}, | ||
{ | ||
type: 'email', | ||
style: styles.email, | ||
onPress: this.handleEmailPress, | ||
}, | ||
{ | ||
pattern: /Bob|David/, | ||
style: styles.name, | ||
onPress: this.handleNamePress, | ||
}, | ||
{ | ||
pattern: /\[(@[^:]+):([^\]]+)\]/i, | ||
style: styles.username, | ||
onPress: this.handleNamePress, | ||
renderText: this.renderText, | ||
}, | ||
{ pattern: /42/, style: styles.magicNumber }, | ||
{ pattern: /#(\w+)/, style: styles.hashTag }, | ||
]} | ||
> | ||
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. | ||
But you can also do more with this package, for example Bob will change style and David too. You should mention [@michel:5455345] about that. [email protected] | ||
And the magic number is 42! | ||
#react #react-native | ||
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. But you can also do more with | ||
this package, for example Bob will change style and David too. You | ||
should mention [@michel:5455345] about that. [email protected] And the | ||
magic number is 42! #react #react-native | ||
</ParsedText> | ||
</View> | ||
); | ||
|
@@ -111,7 +123,6 @@ const styles = StyleSheet.create({ | |
hashTag: { | ||
fontStyle: 'italic', | ||
}, | ||
|
||
}); | ||
|
||
AppRegistry.registerComponent('Example', () => Example); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,13 @@ | |
'use strict'; | ||
|
||
import React from 'react'; | ||
import ReactNative from 'react-native'; | ||
EvanBacon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { | ||
import { | ||
AppRegistry, | ||
StyleSheet, | ||
View, | ||
LinkingIOS, | ||
AlertIOS, | ||
} = ReactNative; | ||
} from 'react-native'; | ||
|
||
import ParsedText from 'react-native-parsed-text'; | ||
|
||
|
@@ -47,22 +46,39 @@ class Example extends React.Component { | |
<View style={styles.container}> | ||
<ParsedText | ||
style={styles.text} | ||
parse={ | ||
[ | ||
{type: 'url', style: styles.url, onPress: this.handleUrlPress}, | ||
{type: 'phone', style: styles.phone, onPress: this.handlePhonePress}, | ||
{type: 'email', style: styles.email, onPress: this.handleEmailPress}, | ||
{pattern: /Bob|David/, style: styles.name, onPress: this.handleNamePress}, | ||
{pattern: /\[(@[^:]+):([^\]]+)\]/i, style: styles.username, onPress: this.handleNamePress, renderText: this.renderText}, | ||
{pattern: /42/, style: styles.magicNumber}, | ||
{pattern: /#(\w+)/, style: styles.hashTag}, | ||
] | ||
} | ||
parse={[ | ||
{ type: 'url', style: styles.url, onPress: this.handleUrlPress }, | ||
{ | ||
type: 'phone', | ||
style: styles.phone, | ||
onPress: this.handlePhonePress, | ||
}, | ||
{ | ||
type: 'email', | ||
style: styles.email, | ||
onPress: this.handleEmailPress, | ||
}, | ||
{ | ||
pattern: /Bob|David/, | ||
style: styles.name, | ||
onPress: this.handleNamePress, | ||
}, | ||
{ | ||
pattern: /\[(@[^:]+):([^\]]+)\]/i, | ||
style: styles.username, | ||
onPress: this.handleNamePress, | ||
renderText: this.renderText, | ||
}, | ||
{ pattern: /42/, style: styles.magicNumber }, | ||
{ pattern: /#(\w+)/, style: styles.hashTag }, | ||
]} | ||
> | ||
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. | ||
But you can also do more with this package, for example Bob will change style and David too. You should mention [@michel:5455345] about that. [email protected] | ||
And the magic number is 42! | ||
#react #react-native | ||
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. But you can also do more with | ||
this package, for example Bob will change style and David too. You | ||
should mention [@michel:5455345] about that. [email protected] And the | ||
magic number is 42! #react #react-native | ||
</ParsedText> | ||
</View> | ||
); | ||
|
@@ -113,7 +129,6 @@ const styles = StyleSheet.create({ | |
hashTag: { | ||
fontStyle: 'italic', | ||
}, | ||
|
||
}); | ||
|
||
AppRegistry.registerComponent('Example', () => Example); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
module.exports = { | ||
retainLines: true, | ||
compact: true, | ||
comments: false, | ||
presets: ["module:metro-react-native-babel-preset"], | ||
sourceMaps: false | ||
module.exports = function(api) { | ||
EvanBacon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
api.cache(true); | ||
EvanBacon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return { | ||
presets: ['babel-preset-expo'], | ||
EvanBacon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import React from 'react'; | ||
import ReactNative from 'react-native'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any significant changes in this file that need to be reviewed? Most of them look like Formatting changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default export of |
||
import { Text } from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import TextExtraction from './lib/TextExtraction'; | ||
|
@@ -11,25 +11,25 @@ export const PATTERNS = { | |
}; | ||
|
||
const defaultParseShape = PropTypes.shape({ | ||
...ReactNative.Text.propTypes, | ||
...Text.propTypes, | ||
type: PropTypes.oneOf(Object.keys(PATTERNS)).isRequired, | ||
}); | ||
|
||
const customParseShape = PropTypes.shape({ | ||
...ReactNative.Text.propTypes, | ||
pattern: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(RegExp)]).isRequired, | ||
...Text.propTypes, | ||
pattern: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(RegExp)]) | ||
.isRequired, | ||
}); | ||
|
||
class ParsedText extends React.Component { | ||
|
||
static displayName = 'ParsedText'; | ||
|
||
static propTypes = { | ||
...ReactNative.Text.propTypes, | ||
...Text.propTypes, | ||
parse: PropTypes.arrayOf( | ||
PropTypes.oneOfType([defaultParseShape, customParseShape]), | ||
), | ||
childrenProps: PropTypes.shape(ReactNative.Text.propTypes), | ||
childrenProps: PropTypes.shape(Text.propTypes), | ||
}; | ||
|
||
static defaultProps = { | ||
|
@@ -42,8 +42,8 @@ class ParsedText extends React.Component { | |
} | ||
|
||
getPatterns() { | ||
return this.props.parse.map((option) => { | ||
const {type, ...patternOption} = option; | ||
return this.props.parse.map(option => { | ||
const { type, ...patternOption } = option; | ||
if (type) { | ||
if (!PATTERNS[type]) { | ||
throw new Error(`${option.type} is not a supported type`); | ||
|
@@ -56,14 +56,21 @@ class ParsedText extends React.Component { | |
} | ||
|
||
getParsedText() { | ||
if (!this.props.parse) { return this.props.children; } | ||
if (typeof this.props.children !== 'string') { return this.props.children; } | ||
|
||
const textExtraction = new TextExtraction(this.props.children, this.getPatterns()); | ||
if (!this.props.parse) { | ||
return this.props.children; | ||
} | ||
if (typeof this.props.children !== 'string') { | ||
return this.props.children; | ||
} | ||
|
||
const textExtraction = new TextExtraction( | ||
this.props.children, | ||
this.getPatterns(), | ||
); | ||
|
||
return textExtraction.parse().map((props, index) => { | ||
return ( | ||
<ReactNative.Text | ||
<Text | ||
key={`parsedText-${index}`} | ||
{...this.props.childrenProps} | ||
{...props} | ||
|
@@ -73,13 +80,13 @@ class ParsedText extends React.Component { | |
} | ||
|
||
render() { | ||
// Discard custom props before passing remainder to ReactNative.Text | ||
// Discard custom props before passing remainder to Text | ||
const { parse, childrenProps, ...remainder } = { ...this.props }; | ||
|
||
return ( | ||
<ReactNative.Text ref={ref => (this._root = ref)} {...remainder}> | ||
<Text ref={ref => (this._root = ref)} {...remainder}> | ||
{this.getParsedText()} | ||
</ReactNative.Text> | ||
</Text> | ||
); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any significant changes in this file that need to be reviewed? Most of them look like Formatting changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default export of
react-native
has been removed from web and will be removed from native soon. I opened this PR right after deleting it. It was removed because it causes all of the RN module to be bundled regardless of if you are using them or not.