1

当我点击(灰色)多行框中的任何位置时,我一直试图让我的 TextInput 聚焦(打开键盘),但它只检测对带有文本(或占位符)的行的点击。

当我单击灰色区域的任意位置时,有什么方法可以强制 TextInput 聚焦?

   <ScrollView style={{ flex: 1}}>

    <View style = {Style.dropdownField}>
      <Dropdown
        label={'Motivo'}
        data={this.props.remiseExcusesData}
        value={this.state.remiseExcuses.value}            
        onChangeText={(value,index, data)=> this.setState({remiseExcuses:data[index]})}
      />
    </View>
    <View style = {{ height:150, marginHorizontal:20, backgroundColor:'#f9f9f9', marginTop:20}}>
    <TextInput
      style={Style.minitextInput}
      placeholder={'Escribir motivo'}
      textAlign={'left'}
      autoCorrect={false}
      autoCapitalize={'none'}
      underlineColorAndroid='transparent'
      multiline
      onChangeText={(text) => this.setState({motive:text})  }
      value={this.state.motive}
      onFocus={() => console.log('Fire only on tap')}
    />
    </View>
   </ScrollView>

在此处输入图像描述

4

2 回答 2

1

您可以使用它来处理灰色框的焦点。

<TouchableOpacity style = {{ height:150, marginHorizontal:20, backgroundColor:'#f9f9f9', marginTop:20}} onPress={this.onPressGrayBox}>
    <TextInput
      ref="textInput"
      style={{ height: 150, textAlignVertical: 'top' }}
      placeholder={'Escribir motivo'}
      textAlign={'left'}
      autoCorrect={false}
      autoCapitalize={'none'}
      underlineColorAndroid='transparent'
      multiline
      onChangeText={(text) => this.setState({motive:text})  }
      value={this.state.motive}

    />
    </TouchableOpacity> 

声明处理动作的方法,这将有助于自动设置文本输入焦点。

onPressGrayBox=()=>{
  this.refs.textInput.focus()
}

此步骤对我有帮助,请使用

于 2019-11-01T06:52:14.297 回答
0

你可以处理类似的事情

   <View style = {{ height:150, marginHorizontal:20, backgroundColor:'#f9f9f9', marginTop:20}}>
    <TextInput
      style={{ height: 150, textAlignVertical: 'top' }}
      placeholder={'Escribir motivo'}
      textAlign={'left'}
      autoCorrect={false}
      autoCapitalize={'none'}
      underlineColorAndroid='transparent'
      multiline
      onChangeText={(text) => this.setState({motive:text})  }
      value={this.state.motive}
      onFocus={() => console.log('Fire only on tap')}
    />
    </View>
于 2019-10-30T13:09:07.983 回答