2017-06-14 88 views
-2

当按下输入文本到3秒时,显示消息“应用程序名称已停止”,如何更正此问题?................ .................................................. ......................... enter image description here输入反应本机 - 按崩溃应用程序

我的组件

return (
     <ReactNative.TextInput 
      ref={(ref: any) => { this.input = ref; }} 
      style={styleInputFormDefault} 
      numberOfLines={this.state.numberOfLines} 
      blurOnSubmit={true} 
      editable={this.state.editable} 
      underlineColorAndroid={"transparent"} 
      value={this.state.value} 
      multiline={this.state.multiline} 
      placeholder={this.state.placeholder} 
      keyboardType="default" 
      onChange={event => { 
       this.value = event.nativeEvent.text; 
      }} 
      onEndEditing={event => { 
       this.value = event.nativeEvent.text; 
       if (this.props.onChange != undefined) { 
        !this.props.onChange(this.value); 
       } 
      }} 
      returnKeyType={this.state.returnKeyType} 
      onSubmitEditing={() => { 
       if (this.props.onSubmit != undefined) { 
        this.props.onSubmit(this); 
       } 
      }} 
      onFocus={() => { 
       if (this.props.onFocus != undefined) { 
        this.props.onFocus(); 
       }; 
      }} 
      onBlur={() => { 
       if (this.props.onBlur != undefined) { 
        this.props.onBlur(); 
       }; 
      }} 
     > 
     </ReactNative.TextInput> 

    ); 

回答

0

为什么使用这样的TextInput组件?只需从原生反应中导入TextInput即可。

试试这个代码:

import React, { Component } from 'react' 
import { TextInput } from 'react-native' 

export default class InputClassName extends Component { 
    constructor(props) { 
    super(props) 
    this.input = null 
    this.state { 
     [...] 
    } 
    } 

    render() { 
    return(
     <View> 
     <TextInput 
      ref={ref => this.input = ref} 
      style={styleInputFormDefault} 
      numberOfLines={this.state.numberOfLines} 
      blurOnSubmit={true} 
      underlineColorAndroid={"transparent"} 
      value={this.state.value} 
      multiline={this.state.multiline} 
      placeholder={this.state.placeholder} 
      keyboardType="default" 
      onChangeText={value => this.value = value} 
      onEndEditing={event => { 
       // I do not know what you're trying to do here 
       // Are you checking if the onChange props is a function? If so, do this instead: 
       // if("function" === typeof this.props.onChange) { [...] } 
       this.value = event.nativeEvent.text; 
       if (this.props.onChange != undefined) { 
        !this.props.onChange(this.value); 
       } 
      }} 
      returnKeyType={this.state.returnKeyType} 
      onSubmitEditing={() => { 
       // same goes here 
       if (this.props.onSubmit != undefined) { 
        this.props.onSubmit(this); 
       } 
      }} 
      onFocus={() => { 
       // also here 
       if (this.props.onFocus != undefined) { 
        this.props.onFocus(); 
       }; 
      }} 
      onBlur={() => { 
       // and here. 
       if (this.props.onBlur != undefined) { 
        this.props.onBlur(); 
       }; 
      }} 
     > 
     </TextInput> 
     { /* Please note that you can also use propTypes in order to force (recommended) 
      a specific prop to be the typeof whatever you want instead of using if/else */ } 
     </View> 
    ) 
    } 
}