我想制作一个“TypefaceTextInput”,它将具有特定的字体和文本颜色,并将替换 native react 中的所有 TextInput。这样我就不必每次都声明字体和文本颜色。有什么办法可以做到吗?
我是react-native新手,但熟悉java和kotlin中的android。 如果您可以用我们在 java 或 kotlin 中的类比来回答,那将非常有帮助。
找到这个答案here其中说
a library of components for our app that match the styles and naming of the style guide put together by our design team
但我认为如果我们使用它,将会有额外的嵌套组件。我们有什么方法可以扩展 TextInput 并在子类中执行需要的操作吗?
最佳答案
检查此模块 https://github.com/Ajackster/react-native-global-props
我用它作为
import {
setCustomTextInput,
setCustomText,
} from 'react-native-global-props';
// Setting default styles for all Text components.
const customTextProps = {
style: {
fontFamily: 'DINPro'
},
};
要添加自定义字体,您可以使用以下教程 https://medium.com/@kswanie21/custom-fonts-in-react-native-tutorial-for-ios-android-76ceeaa0eb78
关于javascript - 扩展 TextInput 以在 React Native 中自定义默认字体和文本颜色,就像在 Java 中一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48661605/