How to change styling of TextInput placeholder in React Native?
Is there a way to set fontStyle: 'italic'
only for the placeholder
of the TextInput in React Native?
looking here at the documentation seems like you can only set a placeholder and placeholderTextColor.
You can set your placeholder color by using the placeholderTextColor
prop.
<TextInput placeholderTextColor={'red'} />
Improving on Daniel's answer for a more generic solution
class TextInput2 extends Component {
constructor(props) {
super(props);
this.state = { placeholder: props.value.length == 0 }
this.handleChange = this.handleChange.bind(this);
}
handleChange(ev) {
this.setState({ placeholder: ev.nativeEvent.text.length == 0 });
this.props.onChange && this.props.onChange(ev);
}
render() {
const { placeholderStyle, style, onChange, ...rest } = this.props;
return <TextInput
{...rest}
onChange={this.handleChange}
style={this.state.placeholder ? [style, placeholderStyle] : style}
/>
}
}
Usage:
<TextInput2
value={this.state.myText}
style={{ fontFamily: "MyFont" }}
placeholderStyle={{ fontFamily: "AnotherFont", borderColor: 'red' }}
/>