0

I need to append a Modal to root element of a React-Native application which I didn't write. But I know there is a root element there. How can I do that?

ZygD
  • 22,092
  • 39
  • 79
  • 102
  • What do you mean precisely? You want to show a modal on a react-native app? Something like [this](https://dev.to/franciscomendes10866/how-to-create-a-modal-in-react-3coc)? – Giovanni Esposito Aug 26 '21 at 14:21
  • @GiovanniEsposito yes, I want to show a modal on a react-native app, but I can't import it to the main page of product. so I've decided to append it to the root element. is there any way to do that? I mean showing modal without using a component, but by appending it to main screen. – Danoosh Jooybar Aug 26 '21 at 14:27
  • 1
    I'm not an expert but I don't think you could do that... Let's wait, maybe there is someone that konws =) – Giovanni Esposito Aug 26 '21 at 14:29
  • 1
    sure =) lets wait for others :) – Danoosh Jooybar Aug 26 '21 at 14:31
  • 1
    is this not gonna do it? https://reactnative.dev/docs/modal – Isaac Aug 26 '21 at 14:41
  • Since you know where your root element is, just need to add the sample code from the doc, into your root element – Isaac Aug 26 '21 at 14:41
  • @Isaac I know there is a root, but I don't have its code. I'm writing a NPM package which needs to show a Modal. but I don't want users to insert my Modal component in their code, but instead I want them to call a function, and I do the rest for them. – Danoosh Jooybar Aug 26 '21 at 14:44
  • 1
    It's quite simple then, you just need install react-native-modal, and check the source code from `node_modules` – Isaac Aug 26 '21 at 14:48
  • @Isaac I'm a newbie, can you please give me a ref to see an example ? – Danoosh Jooybar Aug 26 '21 at 14:49
  • 1
    https://github.com/react-native-modal/react-native-modal take this as an example and this is the source code https://github.com/react-native-modal/react-native-modal/blob/master/src/modal.tsx – Isaac Aug 26 '21 at 14:53
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/236449/discussion-between-danoosh-jooybar-and-isaac). – Danoosh Jooybar Aug 26 '21 at 14:57

1 Answers1

0

It's quite simple then, you just need install react-native-modal, and check the source code from node_modules

http://github.com/react-native-modal/react-native-modal take this as an example and this is the source code https://github.com/react-native-modal/react-native-modal/blob/master/src/modal.tsx

this answer was made by https://stackoverflow.com/users/9816472/isaac in comments