2

我們的應用程序中有一個React Native TextInput組件。使用虛擬鍵盤,按Enter鍵創建一個新行。如果我們使用硬件鍵盤(使用USB OTG適配器連接到Android 6平板電腦),Enter鍵(鍵盤中間的大鍵盤)不會更改文本,但TextInput只會失去焦點。 Return鍵(普通鍵盤右側較小的一個)創建一個新行。React Native TextInput:不帶硬件鍵盤的換行輸入鍵

了TextInput是設置非常簡單:

<TextInput multiline={true} /> 

我嘗試了不同的值的returnKeyType屬性,但它們都沒有建立新行。我錯過了什麼嗎?

回答

1

我面臨同樣的問題,但對我下面的工作:

returnKeyType='none' 
0

試試吧!它也在線的中間工作!

<TextInput 
        placeholder={I18n.t('enterContactQuery')} 

        value={this.state.query} 
        onChangeText={text => this.setState({ query: text, allowEditing: true })} 

        selection = {this.state.selection} 
        onSelectionChange={(event) => this.setState({ cursorPosition: event.nativeEvent.selection, selection: event.nativeEvent.selection, allowEditing: true })} 
        onSubmitEditing={() => { 
        const { query, cursorPosition } = this.state; 
        let newText = query; 
        const ar = newText.split(''); 
        ar.splice(cursorPosition.start, 0, '\n'); 
        newText = ar.join(''); 
        if (cursorPosition.start === query.length && query.endsWith('\n')) { 
         this.setState({ query: newText }); 
        } else if (this.state.allowEditing) { 
         this.setState({ 
         query: newText, 
         selection: { 
          start: cursorPosition.start + 1, 
          end: cursorPosition.end + 1 
         }, 
         allowEditing: !this.state.allowEditing 
         }); 
        } 
        }} 
        multiline = {true} 
        numberOfLines = {10} 
        blurOnSubmit={false} 
        editable={true} 
        // clearButtonMode="while-editing" 
       /> 

constructor(props) { 
super(props); 
this.state = { 
    query: '', 
    cursorPosition: [0,0], 
    selection: null, 
    allowEditing: true 
} 

}

相關問題