簡體   English   中英

React Native-專注於下一個TextInput字段

[英]React Native - Focusing on the next TextInput field

嘗試着重於下一個字段時,我得到的是undefined is not a function (evaluating '_this2._password.focus()')

<View style={{ height: h * .13, width: w }}>
   <Kohana style={[styles.input, { backgroundColor: '#f9f5ed' }]}
           label={'Email'}
           onChangeText={(email) => this.email = email}
           iconClass={MaterialsIcon}
           iconName={'email'}
           iconColor={'#ddd'}
           iconColor={'#f4d29a'}
           keyboardType={'email-address'}
           labelStyle={[styles.inputLabel, { color: '#91627b' }]}
           inputStyle={[styles.inputInput, { color: '#91627b' }]}
           blurOnSubmit={false}
           returnKeyType={"next"}
           onSubmitEditing={(e) => {this._password.focus()}} />
</View>
<View style={{ height: h * .13, width: w }}>
   <Kohana
           style={[styles.input, { backgroundColor: '#f9f5ed' }]}
           ref={(ref) => this._password = ref}
           label={'Password'}
           onChangeText={(password) => this.password = password}
           secureTextEntry={true}
           iconClass={MaterialsIcon}
           iconName={'lock'}
           iconColor={'#ddd'}
           iconColor={'#f4d29a'}
           blurOnSubmit={true}
           labelStyle={[styles.inputLabel, { color: '#91627b' }]}
           inputStyle={[styles.inputInput, { color: '#91627b' }]}/>
</View>

我嘗試了其他解決方案,一種是將ref this.refs._refName.focus()字符串,然后像this.refs._refName.focus()那樣調用它,另一種是來自Facebook的解決方案,您可以在其中創建refs連續整數- [this][1] ,但它們都不起作用。

焦點是TextInput組件的一種方法。 但是,您可以在Kohana組件中添加自定義focus方法,並調用組件中存在的TextInput的焦點。 為此,您將必須添加對TextInput的引用。

在這里查看我的答案: 在TextInput ref上調用focus方法時發生未定義的異常

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM