juiceo / react-native-easy-markdown

Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.
https://www.npmjs.com/package/react-native-easy-markdown
65 stars 62 forks source link

Android crashes with Image and React Native 0.55.3 #17

Closed RGBboy closed 6 years ago

RGBboy commented 6 years ago

Essentially embedding any image in the markdown causes the following error on Android:

Unexpected view type nested under text node

This stems from the fact that View components are nested within Text components, which is no longer supported on Android.

juiceo commented 6 years ago

Hmm, iirc this was an issue before as well, which is why (at least the intention was) to not nest images in Text components anyway. Apparently there are cases where that still happens.

Could you share the input markdown that's causing this?

RGBboy commented 6 years ago

Sure, it is literally just an image:

![Test](https://placehold.it/320x320)

When in debug mode I get this:

==== LOGGING NODE TREE ===
Utils.js:43 > block_0, NODE TYPE: Text
Utils.js:43 > imageWrapper_0_0, NODE TYPE: undefined
RGBboy commented 6 years ago

Just had a deeper look and it looks like the problem is coming from the isTextOnly method in Utils.js. It seems like line 8:

nodes[i].type.hasOwnProperty('displayName'))

is returning false, causing the method to return true. Also looks like ReactNative does not have displayName anywhere on the type property. It may be better to inspect name instead.

juiceo commented 6 years ago

Hmm, I'll have a look, that might have changed. Thanks for the details!

juiceo commented 6 years ago

I pushed a fix to the master branch (removed the isTextOnly from use entirely). I'm unable to test it as I haven't upgraded any of my apps past RN 0.51, would you mind giving it a go?

jsslai commented 6 years ago

I can confirm this fixes the issue.

juiceo commented 6 years ago

Thanks. This fix is now published as 1.2.0 in npm.