如何在不包装在PaperProvider中的React Native Paper TextInput中更改文本颜色?
目前这个方法是可行的:
const theme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
text: "orange",
}
};
<PaperProvider theme={theme}>
<TargetComponent />
</PaperProvider>
然而我希望通过从父组件传递的props控制文本颜色。奇怪的是,传递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
},
<TextInput label={<Text style={{color: "#someColor"}}>{someText}</Text>} />
- Amin Jafarlou