简体   繁体   English

模态在本机基础上无法正常工作

[英]modal not working correctly in native base

[![在此处输入图片描述](https://i.stack.imgur.com/S9zq0.png)](https://i.stack.imgur.com/S9zq0.png)

I want when i click the button, opening the modal.我想要当我点击按钮时,打开模态。 But modal is not opening correctly.但是模态没有正确打开。 And it is not readable.它不可读。

Here is in my modal code:这是我的模态代码:


  <Modal
                        isOpen={showModal}
                    >
                        <Modal.Content top="-60" maxWidth={400} height={300}>
                            <Modal.CloseButton />
                            <Modal.Header> bilgiler</Modal.Header>
                            <Modal.Body>
                                <Text>09.08.2001</Text>
                                {/* <Select
                                    minWidth="200"
                                    accessibilityLabel="Choose Service"
                                    placeholder="Son ölçüm tarihi seçiniz.."
                                    _selectedItem={{
                                        bg: "teal.600",
                                        endIcon: <CheckIcon size="5" />
                                    }} mt={1}
                                >

                                </Select>*/}
                                <Text>Adi ve soyadi</Text>
                            </Modal.Body>
                            <Modal.Footer>
                                <Button.Group space={2}>
                                    <Button variant="ghost" colorScheme="blueGray" onPress={() => setShowModal(false)} >
                                        Çıkış
                                    </Button>
                                    <Button onPress={() => setShowModal(false)} >
                                        Kaydet
                                    </Button>
                                </Button.Group>
                            </Modal.Footer>
                        </Modal.Content>
                    </Modal>

and pressable code:和可按下的代码:

<Box flex="1" >

                                        <Pressable left={290} top="-35" onPress={() => setShowModal(true)}>
                                            <Image size={7} source={require('../assets/clock.png')} />
                                        </Pressable>


                                    </Box>

I try to change pressable but it not working我尝试更改 pressable 但它不起作用

Try this试试这个

Create a component for Model to reuse or use can have it in screen itself.模型创建一个组件以供重用或使用,可以将其放在屏幕本身中。

Modal.js模态.js

 const Mdal = ({...props }) => { const { onInputChanged, showModal, onClose, header, inputTitle, ...p } = props; const [isOpen, setIsOpen] = useState(false); return ( <Modal isOpen={showModal} onClose={onClose} _backdrop={{ _dark: { bg: "coolGray.800", }, bg: "warmGray.50", }} > <Modal.Content borderWidth={2} width="500" maxWidth="93%" maxH="600"> <Modal.CloseButton /> <Modal.Header flexDirection="row">{header}</Modal.Header> <Modal.Body> <Text>Your View</Text> </Modal.Body> <Modal.Footer background={COLOR.card_action_bg}> <Button.Group space={2}> <Button colorScheme="warmGray" onPress={() => { onInputChanged("if any passing value"); }} > Save </Button> <Button colorScheme="red" onPress={() => { onClose(); }} > Cancel </Button> </Button.Group> </Modal.Footer> </Modal.Content> </Modal> ); }; export default Mdal;

In the screen where you want modal:在您想要模态的屏幕中:

 import { Model } from "the path if it is as component"
 
 const [showModal, setShowModal] = useState(false);

Place it inside your view将它放在你的视图中

<Modal onInputChanged={onInputChanged} showModal={showModal} onClose={() => setShowModal(false)} header={"(" + ticketId + ") - " + action} inputTitle={"Reason for transfer"} />
onInputChanged - is the function
 const onInputChanged = (changedText) => { //received selected value in changedText }

change the state of showModal to true on your pressable view(onPress) ->在可按下的视图(onPress)上将 showModal 的状态更改为 true ->

setShowModal(true);设置显示模态(真);

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

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