Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding defaultProp on Text component #44

Open
AdamGerthel opened this issue Dec 1, 2019 · 1 comment
Open

Overriding defaultProp on Text component #44

AdamGerthel opened this issue Dec 1, 2019 · 1 comment

Comments

@AdamGerthel
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants