forked from KBLNY/react-native-message-bar
-
Notifications
You must be signed in to change notification settings - Fork 27
/
MessageBarManager.js
72 lines (58 loc) · 1.8 KB
/
MessageBarManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Name: Message Bar Manager
* Description: A manager to show/hide and handle a queue of alerts
* https://github.com/Talor-A/react-native-message-bar
*/
'use strict'
module.exports = {
_currentMessageBarAlert: null,
_messageAlerts: [],
setCurrentMessageBarAlert (alert) {
console.warn(
'This method is deprecated, please use registerMessageBar instead.'
)
this.registerMessageBar(alert)
},
removeCurrentMessageBarAlert () {
console.warn(
'This method is deprecated, please use registerMessageBar instead.'
)
this.unregisterMessageBar()
},
registerMessageBar (messageBar) {
this._currentMessageBarAlert = messageBar
},
unregisterMessageBar () {
this._currentMessageBarAlert = null
},
showCurrentAlert (newState = null) {
console.warn('This method is deprecated, please use showAlert instead.')
this.showAlert(newState)
},
showAlert (newState = null) {
if (this._currentMessageBarAlert === null) {
return
}
// Hide the current alert
this.hideAlert()
// Get the current alert's duration to hide
var durationToHide = this._currentMessageBarAlert.alertShown ? this._currentMessageBarAlert.state.durationToHide : 0
setTimeout(() => {
// Show the new alert if there is a new state, otherwise
if (newState != null) {
// Clear current state
this._currentMessageBarAlert.setNewState({})
this._currentMessageBarAlert.setNewState(newState)
this._currentMessageBarAlert.notifyAlertHiddenCallback = null
setTimeout(() => {
this._currentMessageBarAlert.showMessageBarAlert()
}, 100)
}
}, durationToHide)
},
hideAlert () {
if (this._currentMessageBarAlert !== null) {
this._currentMessageBarAlert.hideMessageBarAlert()
}
}
}