Git Product home page Git Product logo

Comments (9)

chriswayg avatar chriswayg commented on June 21, 2024 3

I was just looking into the same issue and found a workaround that resolves the issue once and for all, in the entire app.

Add this line to your App.tsx:

(Text as any).defaultProps = { ...(Text as any).defaultProps, allowFontScaling: false };

Note that this is perusing an undocumented API, hence use it at your own risk.

I am using the following in App.js

Text.defaultProps = {};
Text.defaultProps.allowFontScaling = false;

My version is documented or at least commonly recommended, as well as the maxFontSizeMultiplier as an alternative . - But both approaches have the disadvantage that it applies to the whole app and not just the Markdown view, which is what I am still looking for.

from react-native-markdown-display.

hetmann avatar hetmann commented on June 21, 2024 3

@darrylyoung @chriswayg or you can use it like this:

<Markdown
  rules={{
    text: (node, children, parent, styles, inheritedStyles = {}) => (
      <Text
        allowFontScaling={false}
        maxFontSizeMultiplier={1.2} // <- add this one
        key={node.key}
        style={[inheritedStyles, styles.text]}
      >
        {node.content}
      </Text>
    ),
  }}
  style={markdownStyles}
>
  {content}
</Markdown>

from react-native-markdown-display.

pehagg avatar pehagg commented on June 21, 2024 2

I was just looking into the same issue and found a workaround that resolves the issue once and for all, in the entire app.

Add this line to your App.tsx:

(Text as any).defaultProps = { ...(Text as any).defaultProps, allowFontScaling: false };

Note that this is perusing an undocumented API, hence use it at your own risk.

from react-native-markdown-display.

iamacup avatar iamacup commented on June 21, 2024 1

I can take a look at this a little bit later, do you mind trying to see what happens if you overwrite the TextGroup rule as well and apply the scaling prop?

from react-native-markdown-display.

iamacup avatar iamacup commented on June 21, 2024 1

Yeha its a propper pain in the ass, this is why this exists in the readme, and is a hangover from the parent library this fork came from:

Be careful when styling 'text': the text rule is not applied to all rendered text, most notably list bullet points. If you want to, for instance, color all text, change the body style.

but in this case, we need to apply a prop not a style, to the text components.

I will have a little think about how best to approach this and try and commit something tomorrow, in the mean time you will need to change the list render rule, which is an ugly rule to change because of the hasParents dependency... list_item but i think its the only solution right this second - probably just copy and paste the whole thing - you can import hasParents as it is exported here: https://github.com/iamacup/react-native-markdown-display/blob/master/src/index.js

from react-native-markdown-display.

AdamGerthel avatar AdamGerthel commented on June 21, 2024 1

I'm looking into switching to this library from react-native-markdown-view because this specific feature is lacking there too, and that library seems less maintained than this one.

There's a two year old pull request to add support for setting textProps, which is another possible way of doing it, see Pass props to components.

from react-native-markdown-display.

pokhiii avatar pokhiii commented on June 21, 2024 1

Thank you @hetmann!

from react-native-markdown-display.

darrylyoung avatar darrylyoung commented on June 21, 2024

Hey! Thanks for the quick reply.

if you overwrite the TextGroup rule as well and apply the scaling prop?

Sure. So, that got me 99% the way there and I thought no text was changing when setting my device text size but I did notice a small shift. This was due to a list I have in my markdown. It looks like there's a Text component there, too, that would also need to inherit the allowFontScaling={true} prop.

I haven't done too much digging in the code to see how feasible this is right now but I guess, in a situation like this, it's better to be able to set allowFontScaling (or something worded similarly) at the top level and then have it apply to all rendered <Text> components as opposed to manually overriding each rule.

For context, the list I had was basically this:

Some text...

- Item 1
- Item 2

from react-native-markdown-display.

darrylyoung avatar darrylyoung commented on June 21, 2024

Sounds good. Thanks again!

I'm in no immediate rush for this right now (my app won't be released for a month or so I imagine) but I really appreciate the support. I've starred the repository and I'm watching for releases so I'll check back at some point. Have a good week. 👍

from react-native-markdown-display.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.