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

Lev*_*_Up 5 ios inputaccessoryview react-native

当我的屏幕上的 InputAccessoryView 具有没有 nativeID 的组件(因此即使未显示键盘,它也会不断显示)并且我打开和关闭 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>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

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

一些图片:

在此输入图像描述

在此输入图像描述

在此输入图像描述

感谢您的时间和帮助!

Ash*_*sha 2

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

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