最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to automatically close an alert after a certain time React Native - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 5

I 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)

发布评论

评论列表(0)

  1. 暂无评论