akveo / react-native-ui-kitten

:boom: React Native UI Library based on Eva Design System :new_moon_with_face::sparkles:Dark Mode
https://akveo.github.io/react-native-ui-kitten/
MIT License
10.19k stars 952 forks source link

allowFontScaling #1778

Closed poinch closed 9 months ago

poinch commented 9 months ago

💬 Question

UI Kitten and Eva version

Package Version
@eva-design/eva "^2.2.0"
@ui-kitten/components "^5.3.1"

I need to do not allowFontScaling across the entire app so i was wondering if there's a way to set allowFontScaling to false using the custom-mapping. I'm asking because i've already used thounds of times the Text component and it will be a pain to create a custom component at this point.

poinch commented 9 months ago

For anyone who is facing the same problem i fixed by creating something like this:

import { Text as RNText } from 'react-native';
import { Text, Input } from '@ui-kitten/components';

interface RNTextWithDefaultProps extends RNText {
  defaultProps?: { allowFontScaling?: boolean };
}

interface TextWithDefaultProps extends Text {
  defaultProps?: { allowFontScaling?: boolean };
}

interface InputTextWithDefaultProps extends Input {
  defaultProps?: { allowFontScaling?: boolean };
}

export const changeComponentsDefaultProps = () => {
  (RNText as unknown as RNTextWithDefaultProps).defaultProps =
    (RNText as unknown as RNTextWithDefaultProps).defaultProps || {};
  (RNText as unknown as RNTextWithDefaultProps).defaultProps!.allowFontScaling = false;

  (Text as unknown as TextWithDefaultProps).defaultProps =
    (Text as unknown as TextWithDefaultProps).defaultProps || {};
  (Text as unknown as TextWithDefaultProps).defaultProps!.allowFontScaling = false;

  (Input as unknown as InputTextWithDefaultProps).defaultProps =
    (Input as unknown as InputTextWithDefaultProps).defaultProps || {};
  (Input as unknown as InputTextWithDefaultProps).defaultProps!.allowFontScaling = false;
};

Basically i have created a function where i'm changing the default props of the React Native Text (because i'm using it, otherwise you can just avoid it), and the Text and the Input of UI Kitten. Here i'm on a typescript project that's why i'm in need of interfaces. Just call the function as soon the app starts.