如何在 React Native Paper 中更改 TextInput 的文本颜色而不用在 PaperProvider 中换行?
目前这有效:
const theme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
text: "orange",
}
};
<PaperProvider theme={theme}>
<TargetComponent />
</PaperProvider>
但是我想通过从父组件传递的 Prop 来控制文本颜色。
奇怪,路过
backgroundColor
有效但 color
才不是。删除
PaperProvider
包装也无济于事。这是 TargetComponent 中的相关代码:
return (
<View style={styles.container}>
<TextInput
type="outlined"
style={this.props.style}
onChangeText={this.props.onChange}
label={this.props.label}
value={this.props.value || "Replace this text"}
placeholder={this.props.placeholder}
/>
</View>
)
this.props.style
是:{
color: "orange", // This does not work
backgroundColor: "transparent" // This works
},
最佳答案
找到了解决办法。但对于那些处于同样困境的人:
出于某种原因color
不被识别为 style
支持即使其他人,如 backgroundColor
, 是。
只需通过 theme
作为 TextInput
的 Prop .在那theme
对象,像这样分配文本颜色:
<TextInput
type="outlined"
style={{ ...styles.textInput, ...this.props.style }}
underlineColor={this.theme.colors.primary}
onChangeText={this.props.onChange}
label={this.props.label}
value={this.props.value || "Replace this text"}
placeholder={this.props.placeholder}
theme={{ colors: { text: this.props.style.color } }}
/>
关于react-native - 在 React Native Paper 中更改 TextInput 的文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55958311/