Search code examples
react-nativetextfontssize

On changing device font, app font changes.How to restrict that?


I have used one custom font in the react native application. And everything is working fine accept when the users go to the phone settings and change the font size. Then in the application the UI looks pretty ugly. I have used StyleSheet.create method to create all the styles in the app and also have given definite font sizes for the texts. But even though when the phone settings font size is changed, my app font size also changes.

Is there a way to restrict any changes in the app's font size, irrespective of what users may do in the phone settings?


Solution

  • I was able to solve this problem using the following code in every page

    constructor() {
        super();
        if (Text.defaultProps == null) Text.defaultProps = {};
           Text.defaultProps.allowFontScaling = false;
    }
    
    

    Hope it can help others as well.