当TextInput onFocus和onBlur.React-Native更改样式

al

我在5页中有40个TextInput,需要更改输入文本的颜色onfocus:'white'和onBlur:'gray'我知道如何使它成为单输入,但是我需要多输入

<TextInput 
  clearTextOnFocus={true}
  keyboardType="number-pad"
  style={[this.state.isFocused?styles.inputOnFocus:styles.input]}
  onChangeText={v=>handleInput('value',v)}
  value={this.state.value}
  onFocus={()=>this.setState({isFocused:true})}
  onBlur={()=>this.setState({isFocused:false})}

/>
Auticcat

您可以简单地为每个输入提供一个ID,并使用该ID来知道哪个ID是重点:

<TextInput 
  clearTextOnFocus={true}
  keyboardType="number-pad"
  style={[this.state.FocusedItem === "TextInput1"? styles.inputOnFocus : styles.input]}
  onChangeText={v=>handleInput('value',v)}
  value={this.state.value}
  onFocus={()=>this.setState({FocusedItem: "TextInput1"})}
  onBlur={()=>this.setState({FocusedItem: ""})}
/>

在一个.map()函数中,它可能像:

arr.map( (item, index) => { 
   let ID = "TextInput"+index
   return (
       <TextInput 
          clearTextOnFocus={true}
          keyboardType="number-pad"
          style={[this.state.FocusedItem === ID? styles.inputOnFocus : styles.input]}
          onChangeText={v=>handleInput('value',v)}
          value={this.state.value}
          onFocus={()=>this.setState({FocusedItem: ID})}
          onBlur={()=>this.setState({FocusedItem: ""})}
       />
   ) 
})

这只是出于重点目的。如果代码保持这样,则所有输入将具有相同的值

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

更改样式和属性 onTextChange - React Native

来自分类常见问题

React钩子-onFocus和onBlur

来自分类Dev

React钩子-onFocus和onBlur

来自分类Dev

React native-动态更改样式

来自分类Dev

React-native textInput onFocus无法正常工作

来自分类Dev

如何在React Native中更改TextInput占位符的样式?

来自分类Dev

在Focus React Native Paper上更改TextInput样式

来自分类Dev

样式化组件的onFocus和onBlur事件不起作用

来自分类Dev

在React Native中触摸TextInput时打开键盘和/或DatePickerIOS

来自分类Dev

减少 react-native-paper TextInput 的高度和垂直填充

来自分类Dev

React Native中的隐藏TextInput

来自分类Dev

React Native:在文本中查找子字符串,并以编程方式更改样式

来自分类常见问题

如何在React Native中设置TextInput的样式以输入密码

来自分类Dev

react-native中TextInput的焦点样式

来自分类Dev

使用 react-native-textinput-effects 时的样式问题

来自分类Dev

在react-native中将焦点上的underlineColorAndroid更改为TextInput

来自分类Dev

如何在React Native TextInput中更改光标的宽度?

来自分类Dev

在React Native TextInput中更改单个单词的颜色

来自分类Dev

React Native:无法更改<TextInput>组件中文本的颜色

来自分类Dev

无法在React Native中更改或使用导入的TextInput的属性

来自分类Dev

更改Tab后,React Native TextInput值仍然存在

来自分类Dev

在react-native中将焦点上的underlineColorAndroid更改为TextInput

来自分类Dev

React Native:放入视图时TextInput消失

来自分类Dev

React Native Password TextInput引发警告

来自分类Dev

React Native Controller FormData TextInput不重置

来自分类Dev

React Native Set TextInput Value大写

来自分类Dev

React Native 无法在 TextInput 中聚焦

来自分类Dev

React-Native - TextInput 中的 Firebase 数据

来自分类Dev

在React Native中获取TextInput值和复选框状态

Related 相关文章

  1. 1

    更改样式和属性 onTextChange - React Native

  2. 2

    React钩子-onFocus和onBlur

  3. 3

    React钩子-onFocus和onBlur

  4. 4

    React native-动态更改样式

  5. 5

    React-native textInput onFocus无法正常工作

  6. 6

    如何在React Native中更改TextInput占位符的样式?

  7. 7

    在Focus React Native Paper上更改TextInput样式

  8. 8

    样式化组件的onFocus和onBlur事件不起作用

  9. 9

    在React Native中触摸TextInput时打开键盘和/或DatePickerIOS

  10. 10

    减少 react-native-paper TextInput 的高度和垂直填充

  11. 11

    React Native中的隐藏TextInput

  12. 12

    React Native:在文本中查找子字符串,并以编程方式更改样式

  13. 13

    如何在React Native中设置TextInput的样式以输入密码

  14. 14

    react-native中TextInput的焦点样式

  15. 15

    使用 react-native-textinput-effects 时的样式问题

  16. 16

    在react-native中将焦点上的underlineColorAndroid更改为TextInput

  17. 17

    如何在React Native TextInput中更改光标的宽度?

  18. 18

    在React Native TextInput中更改单个单词的颜色

  19. 19

    React Native:无法更改<TextInput>组件中文本的颜色

  20. 20

    无法在React Native中更改或使用导入的TextInput的属性

  21. 21

    更改Tab后,React Native TextInput值仍然存在

  22. 22

    在react-native中将焦点上的underlineColorAndroid更改为TextInput

  23. 23

    React Native:放入视图时TextInput消失

  24. 24

    React Native Password TextInput引发警告

  25. 25

    React Native Controller FormData TextInput不重置

  26. 26

    React Native Set TextInput Value大写

  27. 27

    React Native 无法在 TextInput 中聚焦

  28. 28

    React-Native - TextInput 中的 Firebase 数据

  29. 29

    在React Native中获取TextInput值和复选框状态

热门标签

归档