繁体   English   中英

当键盘以模态打开时,实际 android 设备中的模态关闭

[英]Modal closes in real android devices when Keyboard open in modal

当我单击列表的最后一个按钮或与屏幕底部对齐的按钮并专注于 TextInput 时,Modal 会自动关闭而不会出现任何错误。 这只发生在 android 真实设备上。 iOS 或 Android 模拟器上不会出现此问题。

import React, {useState} from 'react';
import {
  FlatList,
  TouchableOpacity,
  Button,
  Modal,
  TextInput,
} from 'react-native';

const data = [
  0,
  1,
  2,
  3,
  4,
  5,
  6,
  7,
  8,
  9,
  0,
  1,
  2,
  3,
  4,
  5,
  6,
  7,
  8,
  9,
  0,
  1,
  2,
  3,
  4,
  5,
  6,
  7,
  8,
  9,
];

const Item = () => {
  const [state, setState] = useState(false);
  return (
    <>
      <TouchableOpacity style={{marginTop: 10}}>
        <Button title="Open" onPress={() => setState(true)} />
      </TouchableOpacity>
      <Modal visible={state}>
        <TextInput placeholder="Type" />
        <Button title="Close" onPress={() => setState(false)} />
      </Modal>
    </>
  );
};

const App = () => {
  return <FlatList data={data} renderItem={() => <Item />} />;
};

export default App;

将模式移到平面列表之外。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM