Skip to content

Overriding defaultProp on Text component #44

Description

@AdamGerthel

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions