@terreno/ui 0.0.17 → 0.0.18
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/dist/TerrenoProvider.js +1 -1
- package/dist/TerrenoProvider.js.map +1 -1
- package/dist/Toast.js +2 -3
- package/dist/Toast.js.map +1 -1
- package/dist/ToastNotifications.d.ts +144 -0
- package/dist/ToastNotifications.js +387 -0
- package/dist/ToastNotifications.js.map +1 -0
- package/dist/UserInactivity.js +2 -2
- package/dist/UserInactivity.js.map +1 -1
- package/package.json +1 -2
- package/src/TerrenoProvider.tsx +1 -1
- package/src/Toast.tsx +2 -3
- package/src/ToastNotifications.test.tsx +645 -0
- package/src/ToastNotifications.tsx +746 -0
- package/src/UserInactivity.tsx +2 -2
package/dist/TerrenoProvider.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Host } from "react-native-portalize";
|
|
3
|
-
import { ToastProvider } from "react-native-toast-notifications";
|
|
4
3
|
import { OpenAPIProvider } from "./OpenAPIContext";
|
|
5
4
|
import { ThemeProvider } from "./Theme";
|
|
6
5
|
import { Toast } from "./Toast";
|
|
6
|
+
import { ToastProvider } from "./ToastNotifications";
|
|
7
7
|
export const TerrenoProvider = ({ children, openAPISpecUrl }) => {
|
|
8
8
|
return (_jsx(ThemeProvider, { children: _jsx(ToastProvider, { animationDuration: 250, animationType: "slide-in", duration: 50000, offset: 50, placement: "bottom", renderToast: (toastOptions) => _jsx(Toast, Object.assign({}, toastOptions === null || toastOptions === void 0 ? void 0 : toastOptions.data)), swipeEnabled: true, children: _jsx(OpenAPIProvider, { specUrl: openAPISpecUrl, children: _jsx(Host, { children: children }) }) }) }));
|
|
9
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TerrenoProvider.js","sourceRoot":"","sources":["../src/TerrenoProvider.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAC,IAAI,EAAC,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"TerrenoProvider.js","sourceRoot":"","sources":["../src/TerrenoProvider.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAC,IAAI,EAAC,MAAM,wBAAwB,CAAC;AAE5C,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AACtC,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AAEnD,MAAM,CAAC,MAAM,eAAe,GAGvB,CAAC,EAAC,QAAQ,EAAE,cAAc,EAAC,EAAE,EAAE;IAClC,OAAO,CACL,KAAC,aAAa,cACZ,KAAC,aAAa,IACZ,iBAAiB,EAAE,GAAG,EACtB,aAAa,EAAC,UAAU,EACxB,QAAQ,EAAE,KAAK,EACf,MAAM,EAAE,EAAE,EACV,SAAS,EAAC,QAAQ,EAClB,WAAW,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,KAAC,KAAK,oBAAK,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,IAAI,EAAI,EAChE,YAAY,kBAEZ,KAAC,eAAe,IAAC,OAAO,EAAE,cAAc,YACtC,KAAC,IAAI,cAAE,QAAQ,GAAQ,GACP,GACJ,GACF,CACjB,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/Toast.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Platform, Pressable, View } from "react-native";
|
|
3
|
-
import { useToast as useRNToast } from "react-native-toast-notifications";
|
|
4
3
|
import { Heading } from "./Heading";
|
|
5
4
|
import { Icon } from "./Icon";
|
|
6
5
|
import { Text } from "./Text";
|
|
7
6
|
import { useTheme } from "./Theme";
|
|
7
|
+
import { useToastNotifications } from "./ToastNotifications";
|
|
8
8
|
import { isAPIError, printAPIError } from "./Utilities";
|
|
9
9
|
const TOAST_DURATION_MS = 3 * 1000;
|
|
10
10
|
export function useToast() {
|
|
11
|
-
const toast =
|
|
11
|
+
const toast = useToastNotifications();
|
|
12
12
|
const show = (title, options) => {
|
|
13
13
|
const toastData = Object.assign(Object.assign({ variant: "info" }, options), { title });
|
|
14
14
|
return toast.show(title, {
|
|
@@ -54,7 +54,6 @@ export function useToast() {
|
|
|
54
54
|
}
|
|
55
55
|
// TODO: Support secondary version of Toast.
|
|
56
56
|
// TODO: Support dismissible version of Toast. Currently only persistent are dismissible.
|
|
57
|
-
// This may require a different library from react-native-toast-notifications.
|
|
58
57
|
export const Toast = ({ title, variant = "info", secondary, size = "sm", onDismiss, persistent,
|
|
59
58
|
// TODO enforce these should only show if size is "lg" with type discrinimation
|
|
60
59
|
subtitle, }) => {
|
package/dist/Toast.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.js","sourceRoot":"","sources":["../src/Toast.tsx"],"names":[],"mappings":";AACA,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"Toast.js","sourceRoot":"","sources":["../src/Toast.tsx"],"names":[],"mappings":";AACA,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AAGvD,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AACjC,OAAO,EAAC,qBAAqB,EAAC,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AAEtD,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,C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,CAAC,IAAI,CACnC,KAAC,SAAS,iBACE,QAAQ,EAClB,OAAO,EAAE,SAAS,EAClB,KAAK,EAAE;wBACL,UAAU,EAAE,QAAQ;wBACpB,SAAS,EAAE,QAAQ;wBACnB,OAAO,EAAE,MAAM;wBACf,GAAG,EAAE,EAAE;wBACP,UAAU,EAAE,EAAE;wBACd,OAAO,EAAE,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;qBAC/B,YAED,KAAC,IAAI,IAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAC,OAAO,GAAG,GACjC,CACb,IACI,GACF,CACR,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendored from react-native-toast-notifications v3.4.0
|
|
3
|
+
* https://github.com/arnnis/react-native-toast-notifications
|
|
4
|
+
*
|
|
5
|
+
* MIT License
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2020 Alireza Rezania
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
* in the Software without restriction, including without limitation the rights
|
|
12
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
* furnished to do so, subject to the following conditions:
|
|
15
|
+
*
|
|
16
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
* copies or substantial portions of the Software.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
* SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
import React, { type FC, type ReactElement } from "react";
|
|
28
|
+
import { type StyleProp, type TextStyle, type ViewStyle } from "react-native";
|
|
29
|
+
export interface ToastOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Id is optional, you may provide an id only if you want to update toast later using toast.update()
|
|
32
|
+
*/
|
|
33
|
+
id?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Customize toast icon
|
|
36
|
+
*/
|
|
37
|
+
icon?: ReactElement;
|
|
38
|
+
/**
|
|
39
|
+
* Toast types, You can implement your custom types with JSX using renderType method on ToastContainer.
|
|
40
|
+
*/
|
|
41
|
+
type?: "normal" | "success" | "danger" | "warning" | string;
|
|
42
|
+
/**
|
|
43
|
+
* In ms, How long toast will stay before it go away
|
|
44
|
+
*/
|
|
45
|
+
duration?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Customize when toast should be placed
|
|
48
|
+
*/
|
|
49
|
+
placement?: "top" | "bottom" | "center";
|
|
50
|
+
/**
|
|
51
|
+
* Customize style of toast
|
|
52
|
+
*/
|
|
53
|
+
style?: StyleProp<ViewStyle>;
|
|
54
|
+
/**
|
|
55
|
+
* Customize style of toast text
|
|
56
|
+
*/
|
|
57
|
+
textStyle?: StyleProp<TextStyle>;
|
|
58
|
+
/**
|
|
59
|
+
* Customize how fast toast will show and hide
|
|
60
|
+
*/
|
|
61
|
+
animationDuration?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Customize how toast is animated when added or removed
|
|
64
|
+
*/
|
|
65
|
+
animationType?: "slide-in" | "zoom-in";
|
|
66
|
+
/**
|
|
67
|
+
* Customize success type icon
|
|
68
|
+
*/
|
|
69
|
+
successIcon?: ReactElement;
|
|
70
|
+
/**
|
|
71
|
+
* Customize danger type icon
|
|
72
|
+
*/
|
|
73
|
+
dangerIcon?: ReactElement;
|
|
74
|
+
/**
|
|
75
|
+
* Customize warning type icon
|
|
76
|
+
*/
|
|
77
|
+
warningIcon?: ReactElement;
|
|
78
|
+
/**
|
|
79
|
+
* Customize success type color. changes toast background color
|
|
80
|
+
*/
|
|
81
|
+
successColor?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Customize danger type color. changes toast background color
|
|
84
|
+
*/
|
|
85
|
+
dangerColor?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Customize warning type color. changes toast background color
|
|
88
|
+
*/
|
|
89
|
+
warningColor?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Customize normal type color. changes toast background color
|
|
92
|
+
*/
|
|
93
|
+
normalColor?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Register event for when toast is pressed. If you're using a custom toast you have to pass this to a Touchable.
|
|
96
|
+
*/
|
|
97
|
+
onPress?(id: string): void;
|
|
98
|
+
/**
|
|
99
|
+
* Execute event after toast is closed
|
|
100
|
+
*/
|
|
101
|
+
onClose?(): void;
|
|
102
|
+
/**
|
|
103
|
+
* Payload data for custom toasts. You can pass whatever you want
|
|
104
|
+
*/
|
|
105
|
+
data?: any;
|
|
106
|
+
swipeEnabled?: boolean;
|
|
107
|
+
}
|
|
108
|
+
export interface ToastProps extends ToastOptions {
|
|
109
|
+
id: string;
|
|
110
|
+
onDestroy(): void;
|
|
111
|
+
message: string | ReactElement;
|
|
112
|
+
open: boolean;
|
|
113
|
+
renderToast?(toast: ToastProps): ReactElement;
|
|
114
|
+
renderType?: {
|
|
115
|
+
[type: string]: (toast: ToastProps) => ReactElement;
|
|
116
|
+
};
|
|
117
|
+
onHide(): void;
|
|
118
|
+
}
|
|
119
|
+
export interface ToastContainerProps extends ToastOptions {
|
|
120
|
+
renderToast?(toast: ToastProps): ReactElement;
|
|
121
|
+
renderType?: {
|
|
122
|
+
[type: string]: (toast: ToastProps) => ReactElement;
|
|
123
|
+
};
|
|
124
|
+
offset?: number;
|
|
125
|
+
offsetTop?: number;
|
|
126
|
+
offsetBottom?: number;
|
|
127
|
+
swipeEnabled?: boolean;
|
|
128
|
+
}
|
|
129
|
+
export interface ToastContainerRef {
|
|
130
|
+
show: (message: string | ReactElement, toastOptions?: ToastOptions) => string;
|
|
131
|
+
update: (id: string, message: string | ReactElement, toastOptions?: ToastOptions) => void;
|
|
132
|
+
hide: (id: string) => void;
|
|
133
|
+
hideAll: () => void;
|
|
134
|
+
isOpen: (id: string) => boolean;
|
|
135
|
+
}
|
|
136
|
+
declare const ToastContainer: React.ForwardRefExoticComponent<ToastContainerProps & React.RefAttributes<ToastContainerRef>>;
|
|
137
|
+
export type ToastType = ToastContainerRef;
|
|
138
|
+
export declare let GlobalToast: ToastType;
|
|
139
|
+
type ToastProviderProps = ToastContainerProps & {
|
|
140
|
+
children: React.ReactNode;
|
|
141
|
+
};
|
|
142
|
+
export declare const ToastProvider: FC<ToastProviderProps>;
|
|
143
|
+
export declare const useToastNotifications: () => ToastType;
|
|
144
|
+
export default ToastContainer;
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
/**
|
|
14
|
+
* Vendored from react-native-toast-notifications v3.4.0
|
|
15
|
+
* https://github.com/arnnis/react-native-toast-notifications
|
|
16
|
+
*
|
|
17
|
+
* MIT License
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) 2020 Alireza Rezania
|
|
20
|
+
*
|
|
21
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
23
|
+
* in the Software without restriction, including without limitation the rights
|
|
24
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
26
|
+
* furnished to do so, subject to the following conditions:
|
|
27
|
+
*
|
|
28
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
29
|
+
* copies or substantial portions of the Software.
|
|
30
|
+
*
|
|
31
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
+
* SOFTWARE.
|
|
38
|
+
*/
|
|
39
|
+
import React, { createContext, forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState, } from "react";
|
|
40
|
+
import { Animated, Dimensions, KeyboardAvoidingView, PanResponder, Platform, SafeAreaView, StyleSheet, Text, TouchableWithoutFeedback, View, } from "react-native";
|
|
41
|
+
// ============================================================================
|
|
42
|
+
// useDimensions hook
|
|
43
|
+
// ============================================================================
|
|
44
|
+
function useDimensions() {
|
|
45
|
+
const [dimensions, setDimensions] = useState(Dimensions.get("window"));
|
|
46
|
+
const onChange = useCallback(({ window }) => {
|
|
47
|
+
setDimensions(window);
|
|
48
|
+
}, []);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const subscription = Dimensions.addEventListener("change", onChange);
|
|
51
|
+
return () => {
|
|
52
|
+
subscription.remove();
|
|
53
|
+
};
|
|
54
|
+
}, [onChange]);
|
|
55
|
+
return dimensions;
|
|
56
|
+
}
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// Toast Component
|
|
59
|
+
// ============================================================================
|
|
60
|
+
const ToastItem = (props) => {
|
|
61
|
+
var _a;
|
|
62
|
+
let { id, onDestroy, icon, type = "normal", message, duration = 5000, style, textStyle, animationDuration = 250, animationType = "slide-in", successIcon, dangerIcon, warningIcon, successColor, dangerColor, warningColor, normalColor, placement, swipeEnabled, onPress, } = props;
|
|
63
|
+
const containerRef = useRef(null);
|
|
64
|
+
const [animation] = useState(new Animated.Value(0));
|
|
65
|
+
const panResponderRef = useRef(undefined);
|
|
66
|
+
const panResponderAnimRef = useRef(undefined);
|
|
67
|
+
const closeTimeoutRef = useRef(null);
|
|
68
|
+
const dims = useDimensions();
|
|
69
|
+
const handleClose = useCallback(() => {
|
|
70
|
+
Animated.timing(animation, {
|
|
71
|
+
duration: animationDuration,
|
|
72
|
+
toValue: 0,
|
|
73
|
+
useNativeDriver: Platform.OS !== "web",
|
|
74
|
+
}).start(() => onDestroy());
|
|
75
|
+
}, [animation, animationDuration, onDestroy]);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
Animated.timing(animation, {
|
|
78
|
+
duration: animationDuration,
|
|
79
|
+
toValue: 1,
|
|
80
|
+
useNativeDriver: Platform.OS !== "web",
|
|
81
|
+
}).start();
|
|
82
|
+
if (duration !== 0 && typeof duration === "number") {
|
|
83
|
+
closeTimeoutRef.current = setTimeout(() => {
|
|
84
|
+
handleClose();
|
|
85
|
+
}, duration);
|
|
86
|
+
}
|
|
87
|
+
return () => {
|
|
88
|
+
closeTimeoutRef.current && clearTimeout(closeTimeoutRef.current);
|
|
89
|
+
};
|
|
90
|
+
}, [duration, animation, animationDuration, handleClose]);
|
|
91
|
+
// Handles hide & hideAll
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (!props.open) {
|
|
94
|
+
// Unregister close timeout
|
|
95
|
+
closeTimeoutRef.current && clearTimeout(closeTimeoutRef.current);
|
|
96
|
+
// Close animation them remove from stack.
|
|
97
|
+
handleClose();
|
|
98
|
+
}
|
|
99
|
+
}, [
|
|
100
|
+
props.open, // Close animation them remove from stack.
|
|
101
|
+
handleClose,
|
|
102
|
+
]);
|
|
103
|
+
const panReleaseToLeft = (gestureState) => {
|
|
104
|
+
Animated.timing(getPanResponderAnim(), {
|
|
105
|
+
duration: 250,
|
|
106
|
+
toValue: { x: (-dims.width / 10) * 9, y: gestureState.dy },
|
|
107
|
+
useNativeDriver: Platform.OS !== "web",
|
|
108
|
+
}).start(() => onDestroy());
|
|
109
|
+
};
|
|
110
|
+
const panReleaseToRight = (gestureState) => {
|
|
111
|
+
Animated.timing(getPanResponderAnim(), {
|
|
112
|
+
duration: 250,
|
|
113
|
+
toValue: { x: (dims.width / 10) * 9, y: gestureState.dy },
|
|
114
|
+
useNativeDriver: Platform.OS !== "web",
|
|
115
|
+
}).start(() => onDestroy());
|
|
116
|
+
};
|
|
117
|
+
const getPanResponder = () => {
|
|
118
|
+
if (panResponderRef.current)
|
|
119
|
+
return panResponderRef.current;
|
|
120
|
+
const swipeThreshold = Platform.OS === "android" ? 10 : 0;
|
|
121
|
+
panResponderRef.current = PanResponder.create({
|
|
122
|
+
onMoveShouldSetPanResponder: (_, gestureState) => {
|
|
123
|
+
//return true if user is swiping, return false if it's a single click
|
|
124
|
+
return (Math.abs(gestureState.dx) > swipeThreshold || Math.abs(gestureState.dy) > swipeThreshold);
|
|
125
|
+
},
|
|
126
|
+
onPanResponderMove: (_, gestureState) => {
|
|
127
|
+
var _a;
|
|
128
|
+
(_a = getPanResponderAnim()) === null || _a === void 0 ? void 0 : _a.setValue({
|
|
129
|
+
x: gestureState.dx,
|
|
130
|
+
y: gestureState.dy,
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
onPanResponderRelease: (_, gestureState) => {
|
|
134
|
+
if (gestureState.dx > 50) {
|
|
135
|
+
panReleaseToRight(gestureState);
|
|
136
|
+
}
|
|
137
|
+
else if (gestureState.dx < -50) {
|
|
138
|
+
panReleaseToLeft(gestureState);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
Animated.spring(getPanResponderAnim(), {
|
|
142
|
+
toValue: { x: 0, y: 0 },
|
|
143
|
+
useNativeDriver: Platform.OS !== "web",
|
|
144
|
+
}).start();
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
return panResponderRef.current;
|
|
149
|
+
};
|
|
150
|
+
const getPanResponderAnim = () => {
|
|
151
|
+
if (panResponderAnimRef.current)
|
|
152
|
+
return panResponderAnimRef.current;
|
|
153
|
+
panResponderAnimRef.current = new Animated.ValueXY({ x: 0, y: 0 });
|
|
154
|
+
return panResponderAnimRef.current;
|
|
155
|
+
};
|
|
156
|
+
if (icon === undefined) {
|
|
157
|
+
switch (type) {
|
|
158
|
+
case "success": {
|
|
159
|
+
if (successIcon) {
|
|
160
|
+
icon = successIcon;
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case "danger": {
|
|
165
|
+
if (dangerIcon) {
|
|
166
|
+
icon = dangerIcon;
|
|
167
|
+
}
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
case "warning": {
|
|
171
|
+
if (warningIcon) {
|
|
172
|
+
icon = warningIcon;
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
let backgroundColor = "";
|
|
179
|
+
switch (type) {
|
|
180
|
+
case "success":
|
|
181
|
+
backgroundColor = successColor || "rgb(46, 125, 50)";
|
|
182
|
+
break;
|
|
183
|
+
case "danger":
|
|
184
|
+
backgroundColor = dangerColor || "rgb(211, 47, 47)";
|
|
185
|
+
break;
|
|
186
|
+
case "warning":
|
|
187
|
+
backgroundColor = warningColor || "rgb(237, 108, 2)";
|
|
188
|
+
break;
|
|
189
|
+
default:
|
|
190
|
+
backgroundColor = normalColor || "#333";
|
|
191
|
+
}
|
|
192
|
+
const baseTransform = [
|
|
193
|
+
{
|
|
194
|
+
translateY: animation.interpolate({
|
|
195
|
+
inputRange: [0, 1],
|
|
196
|
+
outputRange: placement === "bottom" ? [20, 0] : [-20, 0],
|
|
197
|
+
}),
|
|
198
|
+
},
|
|
199
|
+
];
|
|
200
|
+
if (swipeEnabled) {
|
|
201
|
+
const panTransform = getPanResponderAnim().getTranslateTransform()[0];
|
|
202
|
+
baseTransform.push(panTransform);
|
|
203
|
+
}
|
|
204
|
+
if (animationType === "zoom-in") {
|
|
205
|
+
baseTransform.push({
|
|
206
|
+
scale: animation.interpolate({
|
|
207
|
+
inputRange: [0, 1],
|
|
208
|
+
outputRange: [0.7, 1],
|
|
209
|
+
}),
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
const animationStyle = {
|
|
213
|
+
opacity: animation,
|
|
214
|
+
transform: baseTransform,
|
|
215
|
+
};
|
|
216
|
+
return (_jsx(Animated.View, Object.assign({ pointerEvents: "box-none", ref: containerRef }, (swipeEnabled ? getPanResponder().panHandlers : null), { style: [toastStyles.container, animationStyle], children: ((_a = props.renderType) === null || _a === void 0 ? void 0 : _a[type]) ? (props.renderType[type](props)) : props.renderToast ? (props.renderToast(props)) : (_jsx(TouchableWithoutFeedback, { disabled: !onPress, onPress: () => onPress === null || onPress === void 0 ? void 0 : onPress(id), children: _jsxs(View, { style: [
|
|
217
|
+
toastStyles.toastContainer,
|
|
218
|
+
{ backgroundColor, maxWidth: (dims.width / 10) * 9 },
|
|
219
|
+
style,
|
|
220
|
+
], children: [icon ? _jsx(View, { style: toastStyles.iconContainer, children: icon }) : null, React.isValidElement(message) ? (message) : (_jsx(Text, { style: [toastStyles.message, textStyle], children: message }))] }) })) })));
|
|
221
|
+
};
|
|
222
|
+
const toastStyles = StyleSheet.create({
|
|
223
|
+
container: { alignItems: "center", width: "100%" },
|
|
224
|
+
iconContainer: {
|
|
225
|
+
marginRight: 5,
|
|
226
|
+
},
|
|
227
|
+
message: {
|
|
228
|
+
color: "#fff",
|
|
229
|
+
fontWeight: "500",
|
|
230
|
+
},
|
|
231
|
+
toastContainer: {
|
|
232
|
+
alignItems: "center",
|
|
233
|
+
borderRadius: 5,
|
|
234
|
+
flexDirection: "row",
|
|
235
|
+
marginVertical: 5,
|
|
236
|
+
overflow: "hidden",
|
|
237
|
+
paddingHorizontal: 12,
|
|
238
|
+
paddingVertical: 12,
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
// ============================================================================
|
|
242
|
+
// Toast Container
|
|
243
|
+
// ============================================================================
|
|
244
|
+
const { height, width } = Dimensions.get("window");
|
|
245
|
+
const ToastContainer = forwardRef((props, ref) => {
|
|
246
|
+
const { offset = 10, offsetTop, offsetBottom, placement = "bottom", swipeEnabled = true, renderToast, renderType, duration, type, style, textStyle, animationDuration, animationType, successIcon, dangerIcon, warningIcon, successColor, dangerColor, warningColor, normalColor, onPress, data, } = props;
|
|
247
|
+
const toastDefaults = useMemo(() => ({
|
|
248
|
+
animationDuration,
|
|
249
|
+
animationType,
|
|
250
|
+
dangerColor,
|
|
251
|
+
dangerIcon,
|
|
252
|
+
data,
|
|
253
|
+
duration,
|
|
254
|
+
normalColor,
|
|
255
|
+
onPress,
|
|
256
|
+
renderToast,
|
|
257
|
+
renderType,
|
|
258
|
+
style,
|
|
259
|
+
successColor,
|
|
260
|
+
successIcon,
|
|
261
|
+
textStyle,
|
|
262
|
+
type,
|
|
263
|
+
warningColor,
|
|
264
|
+
warningIcon,
|
|
265
|
+
}), [
|
|
266
|
+
renderToast,
|
|
267
|
+
renderType,
|
|
268
|
+
duration,
|
|
269
|
+
type,
|
|
270
|
+
style,
|
|
271
|
+
textStyle,
|
|
272
|
+
animationDuration,
|
|
273
|
+
animationType,
|
|
274
|
+
successIcon,
|
|
275
|
+
dangerIcon,
|
|
276
|
+
warningIcon,
|
|
277
|
+
successColor,
|
|
278
|
+
dangerColor,
|
|
279
|
+
warningColor,
|
|
280
|
+
normalColor,
|
|
281
|
+
onPress,
|
|
282
|
+
data,
|
|
283
|
+
]);
|
|
284
|
+
const [toasts, setToasts] = useState([]);
|
|
285
|
+
const hide = useCallback((id) => {
|
|
286
|
+
setToasts((prev) => prev.map((t) => (t.id === id ? Object.assign(Object.assign({}, t), { open: false }) : t)));
|
|
287
|
+
}, []);
|
|
288
|
+
const show = useCallback((message, toastOptions) => {
|
|
289
|
+
const id = (toastOptions === null || toastOptions === void 0 ? void 0 : toastOptions.id) || Math.random().toString();
|
|
290
|
+
const onDestroy = () => {
|
|
291
|
+
var _a;
|
|
292
|
+
(_a = toastOptions === null || toastOptions === void 0 ? void 0 : toastOptions.onClose) === null || _a === void 0 ? void 0 : _a.call(toastOptions);
|
|
293
|
+
setToasts((prev) => prev.filter((t) => t.id !== id));
|
|
294
|
+
};
|
|
295
|
+
requestAnimationFrame(() => {
|
|
296
|
+
setToasts((prev) => [
|
|
297
|
+
Object.assign(Object.assign({ id,
|
|
298
|
+
message,
|
|
299
|
+
onDestroy, onHide: () => hide(id), open: true, placement,
|
|
300
|
+
swipeEnabled }, toastDefaults), toastOptions),
|
|
301
|
+
...prev.filter((t) => t.open),
|
|
302
|
+
]);
|
|
303
|
+
});
|
|
304
|
+
return id;
|
|
305
|
+
}, [hide, placement, swipeEnabled, toastDefaults]);
|
|
306
|
+
const update = useCallback((id, message, toastOptions) => {
|
|
307
|
+
setToasts((prev) => prev.map((toast) => (toast.id === id ? Object.assign(Object.assign(Object.assign({}, toast), { message }), toastOptions) : toast)));
|
|
308
|
+
}, []);
|
|
309
|
+
const hideAll = useCallback(() => {
|
|
310
|
+
setToasts((prev) => prev.map((t) => (Object.assign(Object.assign({}, t), { open: false }))));
|
|
311
|
+
}, []);
|
|
312
|
+
const isOpen = useCallback((id) => {
|
|
313
|
+
return toasts.some((t) => t.id === id && t.open);
|
|
314
|
+
}, [toasts]);
|
|
315
|
+
useImperativeHandle(ref, () => ({
|
|
316
|
+
hide,
|
|
317
|
+
hideAll,
|
|
318
|
+
isOpen,
|
|
319
|
+
show,
|
|
320
|
+
update,
|
|
321
|
+
}), [show, update, hide, hideAll, isOpen]);
|
|
322
|
+
const renderBottomToasts = useCallback(() => {
|
|
323
|
+
const style = {
|
|
324
|
+
bottom: offsetBottom || offset,
|
|
325
|
+
flexDirection: "column",
|
|
326
|
+
justifyContent: "flex-end",
|
|
327
|
+
width: width,
|
|
328
|
+
};
|
|
329
|
+
return (_jsx(KeyboardAvoidingView, { behavior: Platform.OS === "ios" ? "position" : undefined, pointerEvents: "box-none", style: [containerStyles.container, style], children: _jsx(SafeAreaView, { children: toasts
|
|
330
|
+
.filter((t) => !t.placement || t.placement === "bottom")
|
|
331
|
+
.map((toast) => (_jsx(ToastItem, Object.assign({}, toast), toast.id))) }) }));
|
|
332
|
+
}, [toasts, offset, offsetBottom]);
|
|
333
|
+
const renderTopToasts = useCallback(() => {
|
|
334
|
+
const style = {
|
|
335
|
+
flexDirection: "column-reverse",
|
|
336
|
+
justifyContent: "flex-start",
|
|
337
|
+
top: offsetTop || offset,
|
|
338
|
+
width: width,
|
|
339
|
+
};
|
|
340
|
+
return (_jsx(KeyboardAvoidingView, { behavior: Platform.OS === "ios" ? "position" : undefined, pointerEvents: "box-none", style: [containerStyles.container, style], children: _jsx(SafeAreaView, { children: toasts
|
|
341
|
+
.filter((t) => t.placement === "top")
|
|
342
|
+
.map((toast) => (_jsx(ToastItem, Object.assign({}, toast), toast.id))) }) }));
|
|
343
|
+
}, [toasts, offset, offsetTop]);
|
|
344
|
+
const renderCenterToasts = useCallback(() => {
|
|
345
|
+
const style = {
|
|
346
|
+
flexDirection: "column-reverse",
|
|
347
|
+
height: height,
|
|
348
|
+
justifyContent: "center",
|
|
349
|
+
top: offsetTop || offset,
|
|
350
|
+
width: width,
|
|
351
|
+
};
|
|
352
|
+
const data = toasts.filter((t) => t.placement === "center");
|
|
353
|
+
const foundToast = data.length > 0;
|
|
354
|
+
if (!foundToast)
|
|
355
|
+
return null;
|
|
356
|
+
return (_jsx(KeyboardAvoidingView, { behavior: Platform.OS === "ios" ? "position" : undefined, pointerEvents: "box-none", style: [containerStyles.container, style], children: toasts
|
|
357
|
+
.filter((t) => t.placement === "center")
|
|
358
|
+
.map((toast) => (_jsx(ToastItem, Object.assign({}, toast), toast.id))) }));
|
|
359
|
+
}, [toasts, offset, offsetTop]);
|
|
360
|
+
return (_jsxs(_Fragment, { children: [renderTopToasts(), renderBottomToasts(), renderCenterToasts()] }));
|
|
361
|
+
});
|
|
362
|
+
ToastContainer.displayName = "ToastContainer";
|
|
363
|
+
const containerStyles = StyleSheet.create({
|
|
364
|
+
container: Object.assign({ alignSelf: "center", elevation: 999999, flex: 0, maxWidth: "100%",
|
|
365
|
+
// @ts-expect-error: fixed is available on web.
|
|
366
|
+
position: Platform.OS === "web" ? "fixed" : "absolute", zIndex: 999999 }, (Platform.OS === "web" ? { overflow: "hidden", userSelect: "none" } : null)),
|
|
367
|
+
message: {
|
|
368
|
+
color: "#333",
|
|
369
|
+
},
|
|
370
|
+
});
|
|
371
|
+
const ToastContext = createContext({});
|
|
372
|
+
export let GlobalToast;
|
|
373
|
+
export const ToastProvider = (_a) => {
|
|
374
|
+
var { children } = _a, props = __rest(_a, ["children"]);
|
|
375
|
+
const toastRef = useRef(null);
|
|
376
|
+
const [refState, setRefState] = useState({});
|
|
377
|
+
useEffect(() => {
|
|
378
|
+
if (toastRef.current) {
|
|
379
|
+
setRefState(toastRef.current);
|
|
380
|
+
GlobalToast = toastRef.current;
|
|
381
|
+
}
|
|
382
|
+
}, []);
|
|
383
|
+
return (_jsxs(ToastContext.Provider, { value: refState, children: [children, _jsx(ToastContainer, Object.assign({ ref: toastRef }, props))] }));
|
|
384
|
+
};
|
|
385
|
+
export const useToastNotifications = () => useContext(ToastContext);
|
|
386
|
+
export default ToastContainer;
|
|
387
|
+
//# sourceMappingURL=ToastNotifications.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToastNotifications.js","sourceRoot":"","sources":["../src/ToastNotifications.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,EACZ,aAAa,EAEb,UAAU,EAEV,WAAW,EACX,UAAU,EACV,SAAS,EACT,mBAAmB,EACnB,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EACL,QAAQ,EACR,UAAU,EACV,oBAAoB,EACpB,YAAY,EAGZ,QAAQ,EACR,YAAY,EAGZ,UAAU,EACV,IAAI,EAEJ,wBAAwB,EACxB,IAAI,GAEL,MAAM,cAAc,CAAC;AAEtB,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E,SAAS,aAAa;IACpB,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEvE,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,EAAC,MAAM,EAAuB,EAAE,EAAE;QAC9D,aAAa,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,YAAY,GAAG,UAAU,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAErE,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,MAAM,EAAE,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,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AAY,EAAe,CAAC,CAAC;IAErE,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;YACrB,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC9B,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC;QACjC,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,MAAC,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,QAAQ,aACnC,QAAQ,EACT,KAAC,cAAc,kBAAC,GAAG,EAAE,QAAQ,IAAM,KAAK,EAAI,IACtB,CACzB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAc,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;AAE/E,eAAe,cAAc,CAAC"}
|
package/dist/UserInactivity.js
CHANGED
|
@@ -34,7 +34,7 @@ export const UserInactivity = ({ children, isActive: isActiveProp, onAction, ski
|
|
|
34
34
|
const actualStyle = style !== null && style !== void 0 ? style : DEFAULT_STYLE;
|
|
35
35
|
const initialActive = isActiveProp === undefined ? true : isActiveProp;
|
|
36
36
|
const [active, setActive] = useState(initialActive);
|
|
37
|
-
const [
|
|
37
|
+
const [_resetKey, setResetKey] = useState(0);
|
|
38
38
|
const timeoutRef = useRef(null);
|
|
39
39
|
const isFirstRender = useRef(true);
|
|
40
40
|
const clearTimer = useCallback(() => {
|
|
@@ -61,7 +61,7 @@ export const UserInactivity = ({ children, isActive: isActiveProp, onAction, ski
|
|
|
61
61
|
onAction(false);
|
|
62
62
|
}, timeForInactivity);
|
|
63
63
|
return clearTimer;
|
|
64
|
-
}, [
|
|
64
|
+
}, [timeForInactivity, onAction, clearTimer]);
|
|
65
65
|
// Trigger onAction when active state changes (except on first render)
|
|
66
66
|
useEffect(() => {
|
|
67
67
|
if (isFirstRender.current) {
|