问题
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