How to automatically close an alert after a certain time React Native

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-14 11:53:58

问题


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!


回答1:


I suggest you use Modal component

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



来源:https://stackoverflow.com/questions/42707264/how-to-automatically-close-an-alert-after-a-certain-time-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!