From cb374d04f406c403b080816b8cdd8accacfee550 Mon Sep 17 00:00:00 2001 From: Naveen Pantra Date: Sat, 20 Mar 2021 20:32:33 +0530 Subject: [PATCH] Change in hierarchy of view for more touchable response --- src/ParsedText.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/ParsedText.js b/src/ParsedText.js index d8a0cc5..f9fd428 100644 --- a/src/ParsedText.js +++ b/src/ParsedText.js @@ -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'; @@ -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 ( - + onPress={onPress} + onLongPress={onLongPress} + > + + ); }); } render() { // Discard custom props before passing remainder to Text - const { parse, childrenProps, ...remainder } = { ...this.props }; + const { parse, childrenProps, style = {}, ...remainder } = { + ...this.props, + }; return ( - (this._root = ref)} {...remainder}> + (this._root = ref)} + style={[{ flexDirection: 'row', flexWrap: 'wrap' }, style]} + {...remainder} + > {this.getParsedText()} - + ); } }