react-native-markdown-renderer
react-native-markdown-renderer copied to clipboard
Fix heading bug
Will close #71.
+1.
My environment is react native 0.57. When apply this pr, heading
works
+1 (RN 0.57.1)
/*
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
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...
seems we should fork a another version of this package
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 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...
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
Okay, I have a solution but it's not pretty ... but it works! 😅 I'll open a new PR and ref this one.
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