Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/ParsedText.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Text } from 'react-native';
import { Text, View, Pressable } from 'react-native';
import PropTypes from 'prop-types';

import TextExtraction from './lib/TextExtraction';
Expand Down Expand Up @@ -109,26 +109,39 @@ class ParsedText extends React.Component {

return textExtraction.parse().map((props, index) => {
const { style: parentStyle } = this.props;
const { style, ...remainder } = props;
const { style, onPress = null, onLongPress = null, ...remainder } = props;
const isNormalText = typeof onPress !== 'function';
const ParentComponent = isNormalText ? View : Pressable;
return (
<Text
<ParentComponent
key={`parsedText-${index}`}
style={[parentStyle, style]}
{...this.props.childrenProps}
{...remainder}
/>
onPress={onPress}
onLongPress={onLongPress}
>
<Text
style={[parentStyle, style]}
{...this.props.childrenProps}
{...remainder}
/>
</ParentComponent>
);
});
}

render() {
// Discard custom props before passing remainder to Text
const { parse, childrenProps, ...remainder } = { ...this.props };
const { parse, childrenProps, style = {}, ...remainder } = {
...this.props,
};

return (
<Text ref={(ref) => (this._root = ref)} {...remainder}>
<View
ref={(ref) => (this._root = ref)}
style={[{ flexDirection: 'row', flexWrap: 'wrap' }, style]}
{...remainder}
>
{this.getParsedText()}
</Text>
</View>
);
}
}
Expand Down