react-native-htmlview icon indicating copy to clipboard operation
react-native-htmlview copied to clipboard

Unexpected view type nested under text node

Open slimcheng opened this issue 6 years ago • 9 comments

qq20180518-173257 2x

wechatimg43

<p><img src="https://user-images.githubusercontent.com/3722860/40227824-219012b2-5ac2-11e8-8ef9-eff05889d76c.png"></p>

When removing the TouchableOpacity components,or

<img src="https://user-images.githubusercontent.com/3722860/40227824-219012b2-5ac2-11e8-8ef9-eff05889d76c.png">

the error no longer appears。

slimcheng avatar May 18 '18 09:05 slimcheng

+1

zengyimou avatar Jun 04 '18 06:06 zengyimou

+1

emilisb avatar Jun 19 '18 12:06 emilisb

+1 when I use renderNode to show the img like this issue https://github.com/jsdf/react-native-htmlview/issues/220 if the html content do not include p Tag ,the error will not show up

syuenkei avatar Jul 05 '18 06:07 syuenkei

+1

jhonmer-araujo avatar Sep 20 '18 18:09 jhonmer-araujo

+1,how to resolve it?

Thyiad avatar Feb 02 '19 10:02 Thyiad

+1 how resolve it?

erez-guesty avatar Mar 13 '19 09:03 erez-guesty

Does somebody succeeded to solve it?

dmitryguesty avatar Mar 13 '19 16:03 dmitryguesty

I finally used webview to show richtext.

Thyiad avatar Mar 14 '19 00:03 Thyiad

After struggling with a similar problem for a long time, I finally found a (somewhat) elegant way to resolve it. As mentioned in an earlier comment the issue is the enclosing p tag. The parser translates it as a Text tag and then you can no longer have any view tags within that Text tag without getting this error.

There are several approaches you might take, but I simply set the parser to convert top level p tags to View tags and then applied a flexDirection of 'row' to the View to give it similar properties. Here's what my code looks like:

if (node.name === 'p' &&
        node.parent === null) {
      return (
        <View key={index} style={styles.messageWrap}>
          {defaultRenderer(node.children, parent)}
        </View>
      );
    } 


const styles = {
  messageWrap: {
    flexDirection: 'row',
    justifyContent: 'flex-start',
    flexWrap: 'wrap'
  }
};

lorenzsell avatar Jul 25 '19 16:07 lorenzsell