@tamagui/animate-presence 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/AnimatePresence.cjs +102 -128
- package/dist/cjs/AnimatePresence.native.cjs +135 -0
- package/dist/cjs/AnimatePresence.native.js +112 -141
- package/dist/cjs/AnimatePresence.native.js.map +1 -1
- package/dist/cjs/LayoutGroupContext.cjs +18 -26
- package/dist/cjs/LayoutGroupContext.native.cjs +34 -0
- package/dist/cjs/LayoutGroupContext.native.js +19 -26
- package/dist/cjs/LayoutGroupContext.native.js.map +1 -1
- package/dist/cjs/PresenceChild.cjs +61 -81
- package/dist/cjs/PresenceChild.native.cjs +105 -0
- package/dist/cjs/PresenceChild.native.js +83 -104
- package/dist/cjs/PresenceChild.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +24 -0
- package/dist/cjs/index.native.js +10 -10
- 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/esm/AnimatePresence.mjs +90 -112
- package/dist/esm/AnimatePresence.mjs.map +1 -1
- package/dist/esm/AnimatePresence.native.js +100 -126
- package/dist/esm/AnimatePresence.native.js.map +1 -1
- package/dist/esm/LayoutGroupContext.mjs +2 -0
- package/dist/esm/LayoutGroupContext.mjs.map +1 -1
- package/dist/esm/LayoutGroupContext.native.js +3 -1
- package/dist/esm/LayoutGroupContext.native.js.map +1 -1
- package/dist/esm/PresenceChild.mjs +45 -55
- package/dist/esm/PresenceChild.mjs.map +1 -1
- package/dist/esm/PresenceChild.native.js +68 -80
- package/dist/esm/PresenceChild.native.js.map +1 -1
- package/dist/esm/index.js +7 -5
- package/dist/esm/index.mjs +7 -5
- package/dist/esm/index.native.js +7 -5
- package/dist/esm/types.mjs +0 -2
- package/dist/esm/types.native.js +0 -2
- package/package.json +8 -8
- package/src/AnimatePresence.tsx +3 -25
- package/src/PresenceChild.tsx +1 -10
- package/src/types.ts +0 -24
- package/types/AnimatePresence.d.ts.map +1 -1
- package/types/PresenceChild.d.ts +1 -4
- package/types/PresenceChild.d.ts.map +1 -1
- package/types/types.d.ts +0 -20
- package/types/types.d.ts.map +1 -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
|
@@ -1,29 +1,26 @@
|
|
|
1
|
+
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
6
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
10
11
|
};
|
|
11
12
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
19
20
|
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
22
|
var AnimatePresence_exports = {};
|
|
24
|
-
__export(AnimatePresence_exports, {
|
|
25
|
-
AnimatePresence: () => AnimatePresence
|
|
26
|
-
});
|
|
23
|
+
__export(AnimatePresence_exports, { AnimatePresence: () => AnimatePresence });
|
|
27
24
|
module.exports = __toCommonJS(AnimatePresence_exports);
|
|
28
25
|
var import_react = require("react");
|
|
29
26
|
var import_use_constant = require("@tamagui/use-constant");
|
|
@@ -32,118 +29,95 @@ var import_react2 = require("react");
|
|
|
32
29
|
var import_LayoutGroupContext = require("./LayoutGroupContext.cjs");
|
|
33
30
|
var import_PresenceChild = require("./PresenceChild.cjs");
|
|
34
31
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
-
const getChildKey = child => {
|
|
36
|
-
|
|
37
|
-
const ct = child.type;
|
|
38
|
-
const defaultName = ct["displayName"] || ct["name"] || "";
|
|
39
|
-
if (ct && typeof ct === "object" && "staticConfig" in ct) {
|
|
40
|
-
return ct.staticConfig.componentName || defaultName;
|
|
41
|
-
}
|
|
42
|
-
return defaultName;
|
|
43
|
-
})();
|
|
32
|
+
const getChildKey = (child) => {
|
|
33
|
+
return child.key ?? "";
|
|
44
34
|
};
|
|
45
35
|
function onlyElements(children) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
const filtered = [];
|
|
37
|
+
import_react2.Children.forEach(children, (child) => {
|
|
38
|
+
if ((0, import_react2.isValidElement)(child)) filtered.push(child);
|
|
39
|
+
});
|
|
40
|
+
return filtered;
|
|
51
41
|
}
|
|
52
|
-
const AnimatePresence = ({
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
onExitComplete?.();
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_PresenceChild.PresenceChild, {
|
|
136
|
-
isPresent,
|
|
137
|
-
initial: !isInitialRender.current || initial ? void 0 : false,
|
|
138
|
-
custom: isPresent ? custom : frozenCustomRef.current.get(key) ?? custom,
|
|
139
|
-
presenceAffectsLayout,
|
|
140
|
-
enterExitVariant,
|
|
141
|
-
enterVariant,
|
|
142
|
-
exitVariant,
|
|
143
|
-
onExitComplete: isPresent ? void 0 : onExit,
|
|
144
|
-
children: child
|
|
145
|
-
}, key);
|
|
146
|
-
})
|
|
147
|
-
});
|
|
42
|
+
const AnimatePresence = ({ children, initial = true, onExitComplete, mode = "sync", presenceAffectsLayout = true, custom, passThrough }) => {
|
|
43
|
+
const presentChildren = (0, import_react2.useMemo)(() => onlyElements(children), [children]);
|
|
44
|
+
const presentKeys = presentChildren.map(getChildKey);
|
|
45
|
+
const isInitialRender = (0, import_react2.useRef)(true);
|
|
46
|
+
const frozenCustomRef = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
|
|
47
|
+
const pendingPresentChildren = (0, import_react2.useRef)(presentChildren);
|
|
48
|
+
const exitComplete = (0, import_use_constant.useConstant)(() => /* @__PURE__ */ new Map());
|
|
49
|
+
const [diffedChildren, setDiffedChildren] = (0, import_react2.useState)(presentChildren);
|
|
50
|
+
const [renderedChildren, setRenderedChildren] = (0, import_react2.useState)(presentChildren);
|
|
51
|
+
const forceRender = (0, import_react2.useContext)(import_LayoutGroupContext.LayoutGroupContext).forceRender ?? (0, import_use_force_update.useForceUpdate)();
|
|
52
|
+
if (passThrough) {
|
|
53
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
54
|
+
}
|
|
55
|
+
(0, import_react.useInsertionEffect)(() => {
|
|
56
|
+
isInitialRender.current = false;
|
|
57
|
+
pendingPresentChildren.current = presentChildren;
|
|
58
|
+
for (let i = 0; i < renderedChildren.length; i++) {
|
|
59
|
+
const key = getChildKey(renderedChildren[i]);
|
|
60
|
+
if (!presentKeys.includes(key)) {
|
|
61
|
+
if (exitComplete.get(key) !== true) {
|
|
62
|
+
exitComplete.set(key, false);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
exitComplete.delete(key);
|
|
66
|
+
frozenCustomRef.current.delete(key);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}, [
|
|
70
|
+
renderedChildren,
|
|
71
|
+
presentKeys.length,
|
|
72
|
+
presentKeys.join("-")
|
|
73
|
+
]);
|
|
74
|
+
if (presentChildren !== diffedChildren) {
|
|
75
|
+
let nextChildren = [...presentChildren];
|
|
76
|
+
for (let i = 0; i < renderedChildren.length; i++) {
|
|
77
|
+
const child = renderedChildren[i];
|
|
78
|
+
const key = getChildKey(child);
|
|
79
|
+
if (!presentKeys.includes(key)) {
|
|
80
|
+
nextChildren.splice(i, 0, child);
|
|
81
|
+
if (!frozenCustomRef.current.has(key)) {
|
|
82
|
+
frozenCustomRef.current.set(key, custom);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const exitingChildren = renderedChildren.filter((child) => !presentKeys.includes(getChildKey(child)));
|
|
87
|
+
if (mode === "wait" && exitingChildren.length) {
|
|
88
|
+
nextChildren = exitingChildren;
|
|
89
|
+
}
|
|
90
|
+
setRenderedChildren(onlyElements(nextChildren));
|
|
91
|
+
setDiffedChildren(presentChildren);
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: renderedChildren.map((child) => {
|
|
95
|
+
const key = getChildKey(child);
|
|
96
|
+
const isPresent = presentChildren === renderedChildren || presentKeys.includes(key);
|
|
97
|
+
const onExit = () => {
|
|
98
|
+
if (exitComplete.has(key)) {
|
|
99
|
+
exitComplete.set(key, true);
|
|
100
|
+
} else {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
let isEveryExitComplete = true;
|
|
104
|
+
exitComplete.forEach((isExitComplete) => {
|
|
105
|
+
if (!isExitComplete) isEveryExitComplete = false;
|
|
106
|
+
});
|
|
107
|
+
if (isEveryExitComplete) {
|
|
108
|
+
forceRender?.();
|
|
109
|
+
setRenderedChildren(pendingPresentChildren.current);
|
|
110
|
+
onExitComplete?.();
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_PresenceChild.PresenceChild, {
|
|
114
|
+
isPresent,
|
|
115
|
+
initial: !isInitialRender.current || initial ? void 0 : false,
|
|
116
|
+
custom: isPresent ? custom : frozenCustomRef.current.get(key) ?? custom,
|
|
117
|
+
presenceAffectsLayout,
|
|
118
|
+
onExitComplete: isPresent ? void 0 : onExit,
|
|
119
|
+
children: child
|
|
120
|
+
}, key);
|
|
121
|
+
}) });
|
|
148
122
|
};
|
|
149
|
-
AnimatePresence.displayName = "AnimatePresence";
|
|
123
|
+
AnimatePresence.displayName = "AnimatePresence";
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var AnimatePresence_exports = {};
|
|
25
|
+
__export(AnimatePresence_exports, { AnimatePresence: () => AnimatePresence });
|
|
26
|
+
module.exports = __toCommonJS(AnimatePresence_exports);
|
|
27
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_use_constant = require("@tamagui/use-constant");
|
|
30
|
+
var import_use_force_update = require("@tamagui/use-force-update");
|
|
31
|
+
var import_react2 = require("react");
|
|
32
|
+
var import_LayoutGroupContext = require("./LayoutGroupContext.native.js");
|
|
33
|
+
var import_PresenceChild = require("./PresenceChild.native.js");
|
|
34
|
+
var getChildKey = function(child) {
|
|
35
|
+
var _child_key;
|
|
36
|
+
return (_child_key = child.key) !== null && _child_key !== void 0 ? _child_key : "";
|
|
37
|
+
};
|
|
38
|
+
function onlyElements(children) {
|
|
39
|
+
var filtered = [];
|
|
40
|
+
import_react2.Children.forEach(children, function(child) {
|
|
41
|
+
if (/* @__PURE__ */ (0, import_react2.isValidElement)(child)) filtered.push(child);
|
|
42
|
+
});
|
|
43
|
+
return filtered;
|
|
44
|
+
}
|
|
45
|
+
var AnimatePresence = function(param) {
|
|
46
|
+
var { children, initial = true, onExitComplete, mode = "sync", presenceAffectsLayout = true, custom, passThrough } = param;
|
|
47
|
+
var presentChildren = (0, import_react2.useMemo)(function() {
|
|
48
|
+
return onlyElements(children);
|
|
49
|
+
}, [children]);
|
|
50
|
+
var presentKeys = presentChildren.map(getChildKey);
|
|
51
|
+
var isInitialRender = (0, import_react2.useRef)(true);
|
|
52
|
+
var frozenCustomRef = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
|
|
53
|
+
var pendingPresentChildren = (0, import_react2.useRef)(presentChildren);
|
|
54
|
+
var exitComplete = (0, import_use_constant.useConstant)(function() {
|
|
55
|
+
return /* @__PURE__ */ new Map();
|
|
56
|
+
});
|
|
57
|
+
var [diffedChildren, setDiffedChildren] = (0, import_react2.useState)(presentChildren);
|
|
58
|
+
var [renderedChildren, setRenderedChildren] = (0, import_react2.useState)(presentChildren);
|
|
59
|
+
var _useContext_forceRender;
|
|
60
|
+
var forceRender = (_useContext_forceRender = (0, import_react2.useContext)(import_LayoutGroupContext.LayoutGroupContext).forceRender) !== null && _useContext_forceRender !== void 0 ? _useContext_forceRender : (0, import_use_force_update.useForceUpdate)();
|
|
61
|
+
if (passThrough) {
|
|
62
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
63
|
+
}
|
|
64
|
+
(0, import_react.useInsertionEffect)(function() {
|
|
65
|
+
isInitialRender.current = false;
|
|
66
|
+
pendingPresentChildren.current = presentChildren;
|
|
67
|
+
for (var i2 = 0; i2 < renderedChildren.length; i2++) {
|
|
68
|
+
var key2 = getChildKey(renderedChildren[i2]);
|
|
69
|
+
if (!presentKeys.includes(key2)) {
|
|
70
|
+
if (exitComplete.get(key2) !== true) {
|
|
71
|
+
exitComplete.set(key2, false);
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
exitComplete.delete(key2);
|
|
75
|
+
frozenCustomRef.current.delete(key2);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}, [
|
|
79
|
+
renderedChildren,
|
|
80
|
+
presentKeys.length,
|
|
81
|
+
presentKeys.join("-")
|
|
82
|
+
]);
|
|
83
|
+
if (presentChildren !== diffedChildren) {
|
|
84
|
+
var nextChildren = [...presentChildren];
|
|
85
|
+
for (var i = 0; i < renderedChildren.length; i++) {
|
|
86
|
+
var child = renderedChildren[i];
|
|
87
|
+
var key = getChildKey(child);
|
|
88
|
+
if (!presentKeys.includes(key)) {
|
|
89
|
+
nextChildren.splice(i, 0, child);
|
|
90
|
+
if (!frozenCustomRef.current.has(key)) {
|
|
91
|
+
frozenCustomRef.current.set(key, custom);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
var exitingChildren = renderedChildren.filter(function(child2) {
|
|
96
|
+
return !presentKeys.includes(getChildKey(child2));
|
|
97
|
+
});
|
|
98
|
+
if (mode === "wait" && exitingChildren.length) {
|
|
99
|
+
nextChildren = exitingChildren;
|
|
100
|
+
}
|
|
101
|
+
setRenderedChildren(onlyElements(nextChildren));
|
|
102
|
+
setDiffedChildren(presentChildren);
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: renderedChildren.map(function(child2) {
|
|
106
|
+
var key2 = getChildKey(child2);
|
|
107
|
+
var isPresent = presentChildren === renderedChildren || presentKeys.includes(key2);
|
|
108
|
+
var onExit = function() {
|
|
109
|
+
if (exitComplete.has(key2)) {
|
|
110
|
+
exitComplete.set(key2, true);
|
|
111
|
+
} else {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
var isEveryExitComplete = true;
|
|
115
|
+
exitComplete.forEach(function(isExitComplete) {
|
|
116
|
+
if (!isExitComplete) isEveryExitComplete = false;
|
|
117
|
+
});
|
|
118
|
+
if (isEveryExitComplete) {
|
|
119
|
+
forceRender === null || forceRender === void 0 ? void 0 : forceRender();
|
|
120
|
+
setRenderedChildren(pendingPresentChildren.current);
|
|
121
|
+
onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
var _frozenCustomRef_current_get;
|
|
125
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_PresenceChild.PresenceChild, {
|
|
126
|
+
isPresent,
|
|
127
|
+
initial: !isInitialRender.current || initial ? void 0 : false,
|
|
128
|
+
custom: isPresent ? custom : (_frozenCustomRef_current_get = frozenCustomRef.current.get(key2)) !== null && _frozenCustomRef_current_get !== void 0 ? _frozenCustomRef_current_get : custom,
|
|
129
|
+
presenceAffectsLayout,
|
|
130
|
+
onExitComplete: isPresent ? void 0 : onExit,
|
|
131
|
+
children: child2
|
|
132
|
+
}, key2);
|
|
133
|
+
}) });
|
|
134
|
+
};
|
|
135
|
+
AnimatePresence.displayName = "AnimatePresence";
|