I would like to automatically close an alert after a couple of seconds without having the user do it themselves.
If possible I would like to do this using Alert (not AlertIOS), but if only AlertIOS has it then I guess I have no other choice.
Thank you very much!
I would like to automatically close an alert after a couple of seconds without having the user do it themselves.
If possible I would like to do this using Alert (not AlertIOS), but if only AlertIOS has it then I guess I have no other choice.
Thank you very much!
Share Improve this question asked Mar 9, 2017 at 23:09 Luis RizoLuis Rizo 2,1094 gold badges17 silver badges34 bronze badges 3- 1 Have you considered using a modal? this would let you control it using a setTimeout() call once it is displayed... – fmacdee Commented Mar 9, 2017 at 23:16
- I have never used a modal, can you elaborate more please? – Luis Rizo Commented Mar 9, 2017 at 23:23
- Also, how do I even dismiss it myself? In the documentation there is no method to dismiss the alert using code. – Luis Rizo Commented Mar 9, 2017 at 23:23
1 Answer
Reset to default 5I suggest you use Modal ponent
<Modal
animationType={"slide"}
transparent={false}
visible={this.state.modalVisible}></Modal>
So you can call setTimeout() in your function to update the state variable modalVisible to show / hide it. More examples can be found here from the official doc (https://facebook.github.io/react-native/docs/modal.html)