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

Font family style broken when using body styling rule and others simultaneously in Android Devices #137

Closed
CXZ7720 opened this issue Mar 16, 2021 · 3 comments

Comments

@CXZ7720
Copy link

CXZ7720 commented Mar 16, 2021

When apply custom font using body style rule to apply globally, other rule's fontFamily broken in android device.

I think this is because nested text component styling issue related with facebook/react-native#20398

DebugPrintTree options activated, the example result was like this.

스크린샷 2021-03-16 오전 11 08 31

Because of strong styled component were nested in default text styled component, fontFamily doesn't apply to children component.

[ENV]
RN 0.64.3
Device : Android 11

[How To Reproduce]

  1. Using custom font (like NotoSans from google fonts).
    In this case, I use separate font files of its weights from google fonts (NotoSans-Bold, NotoSans-Regular, NotoSans-Medium)
  2. apply different styling rules using style props
                    <Markdown
                      style={{
                        body: {
                          fontFamily: Fonts.NotoSansRegular,
                          fontSize: 15,
                        },
                        strong: {
						  fontFamily: Fonts.NotoSansBold
						}
                    >
                      {article.contents}
                    </Markdown>
  1. Only body styling applied and other nested component's style ignored and followed by system default.(In my case, just fontWeight were applied by default library's option, fontFamily style were overwritten by system font)
    image

  2. It has same result when using rules prop. I tried even replace global styling option body to text, but it doesn't work.

@ohmdob
Copy link

ohmdob commented Apr 9, 2021

same
my workaround

<Markdown
              style={{
                body: { fontFamily: typography.medium, color: '#FAA'}
              }}
              rules={{
                strong: (node) => <Text style={{ fontFamily: typography.bold, color: '#FAA'} as ViewStyle} text={node.children[0].content} />
              }}
              >
            {md}
 </Markdown>

@isonlaxman
Copy link

isonlaxman commented Apr 15, 2022

is this still the way to do this? seems like annoying effort just to get bold/italics working

@dmitry-blackwave
Copy link

Guys, you can try pass node content instead
strong: (node: ASTNode, _children: ReactNode, _parent: ASTNode[], _styles: StyleProp<any>) => ( <Text key={node.key}>{node?.children[0]?.content}</Text.Bold> ),

it works well for me

@iamacup iamacup closed this as completed Dec 11, 2023
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

5 participants