@shoutem/ui 6.1.0-beta.1 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,6 +20,7 @@ const config = {
20
20
  'shoutem-info': props => <InfoToast {...props} />,
21
21
  'shoutem-action': props => <ActionToast {...props} />,
22
22
  };
23
+ const toastQueue = [];
23
24
 
24
25
  function normalizeProps(type, props) {
25
26
  const nativeProps = _.pick(props, NATIVE_PROPS_MAP);
@@ -27,20 +28,83 @@ function normalizeProps(type, props) {
27
28
  return {
28
29
  type,
29
30
  ...nativeProps,
31
+ onHide: () => {
32
+ if (nativeProps.onHide) {
33
+ nativeProps.onHide();
34
+ }
35
+
36
+ handleQueuedToastFinish(props.id);
37
+ },
30
38
  props,
31
39
  };
32
40
  }
33
41
 
42
+ // Underlying library doesn't support stacking multiple
43
+ // toasts, so we queue them instead
44
+ const queueToast = (toast, id) => {
45
+ if (_.isEmpty(toastQueue)) {
46
+ toast();
47
+ }
48
+
49
+ toastQueue.push({
50
+ id,
51
+ toast,
52
+ });
53
+ };
54
+
55
+ const handleQueuedToastFinish = toastId => {
56
+ _.remove(toastQueue, toastConfig => toastConfig.id === toastId);
57
+
58
+ if (!_.isEmpty(toastQueue)) {
59
+ // Start the next toast with a bit of a delay to allow
60
+ // the hide transition to finish
61
+ _.delay(() => _.head(toastQueue).toast(), 300);
62
+ }
63
+ };
64
+
34
65
  export const Provider = () => <Toast config={config} />;
35
66
 
36
- const showAction = props => Toast.show(normalizeProps('shoutem-action', props));
67
+ const showAction = props => {
68
+ const id = _.uniqueId();
69
+
70
+ queueToast(
71
+ () => Toast.show(normalizeProps('shoutem-action', { ...props, id })),
72
+ id,
73
+ );
74
+ };
75
+
76
+ const showInfo = props => {
77
+ const id = _.uniqueId();
78
+
79
+ queueToast(
80
+ () => Toast.show(normalizeProps('shoutem-info', { ...props, id })),
81
+ id,
82
+ );
83
+ };
37
84
 
38
- const showInfo = props => Toast.show(normalizeProps('shoutem-info', props));
85
+ const showSuccess = props => {
86
+ const id = _.uniqueId();
87
+
88
+ queueToast(
89
+ () => Toast.show(normalizeProps('shoutem-success', { ...props, id })),
90
+ id,
91
+ );
92
+ };
39
93
 
40
- const showSuccess = props =>
41
- Toast.show(normalizeProps('shoutem-success', props));
94
+ const showError = props => {
95
+ const id = _.uniqueId();
42
96
 
43
- const showError = props => Toast.show(normalizeProps('shoutem-error', props));
97
+ queueToast(
98
+ () => Toast.show(normalizeProps('shoutem-error', { ...props, id })),
99
+ id,
100
+ );
101
+ };
102
+
103
+ const showDefault = props => {
104
+ const id = _.uniqueId();
105
+
106
+ queueToast(() => Toast.show({ ...props, id }), id);
107
+ };
44
108
 
45
109
  export default {
46
110
  Provider,
@@ -48,7 +112,7 @@ export default {
48
112
  showError,
49
113
  showSuccess,
50
114
  showInfo,
51
- show: Toast.show,
115
+ show: showDefault,
52
116
  hide: Toast.hide,
53
117
  defaultConfig: config,
54
118
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shoutem/ui",
3
- "version": "6.1.0-beta.1",
3
+ "version": "6.1.0",
4
4
  "description": "Styleable set of components for React Native applications",
5
5
  "scripts": {
6
6
  "lint": "eslint .",