Benjamin-Dobell / react-native-markdown-view

MarkdownView for React Native
MIT License
190 stars 77 forks source link

Overriding defaultProp on Text component #44

Open AdamGerthel opened 4 years ago

AdamGerthel commented 4 years ago

I'm using the following solution at the entry file for my project in order to set a default font:

import { Text } from 'react-native'

Text.defaultProps = Text.defaultProps || {}
Text.defaultProps.style = { fontFamily: 'Some fontname here' }

It's a neat and well-known solution to avoid having to specify a font on each text component (or having to write your own wrapper component for it).

But, for some reason, this doesn't work when using the MarkdownView component. I'm trying to specify fonts for bold and italic like this:

<MarkdownView 
  style={{
    em: {
      fontFamily: 'Some italic font'
    },
    strong: {
      fontFamily: 'Some bold font'
     }
  }}>
  Text goes here
</MarkdownView>

But that doesn't seem to be working if I use the defaultProps solution. It seems the defaultProps are overriding the markdown-style. Removing that one line specifying the default font fixes it (but I'd like to be able to use that solution).

Is there a way to fix this?

connectdotz commented 4 years ago

I think you want to use "styles", not "style", property under MarkdownView