Skip to content
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

Change in hierarchy of view for more touchable response #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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