@tamagui/toast 2.7.7 → 3.0.0-beta.643.1
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/cjs/ToastComposable.cjs +773 -882
- package/dist/cjs/ToastComposable.native.cjs +924 -0
- package/dist/cjs/ToastComposable.native.js +854 -966
- package/dist/cjs/ToastComposable.native.js.map +1 -1
- package/dist/cjs/ToastItemFrame.cjs +48 -119
- package/dist/cjs/ToastItemFrame.native.cjs +76 -0
- package/dist/cjs/ToastItemFrame.native.js +50 -120
- package/dist/cjs/ToastItemFrame.native.js.map +1 -1
- package/dist/cjs/ToastState.cjs +281 -290
- package/dist/cjs/ToastState.native.cjs +312 -0
- package/dist/cjs/ToastState.native.js +280 -290
- package/dist/cjs/ToastState.native.js.map +1 -1
- package/dist/cjs/createNativeToast.cjs +38 -44
- package/dist/cjs/createNativeToast.native.cjs +54 -0
- package/dist/cjs/createNativeToast.native.js +36 -40
- package/dist/cjs/createNativeToast.native.js.map +1 -1
- package/dist/cjs/dispatchNativeToast.cjs +32 -35
- package/dist/cjs/dispatchNativeToast.native.cjs +48 -0
- package/dist/cjs/dispatchNativeToast.native.js +34 -36
- package/dist/cjs/dispatchNativeToast.native.js.map +1 -1
- package/dist/cjs/index.cjs +25 -12
- package/dist/cjs/index.native.cjs +35 -0
- package/dist/cjs/index.native.js +26 -12
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/types.cjs +10 -11
- package/dist/cjs/types.native.cjs +19 -0
- package/dist/cjs/types.native.js +10 -10
- package/dist/cjs/types.native.js.map +1 -1
- package/dist/cjs/useAnimatedDragGesture.cjs +197 -194
- package/dist/cjs/useAnimatedDragGesture.native.cjs +210 -0
- package/dist/cjs/useAnimatedDragGesture.native.js +179 -191
- package/dist/cjs/useAnimatedDragGesture.native.js.map +1 -1
- package/dist/cjs/useReducedMotion.cjs +47 -55
- package/dist/cjs/useReducedMotion.native.cjs +74 -0
- package/dist/cjs/useReducedMotion.native.js +53 -60
- package/dist/cjs/useReducedMotion.native.js.map +1 -1
- package/dist/cjs/useToastAnimations.cjs +198 -270
- package/dist/cjs/useToastAnimations.native.cjs +229 -0
- package/dist/cjs/useToastAnimations.native.js +205 -276
- package/dist/cjs/useToastAnimations.native.js.map +1 -1
- package/dist/esm/ToastComposable.mjs +752 -854
- package/dist/esm/ToastComposable.mjs.map +1 -1
- package/dist/esm/ToastComposable.native.js +834 -940
- package/dist/esm/ToastComposable.native.js.map +1 -1
- package/dist/esm/ToastItemFrame.mjs +31 -99
- package/dist/esm/ToastItemFrame.mjs.map +1 -1
- package/dist/esm/ToastItemFrame.native.js +34 -102
- package/dist/esm/ToastItemFrame.native.js.map +1 -1
- package/dist/esm/ToastState.mjs +266 -273
- package/dist/esm/ToastState.mjs.map +1 -1
- package/dist/esm/ToastState.native.js +265 -274
- package/dist/esm/ToastState.native.js.map +1 -1
- package/dist/esm/createNativeToast.mjs +22 -26
- package/dist/esm/createNativeToast.mjs.map +1 -1
- package/dist/esm/createNativeToast.native.js +21 -23
- package/dist/esm/createNativeToast.native.js.map +1 -1
- package/dist/esm/dispatchNativeToast.mjs +19 -17
- package/dist/esm/dispatchNativeToast.mjs.map +1 -1
- package/dist/esm/dispatchNativeToast.native.js +21 -19
- package/dist/esm/dispatchNativeToast.native.js.map +1 -1
- package/dist/esm/index.js +5 -2
- package/dist/esm/index.mjs +5 -2
- package/dist/esm/index.native.js +5 -2
- package/dist/esm/types.mjs +0 -2
- package/dist/esm/types.native.js +0 -2
- package/dist/esm/useAnimatedDragGesture.mjs +181 -168
- package/dist/esm/useAnimatedDragGesture.mjs.map +1 -1
- package/dist/esm/useAnimatedDragGesture.native.js +163 -166
- package/dist/esm/useAnimatedDragGesture.native.js.map +1 -1
- package/dist/esm/useReducedMotion.mjs +31 -29
- package/dist/esm/useReducedMotion.mjs.map +1 -1
- package/dist/esm/useReducedMotion.native.js +37 -35
- package/dist/esm/useReducedMotion.native.js.map +1 -1
- package/dist/esm/useToastAnimations.mjs +183 -245
- package/dist/esm/useToastAnimations.mjs.map +1 -1
- package/dist/esm/useToastAnimations.native.js +190 -252
- package/dist/esm/useToastAnimations.native.js.map +1 -1
- package/dist/jsx/ToastComposable.mjs +752 -854
- package/dist/jsx/ToastComposable.mjs.map +1 -1
- package/dist/jsx/ToastComposable.native.cjs +924 -0
- package/dist/jsx/ToastComposable.native.js +854 -966
- package/dist/jsx/ToastComposable.native.js.map +1 -1
- package/dist/jsx/ToastItemFrame.mjs +31 -99
- package/dist/jsx/ToastItemFrame.mjs.map +1 -1
- package/dist/jsx/ToastItemFrame.native.cjs +76 -0
- package/dist/jsx/ToastItemFrame.native.js +50 -120
- package/dist/jsx/ToastItemFrame.native.js.map +1 -1
- package/dist/jsx/ToastState.mjs +266 -273
- package/dist/jsx/ToastState.mjs.map +1 -1
- package/dist/jsx/ToastState.native.cjs +312 -0
- package/dist/jsx/ToastState.native.js +280 -290
- package/dist/jsx/ToastState.native.js.map +1 -1
- package/dist/jsx/createNativeToast.mjs +22 -26
- package/dist/jsx/createNativeToast.mjs.map +1 -1
- package/dist/jsx/createNativeToast.native.cjs +54 -0
- package/dist/jsx/createNativeToast.native.js +36 -40
- package/dist/jsx/createNativeToast.native.js.map +1 -1
- package/dist/jsx/dispatchNativeToast.mjs +19 -17
- package/dist/jsx/dispatchNativeToast.mjs.map +1 -1
- package/dist/jsx/dispatchNativeToast.native.cjs +48 -0
- package/dist/jsx/dispatchNativeToast.native.js +34 -36
- package/dist/jsx/dispatchNativeToast.native.js.map +1 -1
- package/dist/jsx/index.js +5 -2
- package/dist/jsx/index.mjs +5 -2
- package/dist/jsx/index.native.cjs +35 -0
- package/dist/jsx/index.native.js +26 -12
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/types.mjs +0 -2
- package/dist/jsx/types.native.cjs +19 -0
- package/dist/jsx/types.native.js +10 -10
- package/dist/jsx/types.native.js.map +1 -1
- package/dist/jsx/useAnimatedDragGesture.mjs +181 -168
- package/dist/jsx/useAnimatedDragGesture.mjs.map +1 -1
- package/dist/jsx/useAnimatedDragGesture.native.cjs +210 -0
- package/dist/jsx/useAnimatedDragGesture.native.js +179 -191
- package/dist/jsx/useAnimatedDragGesture.native.js.map +1 -1
- package/dist/jsx/useReducedMotion.mjs +31 -29
- package/dist/jsx/useReducedMotion.mjs.map +1 -1
- package/dist/jsx/useReducedMotion.native.cjs +74 -0
- package/dist/jsx/useReducedMotion.native.js +53 -60
- package/dist/jsx/useReducedMotion.native.js.map +1 -1
- package/dist/jsx/useToastAnimations.mjs +183 -245
- package/dist/jsx/useToastAnimations.mjs.map +1 -1
- package/dist/jsx/useToastAnimations.native.cjs +229 -0
- package/dist/jsx/useToastAnimations.native.js +205 -276
- package/dist/jsx/useToastAnimations.native.js.map +1 -1
- package/package.json +20 -37
- package/src/ToastComposable.tsx +55 -97
- package/src/ToastItemFrame.tsx +22 -81
- package/src/ToastState.ts +1 -0
- package/src/index.ts +34 -2
- package/src/types.ts +11 -0
- package/src/useAnimatedDragGesture.native.ts +1 -1
- package/src/useAnimatedDragGesture.ts +1 -1
- package/src/useToastAnimations.ts +20 -36
- package/types/ToastComposable.d.ts +124 -47
- package/types/ToastComposable.d.ts.map +1 -1
- package/types/ToastItemFrame.d.ts +52 -21
- package/types/ToastItemFrame.d.ts.map +1 -1
- package/types/ToastState.d.ts +15 -11
- package/types/ToastState.d.ts.map +1 -1
- package/types/index.d.ts +6 -2
- package/types/index.d.ts.map +1 -1
- package/types/types.d.ts +1 -0
- package/types/types.d.ts.map +1 -1
- package/types/useAnimatedDragGesture.d.ts +1 -1
- package/types/useAnimatedDragGesture.d.ts.map +1 -1
- package/types/useAnimatedDragGesture.native.d.ts +1 -1
- package/types/useAnimatedDragGesture.native.d.ts.map +1 -1
- package/types/useToastAnimations.d.ts +2 -8
- package/types/useToastAnimations.d.ts.map +1 -1
- package/dist/cjs/Toast.cjs +0 -178
- package/dist/cjs/Toast.native.js +0 -181
- package/dist/cjs/Toast.native.js.map +0 -1
- package/dist/cjs/ToastAnnounce.cjs +0 -103
- package/dist/cjs/ToastAnnounce.native.js +0 -111
- package/dist/cjs/ToastAnnounce.native.js.map +0 -1
- package/dist/cjs/ToastImperative.cjs +0 -119
- package/dist/cjs/ToastImperative.native.js +0 -130
- package/dist/cjs/ToastImperative.native.js.map +0 -1
- package/dist/cjs/ToastImpl.cjs +0 -354
- package/dist/cjs/ToastImpl.native.js +0 -364
- package/dist/cjs/ToastImpl.native.js.map +0 -1
- package/dist/cjs/ToastPortal.cjs +0 -49
- package/dist/cjs/ToastPortal.native.js +0 -52
- package/dist/cjs/ToastPortal.native.js.map +0 -1
- package/dist/cjs/ToastProvider.cjs +0 -150
- package/dist/cjs/ToastProvider.native.js +0 -161
- package/dist/cjs/ToastProvider.native.js.map +0 -1
- package/dist/cjs/ToastViewport.cjs +0 -319
- package/dist/cjs/ToastViewport.native.js +0 -343
- package/dist/cjs/ToastViewport.native.js.map +0 -1
- package/dist/cjs/Toaster.cjs +0 -87
- package/dist/cjs/Toaster.native.js +0 -91
- package/dist/cjs/Toaster.native.js.map +0 -1
- package/dist/cjs/constants.cjs +0 -30
- package/dist/cjs/constants.native.js +0 -33
- package/dist/cjs/constants.native.js.map +0 -1
- package/dist/cjs/v2.cjs +0 -36
- package/dist/cjs/v2.native.js +0 -39
- package/dist/cjs/v2.native.js.map +0 -1
- package/dist/esm/Toast.mjs +0 -137
- package/dist/esm/Toast.mjs.map +0 -1
- package/dist/esm/Toast.native.js +0 -137
- package/dist/esm/Toast.native.js.map +0 -1
- package/dist/esm/ToastAnnounce.mjs +0 -66
- package/dist/esm/ToastAnnounce.mjs.map +0 -1
- package/dist/esm/ToastAnnounce.native.js +0 -71
- package/dist/esm/ToastAnnounce.native.js.map +0 -1
- package/dist/esm/ToastImperative.mjs +0 -80
- package/dist/esm/ToastImperative.mjs.map +0 -1
- package/dist/esm/ToastImperative.native.js +0 -88
- package/dist/esm/ToastImperative.native.js.map +0 -1
- package/dist/esm/ToastImpl.mjs +0 -316
- package/dist/esm/ToastImpl.mjs.map +0 -1
- package/dist/esm/ToastImpl.native.js +0 -329
- package/dist/esm/ToastImpl.native.js.map +0 -1
- package/dist/esm/ToastPortal.mjs +0 -24
- package/dist/esm/ToastPortal.mjs.map +0 -1
- package/dist/esm/ToastPortal.native.js +0 -24
- package/dist/esm/ToastPortal.native.js.map +0 -1
- package/dist/esm/ToastProvider.mjs +0 -110
- package/dist/esm/ToastProvider.mjs.map +0 -1
- package/dist/esm/ToastProvider.native.js +0 -118
- package/dist/esm/ToastProvider.native.js.map +0 -1
- package/dist/esm/ToastViewport.mjs +0 -280
- package/dist/esm/ToastViewport.mjs.map +0 -1
- package/dist/esm/ToastViewport.native.js +0 -301
- package/dist/esm/ToastViewport.native.js.map +0 -1
- package/dist/esm/Toaster.mjs +0 -51
- package/dist/esm/Toaster.mjs.map +0 -1
- package/dist/esm/Toaster.native.js +0 -52
- package/dist/esm/Toaster.native.js.map +0 -1
- package/dist/esm/constants.mjs +0 -4
- package/dist/esm/constants.mjs.map +0 -1
- package/dist/esm/constants.native.js +0 -4
- package/dist/esm/constants.native.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/esm/types.mjs.map +0 -1
- package/dist/esm/types.native.js.map +0 -1
- package/dist/esm/v2.mjs +0 -6
- package/dist/esm/v2.mjs.map +0 -1
- package/dist/esm/v2.native.js +0 -6
- package/dist/esm/v2.native.js.map +0 -1
- package/dist/jsx/Toast.mjs +0 -137
- package/dist/jsx/Toast.mjs.map +0 -1
- package/dist/jsx/Toast.native.js +0 -181
- package/dist/jsx/Toast.native.js.map +0 -1
- package/dist/jsx/ToastAnnounce.mjs +0 -66
- package/dist/jsx/ToastAnnounce.mjs.map +0 -1
- package/dist/jsx/ToastAnnounce.native.js +0 -111
- package/dist/jsx/ToastAnnounce.native.js.map +0 -1
- package/dist/jsx/ToastImperative.mjs +0 -80
- package/dist/jsx/ToastImperative.mjs.map +0 -1
- package/dist/jsx/ToastImperative.native.js +0 -130
- package/dist/jsx/ToastImperative.native.js.map +0 -1
- package/dist/jsx/ToastImpl.mjs +0 -316
- package/dist/jsx/ToastImpl.mjs.map +0 -1
- package/dist/jsx/ToastImpl.native.js +0 -364
- package/dist/jsx/ToastImpl.native.js.map +0 -1
- package/dist/jsx/ToastPortal.mjs +0 -24
- package/dist/jsx/ToastPortal.mjs.map +0 -1
- package/dist/jsx/ToastPortal.native.js +0 -52
- package/dist/jsx/ToastPortal.native.js.map +0 -1
- package/dist/jsx/ToastProvider.mjs +0 -110
- package/dist/jsx/ToastProvider.mjs.map +0 -1
- package/dist/jsx/ToastProvider.native.js +0 -161
- package/dist/jsx/ToastProvider.native.js.map +0 -1
- package/dist/jsx/ToastViewport.mjs +0 -280
- package/dist/jsx/ToastViewport.mjs.map +0 -1
- package/dist/jsx/ToastViewport.native.js +0 -343
- package/dist/jsx/ToastViewport.native.js.map +0 -1
- package/dist/jsx/Toaster.mjs +0 -51
- package/dist/jsx/Toaster.mjs.map +0 -1
- package/dist/jsx/Toaster.native.js +0 -91
- package/dist/jsx/Toaster.native.js.map +0 -1
- package/dist/jsx/constants.mjs +0 -4
- package/dist/jsx/constants.mjs.map +0 -1
- package/dist/jsx/constants.native.js +0 -33
- package/dist/jsx/constants.native.js.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
- package/dist/jsx/types.mjs.map +0 -1
- package/dist/jsx/v2.mjs +0 -6
- package/dist/jsx/v2.mjs.map +0 -1
- package/dist/jsx/v2.native.js +0 -39
- package/dist/jsx/v2.native.js.map +0 -1
- package/src/Toast.tsx +0 -219
- package/src/ToastAnnounce.tsx +0 -103
- package/src/ToastImperative.tsx +0 -192
- package/src/ToastImpl.tsx +0 -514
- package/src/ToastPortal.tsx +0 -19
- package/src/ToastProvider.tsx +0 -204
- package/src/ToastViewport.tsx +0 -430
- package/src/Toaster.tsx +0 -181
- package/src/constants.ts +0 -2
- package/src/v2.ts +0 -31
- package/types/Toast.d.ts +0 -84
- package/types/Toast.d.ts.map +0 -1
- package/types/ToastAnnounce.d.ts +0 -18
- package/types/ToastAnnounce.d.ts.map +0 -1
- package/types/ToastImperative.d.ts +0 -95
- package/types/ToastImperative.d.ts.map +0 -1
- package/types/ToastImpl.d.ts +0 -109
- package/types/ToastImpl.d.ts.map +0 -1
- package/types/ToastPortal.d.ts +0 -8
- package/types/ToastPortal.d.ts.map +0 -1
- package/types/ToastProvider.d.ts +0 -92
- package/types/ToastProvider.d.ts.map +0 -1
- package/types/ToastViewport.d.ts +0 -75
- package/types/ToastViewport.d.ts.map +0 -1
- package/types/Toaster.d.ts +0 -112
- package/types/Toaster.d.ts.map +0 -1
- package/types/constants.d.ts +0 -3
- package/types/constants.d.ts.map +0 -1
- package/types/v2.d.ts +0 -10
- package/types/v2.d.ts.map +0 -1
- package/v2/index.cjs +0 -2
- package/v2/index.js +0 -2
- package/v2/index.native.cjs +0 -2
- package/v2/index.native.js +0 -2
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var useToastAnimations_exports = {};
|
|
31
|
+
__export(useToastAnimations_exports, { useToastAnimations: () => useToastAnimations });
|
|
32
|
+
module.exports = __toCommonJS(useToastAnimations_exports);
|
|
33
|
+
var import_constants = require("@tamagui/constants");
|
|
34
|
+
var import_core = require("@tamagui/core");
|
|
35
|
+
var React = __toESM(require("react"), 1);
|
|
36
|
+
var SPRING_CONFIG = {
|
|
37
|
+
type: "spring",
|
|
38
|
+
damping: 30,
|
|
39
|
+
stiffness: 400,
|
|
40
|
+
mass: .5
|
|
41
|
+
};
|
|
42
|
+
var EXIT_DISTANCE = 200;
|
|
43
|
+
function animateSpring(element, fromX, fromY, toX, toY, config, onComplete) {
|
|
44
|
+
var { damping = 30, stiffness = 400, mass = .5, initialVelocityX = 0, initialVelocityY = 0, fadeOut = false } = config;
|
|
45
|
+
var x = fromX;
|
|
46
|
+
var y = fromY;
|
|
47
|
+
var velocityX = initialVelocityX;
|
|
48
|
+
var velocityY = initialVelocityY;
|
|
49
|
+
var animationId = null;
|
|
50
|
+
var targetX = toX;
|
|
51
|
+
var targetY = toY;
|
|
52
|
+
var totalDistance = Math.sqrt(Math.pow(toX - fromX, 2) + Math.pow(toY - fromY, 2)) || 1;
|
|
53
|
+
function step() {
|
|
54
|
+
var forceX = -stiffness * (x - targetX);
|
|
55
|
+
var forceY = -stiffness * (y - targetY);
|
|
56
|
+
var dampingForceX = -damping * velocityX;
|
|
57
|
+
var dampingForceY = -damping * velocityY;
|
|
58
|
+
var accelerationX = (forceX + dampingForceX) / mass;
|
|
59
|
+
var accelerationY = (forceY + dampingForceY) / mass;
|
|
60
|
+
velocityX += accelerationX * .016;
|
|
61
|
+
velocityY += accelerationY * .016;
|
|
62
|
+
x += velocityX * .016;
|
|
63
|
+
y += velocityY * .016;
|
|
64
|
+
element.style.transform = `translate3d(${x}px, ${y}px, 0)`;
|
|
65
|
+
if (fadeOut) {
|
|
66
|
+
var distanceTraveled = Math.sqrt(Math.pow(x - fromX, 2) + Math.pow(y - fromY, 2));
|
|
67
|
+
var progress = Math.min(distanceTraveled / totalDistance, 1);
|
|
68
|
+
element.style.opacity = String(1 - progress);
|
|
69
|
+
}
|
|
70
|
+
var distanceX = Math.abs(x - targetX);
|
|
71
|
+
var distanceY = Math.abs(y - targetY);
|
|
72
|
+
var speed = Math.sqrt(velocityX * velocityX + velocityY * velocityY);
|
|
73
|
+
if (distanceX < .5 && distanceY < .5 && speed < .5) {
|
|
74
|
+
element.style.transform = `translate3d(${targetX}px, ${targetY}px, 0)`;
|
|
75
|
+
if (fadeOut) {
|
|
76
|
+
element.style.opacity = "0";
|
|
77
|
+
}
|
|
78
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
animationId = requestAnimationFrame(step);
|
|
82
|
+
}
|
|
83
|
+
animationId = requestAnimationFrame(step);
|
|
84
|
+
return function() {
|
|
85
|
+
if (animationId) {
|
|
86
|
+
cancelAnimationFrame(animationId);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function useToastAnimations() {
|
|
91
|
+
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
92
|
+
var { onExitComplete, reducedMotion } = options;
|
|
93
|
+
var animationDriver = (0, import_core.useAnimationDriver)();
|
|
94
|
+
var _animationDriver_View;
|
|
95
|
+
var AnimatedView = (_animationDriver_View = animationDriver.View) !== null && _animationDriver_View !== void 0 ? _animationDriver_View : import_core.View;
|
|
96
|
+
var dragRef = React.useRef(null);
|
|
97
|
+
var cancelAnimationRef = React.useRef(null);
|
|
98
|
+
var currentOffsetRef = React.useRef({
|
|
99
|
+
x: 0,
|
|
100
|
+
y: 0
|
|
101
|
+
});
|
|
102
|
+
var useDirectDom = import_constants.isWeb;
|
|
103
|
+
var translateX = (0, import_core.useAnimatedNumber)(0);
|
|
104
|
+
var translateY = (0, import_core.useAnimatedNumber)(0);
|
|
105
|
+
var animatedStyle = (0, import_core.useAnimatedNumbersStyle)([translateX, translateY], function(x, y) {
|
|
106
|
+
"worklet";
|
|
107
|
+
return { transform: [{ translateX: x }, { translateY: y }] };
|
|
108
|
+
});
|
|
109
|
+
var setDragOffset = (0, import_core.useEvent)(function(x, y) {
|
|
110
|
+
var _cancelAnimationRef_current;
|
|
111
|
+
(_cancelAnimationRef_current = cancelAnimationRef.current) === null || _cancelAnimationRef_current === void 0 ? void 0 : _cancelAnimationRef_current.call(cancelAnimationRef);
|
|
112
|
+
cancelAnimationRef.current = null;
|
|
113
|
+
currentOffsetRef.current = {
|
|
114
|
+
x,
|
|
115
|
+
y
|
|
116
|
+
};
|
|
117
|
+
if (useDirectDom && dragRef.current) {
|
|
118
|
+
dragRef.current.style.transform = `translate3d(${x}px, ${y}px, 0)`;
|
|
119
|
+
dragRef.current.style.opacity = "1";
|
|
120
|
+
} else {
|
|
121
|
+
translateX.setValue(x, { type: "direct" });
|
|
122
|
+
translateY.setValue(y, { type: "direct" });
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
var springBack = (0, import_core.useEvent)(function(onComplete) {
|
|
126
|
+
var _cancelAnimationRef_current;
|
|
127
|
+
(_cancelAnimationRef_current = cancelAnimationRef.current) === null || _cancelAnimationRef_current === void 0 ? void 0 : _cancelAnimationRef_current.call(cancelAnimationRef);
|
|
128
|
+
if (reducedMotion) {
|
|
129
|
+
if (useDirectDom && dragRef.current) {
|
|
130
|
+
dragRef.current.style.transform = "translate3d(0px, 0px, 0)";
|
|
131
|
+
} else {
|
|
132
|
+
translateX.setValue(0, { type: "direct" });
|
|
133
|
+
translateY.setValue(0, { type: "direct" });
|
|
134
|
+
}
|
|
135
|
+
currentOffsetRef.current = {
|
|
136
|
+
x: 0,
|
|
137
|
+
y: 0
|
|
138
|
+
};
|
|
139
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (useDirectDom && dragRef.current) {
|
|
143
|
+
var { x, y } = currentOffsetRef.current;
|
|
144
|
+
cancelAnimationRef.current = animateSpring(dragRef.current, x, y, 0, 0, SPRING_CONFIG, function() {
|
|
145
|
+
currentOffsetRef.current = {
|
|
146
|
+
x: 0,
|
|
147
|
+
y: 0
|
|
148
|
+
};
|
|
149
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete();
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
translateX.setValue(0, SPRING_CONFIG);
|
|
153
|
+
translateY.setValue(0, SPRING_CONFIG, onComplete);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
var animateOut = (0, import_core.useEvent)(function(direction, velocity, onComplete) {
|
|
157
|
+
var _cancelAnimationRef_current;
|
|
158
|
+
(_cancelAnimationRef_current = cancelAnimationRef.current) === null || _cancelAnimationRef_current === void 0 ? void 0 : _cancelAnimationRef_current.call(cancelAnimationRef);
|
|
159
|
+
var { x: curX, y: curY } = currentOffsetRef.current;
|
|
160
|
+
var exitX = direction === "left" ? -EXIT_DISTANCE : direction === "right" ? EXIT_DISTANCE : 0;
|
|
161
|
+
var exitY = direction === "up" ? -EXIT_DISTANCE : direction === "down" ? EXIT_DISTANCE : 0;
|
|
162
|
+
if (direction === "left" && curX < exitX) exitX = curX - 50;
|
|
163
|
+
else if (direction === "right" && curX > exitX) exitX = curX + 50;
|
|
164
|
+
if (direction === "up" && curY < exitY) exitY = curY - 50;
|
|
165
|
+
else if (direction === "down" && curY > exitY) exitY = curY + 50;
|
|
166
|
+
if (reducedMotion) {
|
|
167
|
+
if (useDirectDom && dragRef.current) {
|
|
168
|
+
dragRef.current.style.transform = `translate3d(${exitX}px, ${exitY}px, 0)`;
|
|
169
|
+
} else {
|
|
170
|
+
translateX.setValue(exitX, { type: "direct" });
|
|
171
|
+
translateY.setValue(exitY, { type: "direct" });
|
|
172
|
+
}
|
|
173
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete();
|
|
174
|
+
onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete();
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
var velocityScale = (velocity !== null && velocity !== void 0 ? velocity : 0) * 500;
|
|
178
|
+
var initialVelocityX = direction === "left" ? -velocityScale : direction === "right" ? velocityScale : 0;
|
|
179
|
+
var initialVelocityY = direction === "up" ? -velocityScale : direction === "down" ? velocityScale : 0;
|
|
180
|
+
var exitConfig = {
|
|
181
|
+
damping: 25,
|
|
182
|
+
stiffness: 350,
|
|
183
|
+
mass: .4,
|
|
184
|
+
initialVelocityX,
|
|
185
|
+
initialVelocityY,
|
|
186
|
+
fadeOut: true
|
|
187
|
+
};
|
|
188
|
+
if (useDirectDom && dragRef.current) {
|
|
189
|
+
var { x, y } = currentOffsetRef.current;
|
|
190
|
+
cancelAnimationRef.current = animateSpring(dragRef.current, x, y, exitX, exitY, exitConfig, function() {
|
|
191
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete();
|
|
192
|
+
onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete();
|
|
193
|
+
});
|
|
194
|
+
} else {
|
|
195
|
+
var springConfig = {
|
|
196
|
+
type: "spring",
|
|
197
|
+
damping: 25,
|
|
198
|
+
stiffness: 350,
|
|
199
|
+
mass: .4
|
|
200
|
+
};
|
|
201
|
+
translateX.setValue(exitX, springConfig);
|
|
202
|
+
translateY.setValue(exitY, springConfig, function() {
|
|
203
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete();
|
|
204
|
+
onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete();
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
var stop = (0, import_core.useEvent)(function() {
|
|
209
|
+
var _cancelAnimationRef_current;
|
|
210
|
+
(_cancelAnimationRef_current = cancelAnimationRef.current) === null || _cancelAnimationRef_current === void 0 ? void 0 : _cancelAnimationRef_current.call(cancelAnimationRef);
|
|
211
|
+
translateX.stop();
|
|
212
|
+
translateY.stop();
|
|
213
|
+
});
|
|
214
|
+
React.useEffect(function() {
|
|
215
|
+
return function() {
|
|
216
|
+
var _cancelAnimationRef_current;
|
|
217
|
+
(_cancelAnimationRef_current = cancelAnimationRef.current) === null || _cancelAnimationRef_current === void 0 ? void 0 : _cancelAnimationRef_current.call(cancelAnimationRef);
|
|
218
|
+
};
|
|
219
|
+
}, []);
|
|
220
|
+
return {
|
|
221
|
+
setDragOffset,
|
|
222
|
+
springBack,
|
|
223
|
+
animateOut,
|
|
224
|
+
stop,
|
|
225
|
+
animatedStyle,
|
|
226
|
+
AnimatedView,
|
|
227
|
+
dragRef
|
|
228
|
+
};
|
|
229
|
+
}
|