-
Notifications
You must be signed in to change notification settings - Fork 161
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
Setting allowFontScaling prop on <Text> #61
Comments
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? |
Hey! Thanks for the quick reply.
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 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 For context, the list I had was basically this: Some text...
- Item 1
- Item 2 |
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:
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 |
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. 👍 |
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. |
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. |
@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> |
Thank you @hetmann! |
For anyone coming here with issues regarding their font automatically getting smaller based on views/containers, you'll want to also use Example of markdown rule: textgroup: (node, children, parent, styles) => (
<Text
key={node.key}
allowFontScaling={false}
style={{
color: colors.dark_80,
fontFamily: 'Barlow-Light',
fontWeight: '400',
}}
>
{children}
</Text>
), |
Hi! First off, thank you for this package.
I'm playing around with it in a React Native (Expo) app and I'm having trouble with font size. I'd like to disable font scaling but it doesn't seem like it's possible. I had a quick look through the code and in React Native itself and it seems like it could be related to a few things.
For example, the following code, unrelated to your package, will result in "Test" being rendered at a fixed size, regardless of your device's font size. That is, the disabling of the font scaling is working. If, however, I put the
allowFontScaling
on the inner<Text>
only, it doesn't work.So, I tried the following:
As this doesn't work, I can only imagine it's related to the issue I mentioned above (the nested
<Text>
components). Hopefully I'm missing something here, though, and that there's an easy solution to disable all font scaling in my rendered markdown. If there's not, I think it'd be a great prop for theMarkdown
component itself, setting the property on all rendered<Text>
components.Anyway, I hope that was clear enough. Have a nice day. ✌️
The text was updated successfully, but these errors were encountered: