如何在一定时间后自动关闭警报React Native [英] How to automatically close an alert after a certain time React Native

查看:139
本文介绍了如何在一定时间后自动关闭警报React Native的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在几秒钟后自动关闭警报,而无需用户自己做。

I would like to automatically close an alert after a couple of seconds without having the user do it themselves.

如果可能的话,我想使用Alert(不是AlertIOS),但是如果只有AlertIOS的话,我想我别无选择。

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.

非常感谢!

推荐答案

我建议您使用模态组件

<Modal
  animationType={"slide"}
  transparent={false}
  visible={this.state.modalVisible}></Modal>

因此您可以在函数中调用setTimeout()来更新状态变量modalVisible以显示/隐藏它。在官方文档中可以找到更多示例( https://facebook.github。 io / react-native / docs / modal.html

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)

这篇关于如何在一定时间后自动关闭警报React Native的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆