forked from GertlerDavidov/react-native-message-bar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MessageBarManager.js
83 lines (65 loc) · 1.86 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
75
76
77
78
79
80
81
82
83
/**
* Name: Message Bar Manager
* Description: A manager to show/hide and handle a queue of alerts
* https://github.com/KBLNY/react-native-message-bar
*/
"use strict";
module.exports = {
_currentMessageBarAlert: null,
_messageAlerts: new Array(),
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.state.durationToHide;
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();
}
},
init() {
this.showAlert({
message: '',
duration: 1,
position: 'bottom',
viewTopInset: 0,
viewBottomInset: 0,
durationToShow: 1,
durationToHide: 1
});
}
};