-
Notifications
You must be signed in to change notification settings - Fork 0
/
MessageBarManager.js
74 lines (60 loc) · 1.92 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
73
74
/**
* 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 || !this) {
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 && this._currentMessageBarAlert!== null) {
// Clear current state
this._currentMessageBarAlert.setNewState({})
this._currentMessageBarAlert.setNewState(newState)
this._currentMessageBarAlert.notifyAlertHiddenCallback = null
setTimeout(() => {
if (!!this && !!this._currentMessageBarAlert) {
this._currentMessageBarAlert.showMessageBarAlert()
}
}, 100)
}
}, durationToHide)
},
hideAlert () {
if (this._currentMessageBarAlert !== null) {
this._currentMessageBarAlert.hideMessageBarAlert()
}
}
}