forked from orhan/react-native-toast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
96 lines (75 loc) · 1.74 KB
/
index.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
84
85
86
87
88
89
90
91
92
93
94
95
96
'use strict';
var React = require('react');
import { NativeModules } from 'react-native';
var RCTToast= NativeModules.Toast;
var Toast = {};
var optionsBuilder = function () {
// defaults
var message = null;
var duration = "short";
var position = "center";
var addPixelsY = 0;
return {
withMessage: function(m) {
message = m;
return this;
},
withDuration: function(d) {
duration = d;
return this;
},
withPosition: function(p) {
position = p;
return this;
},
withAddPixelsY: function(y) {
addPixelsY = y;
return this;
},
build: function() {
return {
message: message,
duration: duration,
position: position,
addPixelsY: addPixelsY
}
}
}
};
var showWithOptions = function (options) {
RCTToast.show(options);
};
var showToast = function (message, duration, position) {
showWithOptions(
optionsBuilder()
.withMessage(message)
.withDuration(duration)
.withPosition(position)
.build()
);
};
Toast.showShortTop = function (message) {
showToast(message, "short", "top");
};
Toast.showShortCenter = function (message) {
showToast(message, "short", "center");
};
Toast.showShortBottom = function (message) {
showToast(message, "short", "bottom");
};
Toast.showLongTop = function (message) {
showToast(message, "long", "top");
};
Toast.showLongCenter = function (message) {
showToast(message, "long", "center");
};
Toast.showLongBottom = function (message) {
showToast(message, "long", "bottom");
};
Toast.show = function (message) {
showToast(message, "short", "bottom");
};
Toast.hide = function () {
RCTToast.hide();
};
module.exports = Toast;