gpt4 book ai didi

react-native - React Native Text.defaultProps 不存在并且创建它也不起作用

转载 作者:行者123 更新时间:2023-12-04 04:39:53 25 4
gpt4 key购买 nike

我是 React Native (0.59.3) 的新手,我正在尝试为我的应用程序中的所有 Text 组件设置默认字体。我读过 https://stackoverflow.com/a/47925418/811405How to disable font scaling in React Native for IOS app? .

在我的 App.js 中,我放了:

import { Text } from 'react-native';

Text.defaultProps.style = {
fontFamily: 'AmericanTypewriter' //just for testing
}

但是我得到了 Cannot set property 'style' of undefined

当我添加行 Text.defaultProps = Text.defaultProps || {}; 在此之前,我没有收到错误,但什么也没有发生(所有 Text 组件仍然使用默认字体)。我尝试使用不同的字体(内置 iOS 字体和我链接和验证的自定义字体),使用它们的 PostScript 名称,但没有任何反应。

我做错了什么?

最佳答案

在更改fontFamily 样式之前添加这个

import { Text } from 'react-native';

Text.defaultProps = Text.defaultProps || {};

关于react-native - React Native Text.defaultProps 不存在并且创建它也不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55533105/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com