1
A
回答
3
您可以添加對文本輸入的引用,並從Modal的onShow處理函數中調用焦點方法。
import React, { Component } from 'react';
import { Modal, Text, TextInput, TouchableHighlight, View } from 'react-native';
export default class ModalExample extends Component {
state = {
modalVisible: false,
}
render() {
return (
<View style={{flex: 1, justifyContent:'center', alignSelf: 'center'}}>
<Modal
animationType={"slide"}
transparent={false}
visible={this.state.modalVisible}
onShow={() => { this.textInput.focus(); }}
>
<View style={{backgroundColor: 'green', marginTop: 50, width: 300, padding: 50, alignSelf: 'center'}}>
<View>
<Text>Hello World!</Text>
<TextInput
ref={(input) => { this.textInput = input; }}
style={{ padding: 20, backgroundColor: 'white', color: 'red' }}
/>
</View>
</View>
</Modal>
<TouchableHighlight onPress={() => {
this.setState({modalVisible: true});
}}>
<Text>Show Modal</Text>
</TouchableHighlight>
</View>
);
}
}
+0
完美!這正是我所期待的。謝謝! –
相關問題
- 1. React Native中的文本溢出。 (react-native-modal)
- 2. Modal沒有顯示在react-native?
- 3. Make React Native Modal從上到下出現
- 4. 如何檢查輸入中輸入文本的大小? React-Native
- 5. React-Native帶邊框的文本輸入?
- 6. React Native - 無法創建文本輸入
- 7. React Native中的react-native run-android
- 8. 禁用來自react-native-autocomplete輸入的輸入
- 9. SyntaxError在react-native中加載launchChrome.js
- 10. 在React Native中加載Android圖像
- 11. React-Native:在webview中動態注入javascript
- 12. 在React-Native WebView中注入JavaScript調用
- 13. 輸入,無法檢索輸入值React Native
- 14. React-Native Modal在Dom渲染時不顯示
- 15. React Native iOS - Modal未在模擬器上顯示
- 16. 如何在React Native中動態添加文本輸入
- 17. React Native Native Stylesheet
- 18. React Native:從AsyncStorage加載值
- 19. React Native中的zIndex
- 20. React Native中的Geofencing
- 21. React Native中的SHA256
- 22. React Native中的defaultProps?
- 23. 爲什麼react-native-image-picker的showImagePicker在React Native中未定義?
- 24. 在現有的React Native iOS項目中安裝React-Native Android?
- 25. 顯示/關閉使用React Native和Redux的Modal
- 26. 加載一個輸入框的負載
- 27. 在React Native中居中PickerIOS
- 28. react-native插入youtube視頻
- 29. React-Native無法導入庫
- 30. React Router v4 Modal
你到目前爲止試過了什麼? – vinayr