我有一個非常簡單的表格來寫評論,帶有 a<TextInput>和 an <IconButton>:
截屏:

代碼:
<View style={styles.container}>
<TextInput
mode={'outlined'}
onChangeText={(val) => setCommentText(val)}
value={commentText}
label={'Write a comment...'}
/>
<IconButton
icon="send"
onPress={addComment}
/>
</View>
問題是用戶必須點擊發送按鈕兩次。第一次單擊只會模糊輸入并關閉鍵盤,但按鈕不會注冊單擊。然后,當 TextInput 模糊時,他們實際上可以單擊提交按鈕。
TextInput當有焦點時,如何才能只單擊一次“發送”按鈕?
uj5u.com熱心網友回復:
其實這種行為是正常的。如果鍵盤打開并且您想與螢屏互動,第一次單擊將關閉鍵盤,第二次將起作用。因此,作為最佳實踐,您可以在鍵盤上設定一個按鈕,單擊該按鈕將觸發您想要的呼叫請求:

<TextInput
mode={'outlined'}
onChangeText={(val) => setCommentText(val)}
value={commentText}
returnKeyType="send"
onSubmitEditing={() => {
// call you api or whatever function here;
}}
label={'Write a comment...'}
blurOnSubmit={false}
/>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/428811.html
標籤:反应式
