react-native-toast-message 2.1.0-beta.1 → 2.1.0-beta.2
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.
- package/lib/src/Toast.d.ts +2 -4
- package/lib/src/Toast.js +26 -17
- package/lib/src/types/index.d.ts +26 -7
- package/package.json +1 -1
package/lib/src/Toast.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { ToastProps,
|
|
3
|
-
export declare function Toast(
|
|
2
|
+
import { ToastProps, ToastShowParams } from './types';
|
|
3
|
+
export declare function Toast({ nestingLevel, ...rest }: ToastProps): JSX.Element;
|
|
4
4
|
export declare namespace Toast {
|
|
5
|
-
var setRootRef: (ref: ToastRef) => void;
|
|
6
|
-
var setModalRef: (ref: ToastRef) => void;
|
|
7
5
|
var show: (params: ToastShowParams) => void;
|
|
8
6
|
var hide: (params?: void | undefined) => void;
|
|
9
7
|
}
|
package/lib/src/Toast.js
CHANGED
|
@@ -13,29 +13,38 @@ const ToastRoot = React.forwardRef((props, ref) => {
|
|
|
13
13
|
}));
|
|
14
14
|
return (<ToastUI isVisible={isVisible} options={options} data={data} hide={hide} show={show} config={config}/>);
|
|
15
15
|
});
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
const modalRef = {
|
|
20
|
-
current: null
|
|
21
|
-
};
|
|
22
|
-
export function Toast(props) {
|
|
23
|
-
const { setRef } = props;
|
|
16
|
+
const refs = [];
|
|
17
|
+
export function Toast({ nestingLevel = 0, ...rest }) {
|
|
24
18
|
return (<LoggerProvider enableLogs={false}>
|
|
25
|
-
<ToastRoot ref={
|
|
19
|
+
<ToastRoot ref={(ref) => {
|
|
20
|
+
refs[nestingLevel] = {
|
|
21
|
+
current: ref
|
|
22
|
+
};
|
|
23
|
+
}} {...rest}/>
|
|
26
24
|
</LoggerProvider>);
|
|
27
25
|
}
|
|
28
|
-
Toast.setRootRef = (ref) => {
|
|
29
|
-
rootRef.current = ref;
|
|
30
|
-
};
|
|
31
|
-
Toast.setModalRef = (ref) => {
|
|
32
|
-
modalRef.current = ref;
|
|
33
|
-
};
|
|
34
26
|
/**
|
|
35
|
-
* Get Toast instance ref
|
|
27
|
+
* Get the active Toast instance `ref`, by priority.
|
|
28
|
+
* The "highest" Toast in the `View` hierarchy has the highest priority.
|
|
29
|
+
*
|
|
30
|
+
* For example, a Toast inside a `Modal`, would have a higher priority than a Toast inside App's Root
|
|
31
|
+
* (which has a default `nestingLevel` of 0)
|
|
32
|
+
* ```js
|
|
33
|
+
* <>
|
|
34
|
+
* <Toast nestingLevel={0} />
|
|
35
|
+
* <Modal>
|
|
36
|
+
* <Toast nestingLevel={1} />
|
|
37
|
+
* </Modal>
|
|
38
|
+
* </>
|
|
39
|
+
* ```
|
|
36
40
|
*/
|
|
37
41
|
function getRef() {
|
|
38
|
-
|
|
42
|
+
const reversePriority = [...refs].reverse();
|
|
43
|
+
const activeRef = reversePriority.find((ref) => ref?.current !== null);
|
|
44
|
+
if (!activeRef) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return activeRef.current;
|
|
39
48
|
}
|
|
40
49
|
Toast.show = (params) => {
|
|
41
50
|
getRef()?.show(params);
|
package/lib/src/types/index.d.ts
CHANGED
|
@@ -111,20 +111,39 @@ export declare type ToastRef = {
|
|
|
111
111
|
*/
|
|
112
112
|
export declare type ToastProps = {
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
114
|
+
* Nesting level for the Toast instance.
|
|
115
|
+
* The "higher" a Toast instance is in the `View` hierarchy, the bigger its nesting level value.
|
|
116
|
+
* Default `nestingLevel = 0`.
|
|
117
|
+
*
|
|
118
|
+
* By setting this prop, you can show Toasts inside Modals, no matter how nested they would be.
|
|
119
|
+
*
|
|
120
|
+
* For example, a Toast inside a `Modal`, would have a bigger `nestingLevel`
|
|
121
|
+
* than a Toast inside App's Root (which has the default `nestingLevel` of 0).
|
|
116
122
|
*
|
|
117
123
|
* ```js
|
|
118
|
-
*
|
|
119
|
-
*
|
|
124
|
+
* <>
|
|
125
|
+
* <Toast />
|
|
126
|
+
* <Modal>
|
|
127
|
+
* <Toast nestingLevel={1} />
|
|
128
|
+
* </Modal>
|
|
129
|
+
* </>
|
|
120
130
|
* ```
|
|
121
131
|
*
|
|
132
|
+
* If you have nested Modals, the `nestingLevel` prop needs to be adjusted accordingly:
|
|
133
|
+
*
|
|
122
134
|
* ```js
|
|
123
|
-
*
|
|
124
|
-
*
|
|
135
|
+
* <>
|
|
136
|
+
* <Toast />
|
|
137
|
+
* <Modal>
|
|
138
|
+
* <Toast nestingLevel={1} />
|
|
139
|
+
* <Modal>
|
|
140
|
+
* <Toast nestingLevel={2} />
|
|
141
|
+
* </Modal>
|
|
142
|
+
* </Modal>
|
|
143
|
+
* </>
|
|
125
144
|
* ```
|
|
126
145
|
*/
|
|
127
|
-
|
|
146
|
+
nestingLevel?: number;
|
|
128
147
|
/**
|
|
129
148
|
* Layout configuration for custom Toast types
|
|
130
149
|
*/
|