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

Fix heading bug

Open gchallen opened this issue 6 years ago • 10 comments

Will close #71.

gchallen avatar Sep 26 '18 20:09 gchallen

+1.

My environment is react native 0.57. When apply this pr, heading works

alsotang avatar Sep 30 '18 13:09 alsotang

+1 (RN 0.57.1)

hugotox avatar Sep 30 '18 18:09 hugotox

/*
There is bug in react-native-markdown-renderer with rn 0.57. So fix it with the code below.
https://github.com/mientjan/react-native-markdown-renderer/pull/79
 */
function fixMarkdownLib() {
  const applyStyle = require('react-native-markdown-renderer/src/lib/util/applyStyle.js')
  applyStyle.default = function applyStyle(children, styles, type) {
    if (!(styles instanceof Array)) {
      styles = [styles];
    }

    return children.map(child => {
      if (child.type.render.name === type) {
        return <Text key={child.key} {...child.props} style={[].concat(child.props.style, styles)} />;
      }

      return child;
    });
  }
}
fixMarkdownLib()

Currently I use the code above to fix the problem

alsotang avatar Oct 02 '18 16:10 alsotang

Hi! This PR should be merged because headings are not functional right now. @alsotang thanks for your fix but it works only in Debug builds, not Release ones, I guess it's not possible to modify code from the bundle at runtime in Release mode...

psegalen avatar Oct 08 '18 20:10 psegalen

seems we should fork a another version of this package

alsotang avatar Oct 09 '18 03:10 alsotang

I just fork and publish a new pkg named rnmd

https://github.com/alsotang/react-native-markdown-renderer

and I have merged this pr.

The author of react-native-markdown-renderer seems disappeared.

alsotang avatar Oct 09 '18 03:10 alsotang

@alsotang thanks but it (your fork with this PR merged) still doesn't work in Release builds and that's really odd! I'm digging deeper...

psegalen avatar Oct 09 '18 13:10 psegalen

Ok, so child.type.render.name is populated with "Text" when in Debug mode but with an empty string when in Release mode. I guess the feature was some kind of hack through React Native's structure and security has been enhanced, preventing the feature to stay functional. Debug mode Release mode

psegalen avatar Oct 09 '18 14:10 psegalen

Okay, I have a solution but it's not pretty ... but it works! 😅 I'll open a new PR and ref this one.

psegalen avatar Oct 09 '18 14:10 psegalen

I merged this pull request directly into into react-native-markdown-display here: https://github.com/iamacup/react-native-markdown-display/pull/12

in case anyone else comes accross this and needs the merged PRs, react-native-markdown-display is available on NPM

iamacup avatar Nov 06 '19 17:11 iamacup