react-native-markdown-renderer icon indicating copy to clipboard operation
react-native-markdown-renderer copied to clipboard

Default `hardbreak` breaks on Android

Open ghost opened this issue 7 years ago • 3 comments
trafficstars

When trying to render the following

 **2. Find a pattern  (addition, subtraction)  \n With five components**

It breaks on android, specifically where the " \n " is (note the two spaces that cause the hardbreak)

On android this error occurs when rendering

Unexpected view type nested under text node: class com.facebook.react.uimanager.LayoutShadowNode

According to https://github.com/facebook/react-native/issues/10232 this is only a problem for android and not iOS as your able to put view inside text in iOS

The default render rule for hardbreak is a view which causes view inside text to occur. The default should be changed so that it does not break on android.


To get around this I used this render rule for hardbreak instead

hardbreak: (node, children, parent, styles) => (
    <Text key={node.key} styleSheet={styles.hardbreak}>
        {"\n"}
    </Text>,
),

ghost avatar Jun 20 '18 01:06 ghost

This has been fixed in v3.2.8 see ticket #56 describing the same issue, or i am missing something. Thx for reporting this anyway.

mientjan avatar Jun 20 '18 11:06 mientjan

@mientjan

I had another look to see if I did a mistake.

I am on v3.2.8 and I still got the error above.

I'm not exactly sure how the markdown is converted to react-native jsx but the issue lies in hardbreak generating a View being contained in Text components where on android this is not allowed .

So either:

  • hardbreak needs to either split Text components on the most outer level and implement the hardbreak View between the Text paragraphs,
  • OR hardbreak needs to be done through raw text to fit with react-native current standards as my PR (although since its a hard break it should probably contain 2 new lines rather then 1).

Thanks for looking at this.

mazharmorshed avatar Jun 24 '18 05:06 mazharmorshed

I can confirm that this is still a real problem in 3.2.8.

__some bold text  
on two lines__

In this case there is a hardbreak after the word text

toml0006 avatar Aug 03 '18 16:08 toml0006