有没有办法在React Native中为TextInput执行letterSpacing?

Fra*_*ian 10 react-native

我一直试图给出<TextInput>一个letterSpacing风格,但它似乎只适用于<Text>.React Native中有没有办法增加TextInput中字符之间的空间?

这增加了角色之间的空间

<Text style={{'letterSpacing': 5}}>Some Text</Text>
Run Code Online (Sandbox Code Playgroud)

这不行

<TextInput style={{'letterSpacing': 5}} />
Run Code Online (Sandbox Code Playgroud)

Pab*_*rde 1

这是一个可能的解决方案,也许不是更好。

杰斯小提琴

class Form extends React.Component {
  constructor() {
    super();
    this.state = {
        value: '',
    };
    this.onChangeText = this.onChangeText.bind(this);
  }

  onChangeText(e) {
    const val = e.target.value.replace(/ /g, '').split('');
    const spaced = val.join(' ');
    this.setState({
        value: spaced,
    });
  }

  render() {
    return(
        <div style={{flexDirection: 'column'}}>
        <div>Type Text</div>
        <input
          type='text'
          onChange={this.onChangeText}
          value={this.state.value}
        />
      </div>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 他说react native,你说react for web (5认同)