2017-05-24 2 views
1

탐색기에서 버튼을 클릭하면 현재 화면의 하나의 TextInput에 포커스가 있습니다. textChange 함수를 트리거하기 위해 TextInput의 인스턴스 블러를 설정해야합니다.React Native : 메소드에서 TextInput 인스턴스 블러를 트리거하는 방법은 무엇입니까?

필자의 경우 TextInput의 커서가 항상 깜박입니다.

refs.username.blur()이 작동하지 않습니다.

enter image description here

내 코드 : 예상대로

class UploadRecordII extends Component{ 
    static navigationOptions = ({ navigation, screenProps }) => ({ 
    headerRight: (<Button containerStyle={{marginRight: 12,}} onPress={ UploadRecordII.onSubmit}> 
        <Text style={{color: 'white',fontSize: 18,}}>next</Text> 
       </Button>), 
    }); 
..... 


    static onSubmit() { 
    let that = UploadRecordII.instance; 
    debugger; 
    that.refs.username.blur(); 
    debugger; 
    that.props.commitCreateRecordUpdate(that.refs.username._lastNativeText,that.imageList) 
    that.props.navigation.navigate('Record3'); 
    } 



...... in render(){ 
.... 

<TextInput ref = 'username' placeholder='' editable = {true} maxLength = {500} 
        keyboardType='default' multiline={true} 
        style={styles.input} underlineColorAndroid='rgba(0,0,0,0)' 
          onBlur={ ()=> this.textChange()} 
        clearButtonMode='always' placeholderTextColor='#D6D0D8'></TextInput> 



... 
} 
+0

'onChange'를 사용하여'this.description'을 설정하고 버튼을 눌렀을 때'this.description'을 참조하는 것이 잘못된가요? 스크린 샷을 사용하는 대신 코드를 복사하십시오. –

+0

@BenjaminCommet이 질문을 다시 편집합니다. 내 코드가 변경되었습니다. – jiexishede

답변

0

는 심판이 더 이상 문자열로 작동하지 않습니다. 예를 들어 ref를 정의해야합니다.

class UploadRecordII extends Component { 
    constructor(props) { 
    super(props); 

    this.usernameInput = null; 
    } 

    onSubmit() { 
    this.usernameInput.blur(); 
    } 

    render() { 
    return (
    <TextInput ref={(input) => this.usernameInput = input} ... /> 
    ) 
    } 
} 
+0

대단히 고마워요! 나는 당신의 조언으로 내 코드를 수정했다.'this.usernameInput.blur();'역시 효과가 없다. – jiexishede

관련 문제