gpt4 book ai didi

ios - React Native IOS InputAccessoryView 关闭模态后从屏幕上消失

转载 作者:行者123 更新时间:2023-12-02 11:58:36 38 4
gpt4 key购买 nike

当我的屏幕上有InputAccessoryView,它的组件没有nativeID(因此即使没有显示键盘,它也会不断显示)并且我打开和关闭Modal(react-native modal),然后InputAccessoryView与该组件一起从屏幕上消失。我不知道为什么会发生这种情况,也不知道如何将此 InputAccessoryView 保留在屏幕上。

这是重现它的代码:

import * as React from 'react';
import { View, ScrollView, AppRegistry, TextInput, InputAccessoryView, Button } from 'react-native';
import {Modal, Text, TouchableHighlight, Alert} from 'react-native';
import Constants from 'expo-constants';

export default class App extends React.Component {

constructor(props) {
super(props);
this.state = {text: 'Placeholder Text', modalVisible: false,};
}

setModalVisible(visible) {
this.setState({modalVisible: visible});
}

render() {
return (
<View style={{flex:1}}>
<Modal
animationType="slide"
transparent={false}
visible={this.state.modalVisible}
onRequestClose={() => {
Alert.alert('Modal has been closed.');
}}>
<View style={{marginTop: 22, padding: 50, backgroundColor: '#0066ff'}}>
<View>
<TouchableHighlight
onPress={() => {
this.setModalVisible(!this.state.modalVisible);
}}>
<Text style={{color:"#ffffff"}}>Hide Modal</Text>
</TouchableHighlight>
</View>
</View>
</Modal>


<ScrollView style={{ backgroundColor: '#6ED4C8'}}>
<Text></Text>
<TouchableHighlight
onPress={() => {
this.setModalVisible(true);
}}>
<Text style={{padding: 40, backgroundColor: "#ff3300"}}>Show Modal</Text>
</TouchableHighlight>
</ScrollView>
<InputAccessoryView backgroundColor="#ff9900" >
<TextInput
style={{
padding: 20,
paddingTop: 50,
}}
onChangeText={text => this.setState({text})}
value={this.state.text}
/>
</InputAccessoryView>
</View>
);
}
}

在这里您可以找到在线版本(请记住,该问题仅与 IOS 相关): https://snack.expo.io/SJB7ipm6B

一些图片:

enter image description here

enter image description here

enter image description here

感谢您的时间和帮助!

最佳答案

尝试一下这个。模式关闭后,我将重新渲染 InputAccessoryView

{(!this.state.modalVisible) && <InputAccessoryView backgroundColor="#ff9900">
<TextInput
style={{
padding: 20,
paddingTop: 50,
}}
onChangeText={text => this.setState({text})}
value={this.state.text}
/>
</InputAccessoryView>}

关于ios - React Native IOS InputAccessoryView 关闭模态后从屏幕上消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59156706/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com