@tamagui/animate-presence 1.0.1-beta.151 → 1.0.1-beta.152
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.js +56 -38
- package/dist/cjs/AnimatePresence.js.map +2 -2
- package/dist/cjs/LayoutGroupContext.js.map +1 -1
- package/dist/cjs/PresenceChild.js +32 -24
- package/dist/cjs/PresenceChild.js.map +2 -2
- package/dist/cjs/PresenceContext.js.map +1 -1
- package/dist/cjs/usePresence.js.map +2 -2
- package/dist/esm/AnimatePresence.js +52 -37
- package/dist/esm/AnimatePresence.js.map +1 -1
- package/dist/esm/LayoutGroupContext.js.map +1 -1
- package/dist/esm/PresenceChild.js +28 -23
- package/dist/esm/PresenceChild.js.map +2 -2
- package/dist/esm/PresenceContext.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/usePresence.js.map +2 -2
- package/dist/jsx/AnimatePresence.js +27 -17
- package/dist/jsx/AnimatePresence.js.map +1 -1
- package/dist/jsx/LayoutGroupContext.js.map +1 -1
- package/dist/jsx/PresenceChild.js +23 -20
- package/dist/jsx/PresenceChild.js.map +2 -2
- package/dist/jsx/PresenceContext.js.map +1 -1
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/usePresence.js.map +2 -2
- package/package.json +3 -3
|
@@ -17,13 +17,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
var AnimatePresence_exports = {};
|
|
23
26
|
__export(AnimatePresence_exports, {
|
|
24
27
|
AnimatePresence: () => AnimatePresence
|
|
25
28
|
});
|
|
26
29
|
module.exports = __toCommonJS(AnimatePresence_exports);
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
27
31
|
var import_core = require("@tamagui/core");
|
|
28
32
|
var import_react = __toESM(require("react"));
|
|
29
33
|
var import_LayoutGroupContext = require("./LayoutGroupContext");
|
|
@@ -50,9 +54,11 @@ function onlyElements(children) {
|
|
|
50
54
|
if (process.env.NODE_ENV === "development") {
|
|
51
55
|
console.warn(`No key given to AnimatePresence child, assigning index as key`);
|
|
52
56
|
}
|
|
53
|
-
filtered.push(
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
filtered.push(
|
|
58
|
+
import_react.default.cloneElement(child, {
|
|
59
|
+
key: index
|
|
60
|
+
})
|
|
61
|
+
);
|
|
56
62
|
} else {
|
|
57
63
|
filtered.push(child);
|
|
58
64
|
}
|
|
@@ -91,14 +97,16 @@ const AnimatePresence = ({
|
|
|
91
97
|
exiting.clear();
|
|
92
98
|
});
|
|
93
99
|
if (isInitialRender.current) {
|
|
94
|
-
return /* @__PURE__ */
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
101
|
+
children: childrenToRender.map((child) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_PresenceChild.PresenceChild, {
|
|
102
|
+
isPresent: true,
|
|
103
|
+
exitVariant,
|
|
104
|
+
enterVariant,
|
|
105
|
+
initial: initial ? void 0 : false,
|
|
106
|
+
presenceAffectsLayout,
|
|
107
|
+
children: child
|
|
108
|
+
}, getChildKey(child)))
|
|
109
|
+
});
|
|
102
110
|
}
|
|
103
111
|
childrenToRender = [...childrenToRender];
|
|
104
112
|
const presentKeys = presentChildren.current.map(getChildKey);
|
|
@@ -120,41 +128,51 @@ const AnimatePresence = ({
|
|
|
120
128
|
if (!child)
|
|
121
129
|
return;
|
|
122
130
|
const insertionIndex = presentKeys.indexOf(key);
|
|
123
|
-
childrenToRender.splice(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
131
|
+
childrenToRender.splice(
|
|
132
|
+
insertionIndex,
|
|
133
|
+
0,
|
|
134
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_PresenceChild.PresenceChild, {
|
|
135
|
+
isPresent: false,
|
|
136
|
+
onExitComplete: () => {
|
|
137
|
+
allChildren.delete(key);
|
|
138
|
+
exiting.delete(key);
|
|
139
|
+
const removeIndex = presentChildren.current.findIndex(
|
|
140
|
+
(presentChild) => presentChild.key === key
|
|
141
|
+
);
|
|
142
|
+
presentChildren.current.splice(removeIndex, 1);
|
|
143
|
+
if (!exiting.size) {
|
|
144
|
+
presentChildren.current = filteredChildren;
|
|
145
|
+
if (isMounted.current === false)
|
|
146
|
+
return;
|
|
147
|
+
forceRender();
|
|
148
|
+
onExitComplete == null ? void 0 : onExitComplete();
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
exitVariant,
|
|
152
|
+
enterVariant,
|
|
153
|
+
presenceAffectsLayout,
|
|
154
|
+
children: child
|
|
155
|
+
}, getChildKey(child))
|
|
156
|
+
);
|
|
143
157
|
});
|
|
144
158
|
childrenToRender = childrenToRender.map((child) => {
|
|
145
159
|
const key = child.key;
|
|
146
|
-
return exiting.has(key) ? child : /* @__PURE__ */
|
|
147
|
-
key: getChildKey(child),
|
|
160
|
+
return exiting.has(key) ? child : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_PresenceChild.PresenceChild, {
|
|
148
161
|
isPresent: true,
|
|
149
162
|
exitVariant,
|
|
150
163
|
enterVariant,
|
|
151
|
-
presenceAffectsLayout
|
|
152
|
-
|
|
164
|
+
presenceAffectsLayout,
|
|
165
|
+
children: child
|
|
166
|
+
}, getChildKey(child));
|
|
153
167
|
});
|
|
154
168
|
if (process.env.NODE_ENV !== "production" && exitBeforeEnter && childrenToRender.length > 1) {
|
|
155
|
-
console.warn(
|
|
169
|
+
console.warn(
|
|
170
|
+
`You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`
|
|
171
|
+
);
|
|
156
172
|
}
|
|
157
|
-
return /* @__PURE__ */
|
|
173
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
174
|
+
children: exiting.size ? childrenToRender : childrenToRender.map((child) => (0, import_react.cloneElement)(child))
|
|
175
|
+
});
|
|
158
176
|
};
|
|
159
177
|
AnimatePresence.displayName = "AnimatePresence";
|
|
160
178
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/AnimatePresence.tsx"],
|
|
4
4
|
"sourcesContent": ["import {\n useForceUpdate,\n useIsMounted,\n useIsomorphicLayoutEffect,\n useUnmountEffect,\n} from '@tamagui/core'\nimport React, {\n Children,\n ReactElement,\n ReactNode,\n cloneElement,\n isValidElement,\n useContext,\n useRef,\n} from 'react'\n\nimport { LayoutGroupContext } from './LayoutGroupContext'\nimport { PresenceChild } from './PresenceChild'\nimport { AnimatePresenceProps } from './types'\n\nReact['keep']\n\ntype ComponentKey = string | number\n\nconst getChildKey = (child: ReactElement<any>): ComponentKey => child.key || ''\n\nconst isDev = process.env.NODE_ENV !== 'production'\n\nfunction updateChildLookup(\n children: ReactElement<any>[],\n allChildren: Map<ComponentKey, ReactElement<any>>\n) {\n const seenChildren = isDev ? new Set<ComponentKey>() : null\n\n children.forEach((child) => {\n const key = getChildKey(child)\n\n if (isDev && seenChildren && seenChildren.has(key)) {\n // eslint-disable-next-line no-console\n console.warn(`Children of AnimatePresence require unique keys. \"${key}\" is a duplicate.`)\n\n seenChildren.add(key)\n }\n\n allChildren.set(key, child)\n })\n}\n\nfunction onlyElements(children: ReactNode): ReactElement<any>[] {\n const filtered: ReactElement<any>[] = []\n\n // We use forEach here instead of map as map mutates the component key by preprending `.$`\n Children.forEach(children, (child, index) => {\n if (isValidElement(child)) {\n if (!child.key) {\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn(`No key given to AnimatePresence child, assigning index as key`)\n }\n filtered.push(\n React.cloneElement(child, {\n key: index,\n })\n )\n } else {\n filtered.push(child)\n }\n }\n })\n\n return filtered\n}\n\n/**\n * `AnimatePresence` enables the animation of components that have been removed from the tree.\n *\n * When adding/removing more than a single child, every child **must** be given a unique `key` prop.\n *\n * Any `motion` components that have an `exit` property defined will animate out when removed from\n * the tree.\n *\n * ```tsx\n * import { motion, AnimatePresence } from 'framer-motion'\n *\n * export const Items = ({ items }) => (\n * <AnimatePresence>\n * {items.map(item => (\n * <motion.div\n * key={item.id}\n * initial={{ opacity: 0 }}\n * animate={{ opacity: 1 }}\n * exit={{ opacity: 0 }}\n * />\n * ))}\n * </AnimatePresence>\n * )\n * ```\n *\n * You can sequence exit animations throughout a tree using variants.\n *\n * If a child contains multiple `motion` components with `exit` props, it will only unmount the child\n * once all `motion` components have finished animating out. Likewise, any components using\n * `usePresence` all need to call `safeToRemove`.\n *\n * @public\n */\nexport const AnimatePresence: React.FunctionComponent<\n React.PropsWithChildren<AnimatePresenceProps>\n> = ({\n children,\n enterVariant,\n exitVariant,\n initial = true,\n onExitComplete,\n exitBeforeEnter,\n presenceAffectsLayout = true,\n}) => {\n // We want to force a re-render once all exiting animations have finished. We\n // either use a local forceRender function, or one from a parent context if it exists.\n let forceRender = useForceUpdate()\n const forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender\n if (forceRenderLayoutGroup) forceRender = forceRenderLayoutGroup\n\n const isMounted = useIsMounted()\n\n // Filter out any children that aren't ReactElements. We can only track ReactElements with a props.key\n const filteredChildren = onlyElements(children)\n let childrenToRender = filteredChildren\n\n const exiting = new Set<ComponentKey>()\n\n // Keep a living record of the children we're actually rendering so we\n // can diff to figure out which are entering and exiting\n const presentChildren = useRef(childrenToRender)\n\n // A lookup table to quickly reference components by key\n const allChildren = useRef(new Map<ComponentKey, ReactElement<any>>()).current\n\n // If this is the initial component render, just deal with logic surrounding whether\n // we play onMount animations or not.\n const isInitialRender = useRef(true)\n\n useIsomorphicLayoutEffect(() => {\n isInitialRender.current = false\n updateChildLookup(filteredChildren, allChildren)\n presentChildren.current = childrenToRender\n })\n\n useUnmountEffect(() => {\n isInitialRender.current = true\n allChildren.clear()\n exiting.clear()\n })\n\n if (isInitialRender.current) {\n return (\n <>\n {childrenToRender.map((child) => (\n <PresenceChild\n key={getChildKey(child)}\n isPresent\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n initial={initial ? undefined : false}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n ))}\n </>\n )\n }\n\n // If this is a subsequent render, deal with entering and exiting children\n childrenToRender = [...childrenToRender]\n\n // Diff the keys of the currently-present and target children to update our\n // exiting list.\n const presentKeys = presentChildren.current.map(getChildKey)\n const targetKeys = filteredChildren.map(getChildKey)\n\n // Diff the present children with our target children and mark those that are exiting\n const numPresent = presentKeys.length\n for (let i = 0; i < numPresent; i++) {\n const key = presentKeys[i]\n if (targetKeys.indexOf(key) === -1) {\n exiting.add(key)\n }\n }\n\n // If we currently have exiting children, and we're deferring rendering incoming children\n // until after all current children have exiting, empty the childrenToRender array\n if (exitBeforeEnter && exiting.size) {\n childrenToRender = []\n }\n\n // Loop through all currently exiting components and clone them to overwrite `animate`\n // with any `exit` prop they might have defined.\n exiting.forEach((key) => {\n // If this component is actually entering again, early return\n if (targetKeys.indexOf(key) !== -1) return\n\n const child = allChildren.get(key)\n if (!child) return\n\n const insertionIndex = presentKeys.indexOf(key)\n\n childrenToRender.splice(\n insertionIndex,\n 0,\n <PresenceChild\n key={getChildKey(child)}\n isPresent={false}\n onExitComplete={() => {\n allChildren.delete(key)\n exiting.delete(key)\n\n // Remove this child from the present children\n const removeIndex = presentChildren.current.findIndex(\n (presentChild) => presentChild.key === key\n )\n presentChildren.current.splice(removeIndex, 1)\n\n // Defer re-rendering until all exiting children have indeed left\n if (!exiting.size) {\n presentChildren.current = filteredChildren\n\n if (isMounted.current === false) return\n\n forceRender()\n onExitComplete?.()\n }\n }}\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n )\n })\n\n // Add `MotionContext` even to children that don't need it to ensure we're rendering\n // the same tree between renders\n childrenToRender = childrenToRender.map((child) => {\n const key = child.key as string | number\n return exiting.has(key) ? (\n child\n ) : (\n <PresenceChild\n key={getChildKey(child)}\n isPresent\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n )\n })\n\n if (process.env.NODE_ENV !== 'production' && exitBeforeEnter && childrenToRender.length > 1) {\n // eslint-disable-next-line no-console\n console.warn(\n `You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`\n )\n }\n\n return (\n <>{exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child))}</>\n )\n}\n\nAnimatePresence.displayName = 'AnimatePresence'\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4JM;AA5JN,kBAKO;AACP,mBAQO;AAEP,gCAAmC;AACnC,2BAA8B;AAG9B,aAAAA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,gBAAM,cAAc,gBAAgB,QAAQ;AAAA,YAC1C,CAAC,iBAAiB,aAAa,QAAQ;AAAA,UACzC;AACA,0BAAgB,QAAQ,OAAO,aAAa,CAAC;AAG7C,cAAI,CAAC,QAAQ,MAAM;AACjB,4BAAgB,UAAU;AAE1B,gBAAI,UAAU,YAAY;AAAO;AAEjC,wBAAY;AACZ;AAAA,UACF;AAAA,QACF;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QAEC;AAAA,SA1BI,YAAY,KAAK,CA2BxB;AAAA,IACF;AAAA,EACF,CAAC;AAID,qBAAmB,iBAAiB,IAAI,CAAC,UAAU;AACjD,UAAM,MAAM,MAAM;AAClB,WAAO,QAAQ,IAAI,GAAG,IACpB,QAEA,4CAAC;AAAA,MAEC,WAAS;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MAEC;AAAA,OANI,YAAY,KAAK,CAOxB;AAAA,EAEJ,CAAC;AAED,MAAI,QAAQ,IAAI,aAAa,gBAAgB,mBAAmB,iBAAiB,SAAS,GAAG;AAE3F,YAAQ;AAAA,MACN;AAAA,IACF;AAAA,EACF;AAEA,SACE;AAAA,IAAG,kBAAQ,OAAO,mBAAmB,iBAAiB,IAAI,CAAC,cAAU,2BAAa,KAAK,CAAC;AAAA,GAAE;AAE9F;AAEA,gBAAgB,cAAc;",
|
|
6
|
+
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/LayoutGroupContext.tsx"],
|
|
4
4
|
"sourcesContent": ["import { createContext } from 'react'\n\nexport interface LayoutGroupContextProps {\n id?: string\n forceRender?: VoidFunction\n}\n\nexport const LayoutGroupContext = createContext<LayoutGroupContextProps>({})\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;AAOvB,MAAM,
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;AAOvB,MAAM,yBAAqB,4BAAuC,CAAC,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -17,13 +17,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
var PresenceChild_exports = {};
|
|
23
26
|
__export(PresenceChild_exports, {
|
|
24
27
|
PresenceChild: () => PresenceChild
|
|
25
28
|
});
|
|
26
29
|
module.exports = __toCommonJS(PresenceChild_exports);
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
27
31
|
var import_core = require("@tamagui/core");
|
|
28
32
|
var React = __toESM(require("react"));
|
|
29
33
|
var import_PresenceContext = require("./PresenceContext");
|
|
@@ -38,37 +42,41 @@ const PresenceChild = ({
|
|
|
38
42
|
}) => {
|
|
39
43
|
const presenceChildren = (0, import_core.useConstant)(newChildrenMap);
|
|
40
44
|
const id = (0, import_core.useId)() || "";
|
|
41
|
-
const context = React.useMemo(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
const context = React.useMemo(
|
|
46
|
+
() => {
|
|
47
|
+
return {
|
|
48
|
+
id,
|
|
49
|
+
initial,
|
|
50
|
+
isPresent,
|
|
51
|
+
exitVariant,
|
|
52
|
+
enterVariant,
|
|
53
|
+
onExitComplete: (id2) => {
|
|
54
|
+
presenceChildren.set(id2, true);
|
|
55
|
+
for (const isComplete of presenceChildren.values()) {
|
|
56
|
+
if (!isComplete) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
53
59
|
}
|
|
60
|
+
onExitComplete == null ? void 0 : onExitComplete();
|
|
61
|
+
},
|
|
62
|
+
register: (id2) => {
|
|
63
|
+
presenceChildren.set(id2, false);
|
|
64
|
+
return () => presenceChildren.delete(id2);
|
|
54
65
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return () => presenceChildren.delete(id2);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}, presenceAffectsLayout ? void 0 : [isPresent, exitVariant, enterVariant]);
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
presenceAffectsLayout ? void 0 : [isPresent, exitVariant, enterVariant]
|
|
69
|
+
);
|
|
63
70
|
React.useMemo(() => {
|
|
64
71
|
presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
|
|
65
72
|
}, [isPresent]);
|
|
66
73
|
React.useEffect(() => {
|
|
67
74
|
!isPresent && !presenceChildren.size && (onExitComplete == null ? void 0 : onExitComplete());
|
|
68
75
|
}, [isPresent]);
|
|
69
|
-
return /* @__PURE__ */
|
|
70
|
-
value: context
|
|
71
|
-
|
|
76
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_PresenceContext.PresenceContext.Provider, {
|
|
77
|
+
value: context,
|
|
78
|
+
children
|
|
79
|
+
});
|
|
72
80
|
};
|
|
73
81
|
function newChildrenMap() {
|
|
74
82
|
return /* @__PURE__ */ new Map();
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/PresenceChild.tsx"],
|
|
4
4
|
"sourcesContent": ["import { useConstant, useId } from '@tamagui/core'\nimport * as React from 'react'\n\nimport { PresenceContext, PresenceContextProps } from './PresenceContext'\nimport { VariantLabels } from './types'\n\ninterface PresenceChildProps {\n children: React.ReactElement<any>\n isPresent: boolean\n onExitComplete?: () => void\n initial?: false | VariantLabels\n custom?: any\n presenceAffectsLayout: boolean\n exitVariant?: string | null\n enterVariant?: string | null\n}\n\nexport const PresenceChild = ({\n children,\n initial,\n isPresent,\n onExitComplete,\n exitVariant,\n enterVariant,\n presenceAffectsLayout,\n}: PresenceChildProps) => {\n const presenceChildren = useConstant(newChildrenMap)\n const id = useId() || ''\n\n const context = React.useMemo(\n (): PresenceContextProps => {\n return {\n id,\n initial,\n isPresent,\n exitVariant,\n enterVariant,\n onExitComplete: (id: string) => {\n presenceChildren.set(id, true)\n for (const isComplete of presenceChildren.values()) {\n if (!isComplete) {\n return // can stop searching when any is incomplete\n }\n }\n onExitComplete?.()\n },\n register: (id: string) => {\n presenceChildren.set(id, false)\n return () => presenceChildren.delete(id)\n },\n }\n },\n /**\n * If the presence of a child affects the layout of the components around it,\n * we want to make a new context value to ensure they get re-rendered\n * so they can detect that layout change.\n */\n // eslint-disable-next-line react-hooks/exhaustive-deps\n presenceAffectsLayout ? undefined : [isPresent, exitVariant, enterVariant]\n )\n\n React.useMemo(() => {\n presenceChildren.forEach((_, key) => presenceChildren.set(key, false))\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isPresent])\n\n /**\n * If there's no animated components to fire exit animations, we want to remove this\n * component immediately.\n */\n React.useEffect(() => {\n !isPresent && !presenceChildren.size && onExitComplete?.()\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isPresent])\n\n return <PresenceContext.Provider value={context}>{children}</PresenceContext.Provider>\n}\n\nfunction newChildrenMap(): Map<string, boolean> {\n return new Map()\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2ES;AA3ET,kBAAmC;AAC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 'react'\n\nimport { VariantLabels } from './types'\n\nexport interface PresenceContextProps {\n id: string\n isPresent: boolean\n register: (id: string) => () => void\n onExitComplete?: (id: string) => void\n initial?: false | VariantLabels\n custom?: any\n exitVariant?: string | null\n enterVariant?: string | null\n}\n\nexport const PresenceContext = createContext<PresenceContextProps | null>(null)\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;AAevB,MAAM,
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;AAevB,MAAM,sBAAkB,4BAA2C,IAAI;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/usePresence.ts"],
|
|
4
4
|
"sourcesContent": ["import { useId } from '@tamagui/core'\nimport { useContext, useEffect } from 'react'\n\nimport { PresenceContext, PresenceContextProps } from './PresenceContext'\n\nexport type SafeToRemove = () => void\ntype AlwaysPresent = [true, null]\ntype Present = [true]\ntype NotPresent = [false, SafeToRemove]\n\nexport function usePresence(): AlwaysPresent | Present | NotPresent {\n const context = useContext(PresenceContext)\n\n if (context === null) {\n return [true, null]\n }\n\n const { isPresent, onExitComplete, register } = context\n const id = useId() || ''\n useEffect(() => register(id), [id, register])\n\n const safeToRemove = () => onExitComplete?.(id)\n\n return !isPresent && onExitComplete ? [false, safeToRemove] : [true]\n}\n\n/**\n * Similar to `usePresence`, except `useIsPresent` simply returns whether or not the component is present.\n * There is no `safeToRemove` function. ```\n */\nexport function useIsPresent() {\n return isPresent(useContext(PresenceContext))\n}\n\nexport function isPresent(context: PresenceContextProps | null) {\n return context === null ? true : context.isPresent\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAsB;AACtB,mBAAsC;AAEtC,6BAAsD;AAO/C,
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAsB;AACtB,mBAAsC;AAEtC,6BAAsD;AAO/C,SAAS,cAAoD;AAClE,QAAM,cAAU,yBAAW,sCAAe;AAE1C,MAAI,YAAY,MAAM;AACpB,WAAO,CAAC,MAAM,IAAI;AAAA,EACpB;AAEA,QAAM,EAAE,WAAAA,YAAW,gBAAgB,SAAS,IAAI;AAChD,QAAM,SAAK,mBAAM,KAAK;AACtB,8BAAU,MAAM,SAAS,EAAE,GAAG,CAAC,IAAI,QAAQ,CAAC;AAE5C,QAAM,eAAe,MAAM,iDAAiB;AAE5C,SAAO,CAACA,cAAa,iBAAiB,CAAC,OAAO,YAAY,IAAI,CAAC,IAAI;AACrE;AAMO,SAAS,eAAe;AAC7B,SAAO,cAAU,yBAAW,sCAAe,CAAC;AAC9C;AAEO,SAAS,UAAU,SAAsC;AAC9D,SAAO,YAAY,OAAO,OAAO,QAAQ;AAC3C;",
|
|
6
|
+
"names": ["isPresent"]
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
1
2
|
import {
|
|
2
3
|
useForceUpdate,
|
|
3
4
|
useIsMounted,
|
|
@@ -35,9 +36,11 @@ function onlyElements(children) {
|
|
|
35
36
|
if (process.env.NODE_ENV === "development") {
|
|
36
37
|
console.warn(`No key given to AnimatePresence child, assigning index as key`);
|
|
37
38
|
}
|
|
38
|
-
filtered.push(
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
filtered.push(
|
|
40
|
+
React.cloneElement(child, {
|
|
41
|
+
key: index
|
|
42
|
+
})
|
|
43
|
+
);
|
|
41
44
|
} else {
|
|
42
45
|
filtered.push(child);
|
|
43
46
|
}
|
|
@@ -76,14 +79,16 @@ const AnimatePresence = ({
|
|
|
76
79
|
exiting.clear();
|
|
77
80
|
});
|
|
78
81
|
if (isInitialRender.current) {
|
|
79
|
-
return /* @__PURE__ */
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
83
|
+
children: childrenToRender.map((child) => /* @__PURE__ */ jsx(PresenceChild, {
|
|
84
|
+
isPresent: true,
|
|
85
|
+
exitVariant,
|
|
86
|
+
enterVariant,
|
|
87
|
+
initial: initial ? void 0 : false,
|
|
88
|
+
presenceAffectsLayout,
|
|
89
|
+
children: child
|
|
90
|
+
}, getChildKey(child)))
|
|
91
|
+
});
|
|
87
92
|
}
|
|
88
93
|
childrenToRender = [...childrenToRender];
|
|
89
94
|
const presentKeys = presentChildren.current.map(getChildKey);
|
|
@@ -105,41 +110,51 @@ const AnimatePresence = ({
|
|
|
105
110
|
if (!child)
|
|
106
111
|
return;
|
|
107
112
|
const insertionIndex = presentKeys.indexOf(key);
|
|
108
|
-
childrenToRender.splice(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
113
|
+
childrenToRender.splice(
|
|
114
|
+
insertionIndex,
|
|
115
|
+
0,
|
|
116
|
+
/* @__PURE__ */ jsx(PresenceChild, {
|
|
117
|
+
isPresent: false,
|
|
118
|
+
onExitComplete: () => {
|
|
119
|
+
allChildren.delete(key);
|
|
120
|
+
exiting.delete(key);
|
|
121
|
+
const removeIndex = presentChildren.current.findIndex(
|
|
122
|
+
(presentChild) => presentChild.key === key
|
|
123
|
+
);
|
|
124
|
+
presentChildren.current.splice(removeIndex, 1);
|
|
125
|
+
if (!exiting.size) {
|
|
126
|
+
presentChildren.current = filteredChildren;
|
|
127
|
+
if (isMounted.current === false)
|
|
128
|
+
return;
|
|
129
|
+
forceRender();
|
|
130
|
+
onExitComplete == null ? void 0 : onExitComplete();
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
exitVariant,
|
|
134
|
+
enterVariant,
|
|
135
|
+
presenceAffectsLayout,
|
|
136
|
+
children: child
|
|
137
|
+
}, getChildKey(child))
|
|
138
|
+
);
|
|
128
139
|
});
|
|
129
140
|
childrenToRender = childrenToRender.map((child) => {
|
|
130
141
|
const key = child.key;
|
|
131
|
-
return exiting.has(key) ? child : /* @__PURE__ */
|
|
132
|
-
key: getChildKey(child),
|
|
142
|
+
return exiting.has(key) ? child : /* @__PURE__ */ jsx(PresenceChild, {
|
|
133
143
|
isPresent: true,
|
|
134
144
|
exitVariant,
|
|
135
145
|
enterVariant,
|
|
136
|
-
presenceAffectsLayout
|
|
137
|
-
|
|
146
|
+
presenceAffectsLayout,
|
|
147
|
+
children: child
|
|
148
|
+
}, getChildKey(child));
|
|
138
149
|
});
|
|
139
150
|
if (process.env.NODE_ENV !== "production" && exitBeforeEnter && childrenToRender.length > 1) {
|
|
140
|
-
console.warn(
|
|
151
|
+
console.warn(
|
|
152
|
+
`You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`
|
|
153
|
+
);
|
|
141
154
|
}
|
|
142
|
-
return /* @__PURE__ */
|
|
155
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
156
|
+
children: exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child))
|
|
157
|
+
});
|
|
143
158
|
};
|
|
144
159
|
AnimatePresence.displayName = "AnimatePresence";
|
|
145
160
|
export {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/AnimatePresence.tsx"],
|
|
4
4
|
"sourcesContent": ["import {\n useForceUpdate,\n useIsMounted,\n useIsomorphicLayoutEffect,\n useUnmountEffect,\n} from '@tamagui/core'\nimport React, {\n Children,\n ReactElement,\n ReactNode,\n cloneElement,\n isValidElement,\n useContext,\n useRef,\n} from 'react'\n\nimport { LayoutGroupContext } from './LayoutGroupContext'\nimport { PresenceChild } from './PresenceChild'\nimport { AnimatePresenceProps } from './types'\n\nReact['keep']\n\ntype ComponentKey = string | number\n\nconst getChildKey = (child: ReactElement<any>): ComponentKey => child.key || ''\n\nconst isDev = process.env.NODE_ENV !== 'production'\n\nfunction updateChildLookup(\n children: ReactElement<any>[],\n allChildren: Map<ComponentKey, ReactElement<any>>\n) {\n const seenChildren = isDev ? new Set<ComponentKey>() : null\n\n children.forEach((child) => {\n const key = getChildKey(child)\n\n if (isDev && seenChildren && seenChildren.has(key)) {\n // eslint-disable-next-line no-console\n console.warn(`Children of AnimatePresence require unique keys. \"${key}\" is a duplicate.`)\n\n seenChildren.add(key)\n }\n\n allChildren.set(key, child)\n })\n}\n\nfunction onlyElements(children: ReactNode): ReactElement<any>[] {\n const filtered: ReactElement<any>[] = []\n\n // We use forEach here instead of map as map mutates the component key by preprending `.$`\n Children.forEach(children, (child, index) => {\n if (isValidElement(child)) {\n if (!child.key) {\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn(`No key given to AnimatePresence child, assigning index as key`)\n }\n filtered.push(\n React.cloneElement(child, {\n key: index,\n })\n )\n } else {\n filtered.push(child)\n }\n }\n })\n\n return filtered\n}\n\n/**\n * `AnimatePresence` enables the animation of components that have been removed from the tree.\n *\n * When adding/removing more than a single child, every child **must** be given a unique `key` prop.\n *\n * Any `motion` components that have an `exit` property defined will animate out when removed from\n * the tree.\n *\n * ```tsx\n * import { motion, AnimatePresence } from 'framer-motion'\n *\n * export const Items = ({ items }) => (\n * <AnimatePresence>\n * {items.map(item => (\n * <motion.div\n * key={item.id}\n * initial={{ opacity: 0 }}\n * animate={{ opacity: 1 }}\n * exit={{ opacity: 0 }}\n * />\n * ))}\n * </AnimatePresence>\n * )\n * ```\n *\n * You can sequence exit animations throughout a tree using variants.\n *\n * If a child contains multiple `motion` components with `exit` props, it will only unmount the child\n * once all `motion` components have finished animating out. Likewise, any components using\n * `usePresence` all need to call `safeToRemove`.\n *\n * @public\n */\nexport const AnimatePresence: React.FunctionComponent<\n React.PropsWithChildren<AnimatePresenceProps>\n> = ({\n children,\n enterVariant,\n exitVariant,\n initial = true,\n onExitComplete,\n exitBeforeEnter,\n presenceAffectsLayout = true,\n}) => {\n // We want to force a re-render once all exiting animations have finished. We\n // either use a local forceRender function, or one from a parent context if it exists.\n let forceRender = useForceUpdate()\n const forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender\n if (forceRenderLayoutGroup) forceRender = forceRenderLayoutGroup\n\n const isMounted = useIsMounted()\n\n // Filter out any children that aren't ReactElements. We can only track ReactElements with a props.key\n const filteredChildren = onlyElements(children)\n let childrenToRender = filteredChildren\n\n const exiting = new Set<ComponentKey>()\n\n // Keep a living record of the children we're actually rendering so we\n // can diff to figure out which are entering and exiting\n const presentChildren = useRef(childrenToRender)\n\n // A lookup table to quickly reference components by key\n const allChildren = useRef(new Map<ComponentKey, ReactElement<any>>()).current\n\n // If this is the initial component render, just deal with logic surrounding whether\n // we play onMount animations or not.\n const isInitialRender = useRef(true)\n\n useIsomorphicLayoutEffect(() => {\n isInitialRender.current = false\n updateChildLookup(filteredChildren, allChildren)\n presentChildren.current = childrenToRender\n })\n\n useUnmountEffect(() => {\n isInitialRender.current = true\n allChildren.clear()\n exiting.clear()\n })\n\n if (isInitialRender.current) {\n return (\n <>\n {childrenToRender.map((child) => (\n <PresenceChild\n key={getChildKey(child)}\n isPresent\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n initial={initial ? undefined : false}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n ))}\n </>\n )\n }\n\n // If this is a subsequent render, deal with entering and exiting children\n childrenToRender = [...childrenToRender]\n\n // Diff the keys of the currently-present and target children to update our\n // exiting list.\n const presentKeys = presentChildren.current.map(getChildKey)\n const targetKeys = filteredChildren.map(getChildKey)\n\n // Diff the present children with our target children and mark those that are exiting\n const numPresent = presentKeys.length\n for (let i = 0; i < numPresent; i++) {\n const key = presentKeys[i]\n if (targetKeys.indexOf(key) === -1) {\n exiting.add(key)\n }\n }\n\n // If we currently have exiting children, and we're deferring rendering incoming children\n // until after all current children have exiting, empty the childrenToRender array\n if (exitBeforeEnter && exiting.size) {\n childrenToRender = []\n }\n\n // Loop through all currently exiting components and clone them to overwrite `animate`\n // with any `exit` prop they might have defined.\n exiting.forEach((key) => {\n // If this component is actually entering again, early return\n if (targetKeys.indexOf(key) !== -1) return\n\n const child = allChildren.get(key)\n if (!child) return\n\n const insertionIndex = presentKeys.indexOf(key)\n\n childrenToRender.splice(\n insertionIndex,\n 0,\n <PresenceChild\n key={getChildKey(child)}\n isPresent={false}\n onExitComplete={() => {\n allChildren.delete(key)\n exiting.delete(key)\n\n // Remove this child from the present children\n const removeIndex = presentChildren.current.findIndex(\n (presentChild) => presentChild.key === key\n )\n presentChildren.current.splice(removeIndex, 1)\n\n // Defer re-rendering until all exiting children have indeed left\n if (!exiting.size) {\n presentChildren.current = filteredChildren\n\n if (isMounted.current === false) return\n\n forceRender()\n onExitComplete?.()\n }\n }}\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n )\n })\n\n // Add `MotionContext` even to children that don't need it to ensure we're rendering\n // the same tree between renders\n childrenToRender = childrenToRender.map((child) => {\n const key = child.key as string | number\n return exiting.has(key) ? (\n child\n ) : (\n <PresenceChild\n key={getChildKey(child)}\n isPresent\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n )\n })\n\n if (process.env.NODE_ENV !== 'production' && exitBeforeEnter && childrenToRender.length > 1) {\n // eslint-disable-next-line no-console\n console.warn(\n `You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`\n )\n }\n\n return (\n <>{exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child))}</>\n )\n}\n\nAnimatePresence.displayName = 'AnimatePresence'\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": "AA4JM,mBAEI,WAFJ;AA5JN;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO;AAAA,EACL;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,0BAA0B;AACnC,SAAS,qBAAqB;AAG9B,MAAM;AAIN,MAAM,cAAc,CAAC,UAA2C,MAAM,OAAO;AAE7E,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAEvC,SAAS,kBACP,UACA,aACA;AACA,QAAM,eAAe,QAAQ,oBAAI,IAAkB,IAAI;AAEvD,WAAS,QAAQ,CAAC,UAAU;AAC1B,UAAM,MAAM,YAAY,KAAK;AAE7B,QAAI,SAAS,gBAAgB,aAAa,IAAI,GAAG,GAAG;AAElD,cAAQ,KAAK,qDAAqD,sBAAsB;AAExF,mBAAa,IAAI,GAAG;AAAA,IACtB;AAEA,gBAAY,IAAI,KAAK,KAAK;AAAA,EAC5B,CAAC;AACH;AAEA,SAAS,aAAa,UAA0C;AAC9D,QAAM,WAAgC,CAAC;AAGvC,WAAS,QAAQ,UAAU,CAAC,OAAO,UAAU;AAC3C,QAAI,eAAe,KAAK,GAAG;AACzB,UAAI,CAAC,MAAM,KAAK;AACd,YAAI,QAAQ,IAAI,aAAa,eAAe;AAE1C,kBAAQ,KAAK,+DAA+D;AAAA,QAC9E;AACA,iBAAS;AAAA,UACP,MAAM,aAAa,OAAO;AAAA,YACxB,KAAK;AAAA,UACP,CAAC;AAAA,QACH;AAAA,MACF,OAAO;AACL,iBAAS,KAAK,KAAK;AAAA,MACrB;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO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": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/LayoutGroupContext.tsx"],
|
|
4
4
|
"sourcesContent": ["import { createContext } from 'react'\n\nexport interface LayoutGroupContextProps {\n id?: string\n forceRender?: VoidFunction\n}\n\nexport const LayoutGroupContext = createContext<LayoutGroupContextProps>({})\n"],
|
|
5
|
-
"mappings": "AAAA;
|
|
5
|
+
"mappings": "AAAA,SAAS,qBAAqB;AAOvB,MAAM,qBAAqB,cAAuC,CAAC,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
1
2
|
import { useConstant, useId } from "@tamagui/core";
|
|
2
3
|
import * as React from "react";
|
|
3
4
|
import { PresenceContext } from "./PresenceContext";
|
|
@@ -12,37 +13,41 @@ const PresenceChild = ({
|
|
|
12
13
|
}) => {
|
|
13
14
|
const presenceChildren = useConstant(newChildrenMap);
|
|
14
15
|
const id = useId() || "";
|
|
15
|
-
const context = React.useMemo(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
const context = React.useMemo(
|
|
17
|
+
() => {
|
|
18
|
+
return {
|
|
19
|
+
id,
|
|
20
|
+
initial,
|
|
21
|
+
isPresent,
|
|
22
|
+
exitVariant,
|
|
23
|
+
enterVariant,
|
|
24
|
+
onExitComplete: (id2) => {
|
|
25
|
+
presenceChildren.set(id2, true);
|
|
26
|
+
for (const isComplete of presenceChildren.values()) {
|
|
27
|
+
if (!isComplete) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
27
30
|
}
|
|
31
|
+
onExitComplete == null ? void 0 : onExitComplete();
|
|
32
|
+
},
|
|
33
|
+
register: (id2) => {
|
|
34
|
+
presenceChildren.set(id2, false);
|
|
35
|
+
return () => presenceChildren.delete(id2);
|
|
28
36
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return () => presenceChildren.delete(id2);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
}, presenceAffectsLayout ? void 0 : [isPresent, exitVariant, enterVariant]);
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
presenceAffectsLayout ? void 0 : [isPresent, exitVariant, enterVariant]
|
|
40
|
+
);
|
|
37
41
|
React.useMemo(() => {
|
|
38
42
|
presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
|
|
39
43
|
}, [isPresent]);
|
|
40
44
|
React.useEffect(() => {
|
|
41
45
|
!isPresent && !presenceChildren.size && (onExitComplete == null ? void 0 : onExitComplete());
|
|
42
46
|
}, [isPresent]);
|
|
43
|
-
return /* @__PURE__ */
|
|
44
|
-
value: context
|
|
45
|
-
|
|
47
|
+
return /* @__PURE__ */ jsx(PresenceContext.Provider, {
|
|
48
|
+
value: context,
|
|
49
|
+
children
|
|
50
|
+
});
|
|
46
51
|
};
|
|
47
52
|
function newChildrenMap() {
|
|
48
53
|
return /* @__PURE__ */ new Map();
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/PresenceChild.tsx"],
|
|
4
4
|
"sourcesContent": ["import { useConstant, useId } from '@tamagui/core'\nimport * as React from 'react'\n\nimport { PresenceContext, PresenceContextProps } from './PresenceContext'\nimport { VariantLabels } from './types'\n\ninterface PresenceChildProps {\n children: React.ReactElement<any>\n isPresent: boolean\n onExitComplete?: () => void\n initial?: false | VariantLabels\n custom?: any\n presenceAffectsLayout: boolean\n exitVariant?: string | null\n enterVariant?: string | null\n}\n\nexport const PresenceChild = ({\n children,\n initial,\n isPresent,\n onExitComplete,\n exitVariant,\n enterVariant,\n presenceAffectsLayout,\n}: PresenceChildProps) => {\n const presenceChildren = useConstant(newChildrenMap)\n const id = useId() || ''\n\n const context = React.useMemo(\n (): PresenceContextProps => {\n return {\n id,\n initial,\n isPresent,\n exitVariant,\n enterVariant,\n onExitComplete: (id: string) => {\n presenceChildren.set(id, true)\n for (const isComplete of presenceChildren.values()) {\n if (!isComplete) {\n return // can stop searching when any is incomplete\n }\n }\n onExitComplete?.()\n },\n register: (id: string) => {\n presenceChildren.set(id, false)\n return () => presenceChildren.delete(id)\n },\n }\n },\n /**\n * If the presence of a child affects the layout of the components around it,\n * we want to make a new context value to ensure they get re-rendered\n * so they can detect that layout change.\n */\n // eslint-disable-next-line react-hooks/exhaustive-deps\n presenceAffectsLayout ? undefined : [isPresent, exitVariant, enterVariant]\n )\n\n React.useMemo(() => {\n presenceChildren.forEach((_, key) => presenceChildren.set(key, false))\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isPresent])\n\n /**\n * If there's no animated components to fire exit animations, we want to remove this\n * component immediately.\n */\n React.useEffect(() => {\n !isPresent && !presenceChildren.size && onExitComplete?.()\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isPresent])\n\n return <PresenceContext.Provider value={context}>{children}</PresenceContext.Provider>\n}\n\nfunction newChildrenMap(): Map<string, boolean> {\n return new Map()\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "AA2ES;AA3ET,SAAS,aAAa,aAAa;AACnC,YAAY,WAAW;AAEvB,SAAS,uBAA6C;AAc/C,MAAM,gBAAgB,CAAC;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA0B;AACxB,QAAM,mBAAmB,YAAY,cAAc;AACnD,QAAM,KAAK,MAAM,KAAK;AAEtB,QAAM,UAAU,MAAM;AAAA,IACpB,MAA4B;AAC1B,aAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,gBAAgB,CAACA,QAAe;AAC9B,2BAAiB,IAAIA,KAAI,IAAI;AAC7B,qBAAW,cAAc,iBAAiB,OAAO,GAAG;AAClD,gBAAI,CAAC,YAAY;AACf;AAAA,YACF;AAAA,UACF;AACA;AAAA,QACF;AAAA,QACA,UAAU,CAACA,QAAe;AACxB,2BAAiB,IAAIA,KAAI,KAAK;AAC9B,iBAAO,MAAM,iBAAiB,OAAOA,GAAE;AAAA,QACzC;AAAA,MACF;AAAA,IACF;AAAA,IAOA,wBAAwB,SAAY,CAAC,WAAW,aAAa,YAAY;AAAA,EAC3E;AAEA,QAAM,QAAQ,MAAM;AAClB,qBAAiB,QAAQ,CAAC,GAAG,QAAQ,iBAAiB,IAAI,KAAK,KAAK,CAAC;AAAA,EAEvE,GAAG,CAAC,SAAS,CAAC;AAMd,QAAM,UAAU,MAAM;AACpB,KAAC,aAAa,CAAC,iBAAiB,SAAQ;AAAA,EAE1C,GAAG,CAAC,SAAS,CAAC;AAEd,SAAO,oBAAC,gBAAgB,UAAhB;AAAA,IAAyB,OAAO;AAAA,IAAU;AAAA,GAAS;AAC7D;AAEA,SAAS,iBAAuC;AAC9C,SAAO,oBAAI,IAAI;AACjB;",
|
|
6
|
+
"names": ["id"]
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/PresenceContext.tsx"],
|
|
4
4
|
"sourcesContent": ["import { createContext } from 'react'\n\nimport { VariantLabels } from './types'\n\nexport interface PresenceContextProps {\n id: string\n isPresent: boolean\n register: (id: string) => () => void\n onExitComplete?: (id: string) => void\n initial?: false | VariantLabels\n custom?: any\n exitVariant?: string | null\n enterVariant?: string | null\n}\n\nexport const PresenceContext = createContext<PresenceContextProps | null>(null)\n"],
|
|
5
|
-
"mappings": "AAAA;
|
|
5
|
+
"mappings": "AAAA,SAAS,qBAAqB;AAevB,MAAM,kBAAkB,cAA2C,IAAI;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["export * from './AnimatePresence'\nexport * from './usePresence'\nexport { PresenceContext } from './PresenceContext'\n"],
|
|
5
|
-
"mappings": "AAAA;
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,SAAS,uBAAuB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/usePresence.ts"],
|
|
4
4
|
"sourcesContent": ["import { useId } from '@tamagui/core'\nimport { useContext, useEffect } from 'react'\n\nimport { PresenceContext, PresenceContextProps } from './PresenceContext'\n\nexport type SafeToRemove = () => void\ntype AlwaysPresent = [true, null]\ntype Present = [true]\ntype NotPresent = [false, SafeToRemove]\n\nexport function usePresence(): AlwaysPresent | Present | NotPresent {\n const context = useContext(PresenceContext)\n\n if (context === null) {\n return [true, null]\n }\n\n const { isPresent, onExitComplete, register } = context\n const id = useId() || ''\n useEffect(() => register(id), [id, register])\n\n const safeToRemove = () => onExitComplete?.(id)\n\n return !isPresent && onExitComplete ? [false, safeToRemove] : [true]\n}\n\n/**\n * Similar to `usePresence`, except `useIsPresent` simply returns whether or not the component is present.\n * There is no `safeToRemove` function. ```\n */\nexport function useIsPresent() {\n return isPresent(useContext(PresenceContext))\n}\n\nexport function isPresent(context: PresenceContextProps | null) {\n return context === null ? true : context.isPresent\n}\n"],
|
|
5
|
-
"mappings": "AAAA;
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AACtB,SAAS,YAAY,iBAAiB;AAEtC,SAAS,uBAA6C;AAO/C,SAAS,cAAoD;AAClE,QAAM,UAAU,WAAW,eAAe;AAE1C,MAAI,YAAY,MAAM;AACpB,WAAO,CAAC,MAAM,IAAI;AAAA,EACpB;AAEA,QAAM,EAAE,WAAAA,YAAW,gBAAgB,SAAS,IAAI;AAChD,QAAM,KAAK,MAAM,KAAK;AACtB,YAAU,MAAM,SAAS,EAAE,GAAG,CAAC,IAAI,QAAQ,CAAC;AAE5C,QAAM,eAAe,MAAM,iDAAiB;AAE5C,SAAO,CAACA,cAAa,iBAAiB,CAAC,OAAO,YAAY,IAAI,CAAC,IAAI;AACrE;AAMO,SAAS,eAAe;AAC7B,SAAO,UAAU,WAAW,eAAe,CAAC;AAC9C;AAEO,SAAS,UAAU,SAAsC;AAC9D,SAAO,YAAY,OAAO,OAAO,QAAQ;AAC3C;",
|
|
6
|
+
"names": ["isPresent"]
|
|
7
7
|
}
|
|
@@ -35,9 +35,11 @@ function onlyElements(children) {
|
|
|
35
35
|
if (process.env.NODE_ENV === "development") {
|
|
36
36
|
console.warn(`No key given to AnimatePresence child, assigning index as key`);
|
|
37
37
|
}
|
|
38
|
-
filtered.push(
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
filtered.push(
|
|
39
|
+
React.cloneElement(child, {
|
|
40
|
+
key: index
|
|
41
|
+
})
|
|
42
|
+
);
|
|
41
43
|
} else {
|
|
42
44
|
filtered.push(child);
|
|
43
45
|
}
|
|
@@ -98,26 +100,34 @@ const AnimatePresence = ({
|
|
|
98
100
|
if (!child)
|
|
99
101
|
return;
|
|
100
102
|
const insertionIndex = presentKeys.indexOf(key);
|
|
101
|
-
childrenToRender.splice(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
presentChildren.current
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
103
|
+
childrenToRender.splice(
|
|
104
|
+
insertionIndex,
|
|
105
|
+
0,
|
|
106
|
+
<PresenceChild key={getChildKey(child)} isPresent={false} onExitComplete={() => {
|
|
107
|
+
allChildren.delete(key);
|
|
108
|
+
exiting.delete(key);
|
|
109
|
+
const removeIndex = presentChildren.current.findIndex(
|
|
110
|
+
(presentChild) => presentChild.key === key
|
|
111
|
+
);
|
|
112
|
+
presentChildren.current.splice(removeIndex, 1);
|
|
113
|
+
if (!exiting.size) {
|
|
114
|
+
presentChildren.current = filteredChildren;
|
|
115
|
+
if (isMounted.current === false)
|
|
116
|
+
return;
|
|
117
|
+
forceRender();
|
|
118
|
+
onExitComplete?.();
|
|
119
|
+
}
|
|
120
|
+
}} exitVariant={exitVariant} enterVariant={enterVariant} presenceAffectsLayout={presenceAffectsLayout}>{child}</PresenceChild>
|
|
121
|
+
);
|
|
114
122
|
});
|
|
115
123
|
childrenToRender = childrenToRender.map((child) => {
|
|
116
124
|
const key = child.key;
|
|
117
125
|
return exiting.has(key) ? child : <PresenceChild key={getChildKey(child)} isPresent exitVariant={exitVariant} enterVariant={enterVariant} presenceAffectsLayout={presenceAffectsLayout}>{child}</PresenceChild>;
|
|
118
126
|
});
|
|
119
127
|
if (process.env.NODE_ENV !== "production" && exitBeforeEnter && childrenToRender.length > 1) {
|
|
120
|
-
console.warn(
|
|
128
|
+
console.warn(
|
|
129
|
+
`You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`
|
|
130
|
+
);
|
|
121
131
|
}
|
|
122
132
|
return <>{exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child))}</>;
|
|
123
133
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/AnimatePresence.tsx"],
|
|
4
4
|
"sourcesContent": ["import {\n useForceUpdate,\n useIsMounted,\n useIsomorphicLayoutEffect,\n useUnmountEffect,\n} from '@tamagui/core'\nimport React, {\n Children,\n ReactElement,\n ReactNode,\n cloneElement,\n isValidElement,\n useContext,\n useRef,\n} from 'react'\n\nimport { LayoutGroupContext } from './LayoutGroupContext'\nimport { PresenceChild } from './PresenceChild'\nimport { AnimatePresenceProps } from './types'\n\nReact['keep']\n\ntype ComponentKey = string | number\n\nconst getChildKey = (child: ReactElement<any>): ComponentKey => child.key || ''\n\nconst isDev = process.env.NODE_ENV !== 'production'\n\nfunction updateChildLookup(\n children: ReactElement<any>[],\n allChildren: Map<ComponentKey, ReactElement<any>>\n) {\n const seenChildren = isDev ? new Set<ComponentKey>() : null\n\n children.forEach((child) => {\n const key = getChildKey(child)\n\n if (isDev && seenChildren && seenChildren.has(key)) {\n // eslint-disable-next-line no-console\n console.warn(`Children of AnimatePresence require unique keys. \"${key}\" is a duplicate.`)\n\n seenChildren.add(key)\n }\n\n allChildren.set(key, child)\n })\n}\n\nfunction onlyElements(children: ReactNode): ReactElement<any>[] {\n const filtered: ReactElement<any>[] = []\n\n // We use forEach here instead of map as map mutates the component key by preprending `.$`\n Children.forEach(children, (child, index) => {\n if (isValidElement(child)) {\n if (!child.key) {\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn(`No key given to AnimatePresence child, assigning index as key`)\n }\n filtered.push(\n React.cloneElement(child, {\n key: index,\n })\n )\n } else {\n filtered.push(child)\n }\n }\n })\n\n return filtered\n}\n\n/**\n * `AnimatePresence` enables the animation of components that have been removed from the tree.\n *\n * When adding/removing more than a single child, every child **must** be given a unique `key` prop.\n *\n * Any `motion` components that have an `exit` property defined will animate out when removed from\n * the tree.\n *\n * ```tsx\n * import { motion, AnimatePresence } from 'framer-motion'\n *\n * export const Items = ({ items }) => (\n * <AnimatePresence>\n * {items.map(item => (\n * <motion.div\n * key={item.id}\n * initial={{ opacity: 0 }}\n * animate={{ opacity: 1 }}\n * exit={{ opacity: 0 }}\n * />\n * ))}\n * </AnimatePresence>\n * )\n * ```\n *\n * You can sequence exit animations throughout a tree using variants.\n *\n * If a child contains multiple `motion` components with `exit` props, it will only unmount the child\n * once all `motion` components have finished animating out. Likewise, any components using\n * `usePresence` all need to call `safeToRemove`.\n *\n * @public\n */\nexport const AnimatePresence: React.FunctionComponent<\n React.PropsWithChildren<AnimatePresenceProps>\n> = ({\n children,\n enterVariant,\n exitVariant,\n initial = true,\n onExitComplete,\n exitBeforeEnter,\n presenceAffectsLayout = true,\n}) => {\n // We want to force a re-render once all exiting animations have finished. We\n // either use a local forceRender function, or one from a parent context if it exists.\n let forceRender = useForceUpdate()\n const forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender\n if (forceRenderLayoutGroup) forceRender = forceRenderLayoutGroup\n\n const isMounted = useIsMounted()\n\n // Filter out any children that aren't ReactElements. We can only track ReactElements with a props.key\n const filteredChildren = onlyElements(children)\n let childrenToRender = filteredChildren\n\n const exiting = new Set<ComponentKey>()\n\n // Keep a living record of the children we're actually rendering so we\n // can diff to figure out which are entering and exiting\n const presentChildren = useRef(childrenToRender)\n\n // A lookup table to quickly reference components by key\n const allChildren = useRef(new Map<ComponentKey, ReactElement<any>>()).current\n\n // If this is the initial component render, just deal with logic surrounding whether\n // we play onMount animations or not.\n const isInitialRender = useRef(true)\n\n useIsomorphicLayoutEffect(() => {\n isInitialRender.current = false\n updateChildLookup(filteredChildren, allChildren)\n presentChildren.current = childrenToRender\n })\n\n useUnmountEffect(() => {\n isInitialRender.current = true\n allChildren.clear()\n exiting.clear()\n })\n\n if (isInitialRender.current) {\n return (\n <>\n {childrenToRender.map((child) => (\n <PresenceChild\n key={getChildKey(child)}\n isPresent\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n initial={initial ? undefined : false}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n ))}\n </>\n )\n }\n\n // If this is a subsequent render, deal with entering and exiting children\n childrenToRender = [...childrenToRender]\n\n // Diff the keys of the currently-present and target children to update our\n // exiting list.\n const presentKeys = presentChildren.current.map(getChildKey)\n const targetKeys = filteredChildren.map(getChildKey)\n\n // Diff the present children with our target children and mark those that are exiting\n const numPresent = presentKeys.length\n for (let i = 0; i < numPresent; i++) {\n const key = presentKeys[i]\n if (targetKeys.indexOf(key) === -1) {\n exiting.add(key)\n }\n }\n\n // If we currently have exiting children, and we're deferring rendering incoming children\n // until after all current children have exiting, empty the childrenToRender array\n if (exitBeforeEnter && exiting.size) {\n childrenToRender = []\n }\n\n // Loop through all currently exiting components and clone them to overwrite `animate`\n // with any `exit` prop they might have defined.\n exiting.forEach((key) => {\n // If this component is actually entering again, early return\n if (targetKeys.indexOf(key) !== -1) return\n\n const child = allChildren.get(key)\n if (!child) return\n\n const insertionIndex = presentKeys.indexOf(key)\n\n childrenToRender.splice(\n insertionIndex,\n 0,\n <PresenceChild\n key={getChildKey(child)}\n isPresent={false}\n onExitComplete={() => {\n allChildren.delete(key)\n exiting.delete(key)\n\n // Remove this child from the present children\n const removeIndex = presentChildren.current.findIndex(\n (presentChild) => presentChild.key === key\n )\n presentChildren.current.splice(removeIndex, 1)\n\n // Defer re-rendering until all exiting children have indeed left\n if (!exiting.size) {\n presentChildren.current = filteredChildren\n\n if (isMounted.current === false) return\n\n forceRender()\n onExitComplete?.()\n }\n }}\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n )\n })\n\n // Add `MotionContext` even to children that don't need it to ensure we're rendering\n // the same tree between renders\n childrenToRender = childrenToRender.map((child) => {\n const key = child.key as string | number\n return exiting.has(key) ? (\n child\n ) : (\n <PresenceChild\n key={getChildKey(child)}\n isPresent\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n )\n })\n\n if (process.env.NODE_ENV !== 'production' && exitBeforeEnter && childrenToRender.length > 1) {\n // eslint-disable-next-line no-console\n console.warn(\n `You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`\n )\n }\n\n return (\n <>{exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child))}</>\n )\n}\n\nAnimatePresence.displayName = 'AnimatePresence'\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,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A,CAAC,cACC,KAAK,YAAY,KAAK,GACtB,WAAW,OACX,gBAAgB,MAAM;AACpB,oBAAY,OAAO,GAAG;AACtB,gBAAQ,OAAO,GAAG;AAGlB,cAAM,cAAc,gBAAgB,QAAQ;AAAA,UAC1C,CAAC,iBAAiB,aAAa,QAAQ;AAAA,QACzC;AACA,wBAAgB,QAAQ,OAAO,aAAa,CAAC;AAG7C,YAAI,CAAC,QAAQ,MAAM;AACjB,0BAAgB,UAAU;AAE1B,cAAI,UAAU,YAAY;AAAO;AAEjC,sBAAY;AACZ,2BAAiB;AAAA,QACnB;AAAA,MACF,GACA,aAAa,aACb,cAAc,cACd,uBAAuB,wBAEtB,MACH,EA5BC;AAAA,IA6BH;AAAA,EACF,CAAC;AAID,qBAAmB,iBAAiB,IAAI,CAAC,UAAU;AACjD,UAAM,MAAM,MAAM;AAClB,WAAO,QAAQ,IAAI,GAAG,IACpB,QAEA,CAAC,cACC,KAAK,YAAY,KAAK,GACtB,UACA,aAAa,aACb,cAAc,cACd,uBAAuB,wBAEtB,MACH,EARC;AAAA,EAUL,CAAC;AAED,MAAI,QAAQ,IAAI,aAAa,gBAAgB,mBAAmB,iBAAiB,SAAS,GAAG;AAE3F,YAAQ;AAAA,MACN;AAAA,IACF;AAAA,EACF;AAEA,SACE,GAAG,QAAQ,OAAO,mBAAmB,iBAAiB,IAAI,CAAC,UAAU,aAAa,KAAK,CAAC,EAAE;AAE9F;AAEA,gBAAgB,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/LayoutGroupContext.tsx"],
|
|
4
4
|
"sourcesContent": ["import { createContext } from 'react'\n\nexport interface LayoutGroupContextProps {\n id?: string\n forceRender?: VoidFunction\n}\n\nexport const LayoutGroupContext = createContext<LayoutGroupContextProps>({})\n"],
|
|
5
|
-
"mappings": "AAAA;
|
|
5
|
+
"mappings": "AAAA,SAAS,qBAAqB;AAOvB,MAAM,qBAAqB,cAAuC,CAAC,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -12,28 +12,31 @@ const PresenceChild = ({
|
|
|
12
12
|
}) => {
|
|
13
13
|
const presenceChildren = useConstant(newChildrenMap);
|
|
14
14
|
const id = useId() || "";
|
|
15
|
-
const context = React.useMemo(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
const context = React.useMemo(
|
|
16
|
+
() => {
|
|
17
|
+
return {
|
|
18
|
+
id,
|
|
19
|
+
initial,
|
|
20
|
+
isPresent,
|
|
21
|
+
exitVariant,
|
|
22
|
+
enterVariant,
|
|
23
|
+
onExitComplete: (id2) => {
|
|
24
|
+
presenceChildren.set(id2, true);
|
|
25
|
+
for (const isComplete of presenceChildren.values()) {
|
|
26
|
+
if (!isComplete) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
27
29
|
}
|
|
30
|
+
onExitComplete?.();
|
|
31
|
+
},
|
|
32
|
+
register: (id2) => {
|
|
33
|
+
presenceChildren.set(id2, false);
|
|
34
|
+
return () => presenceChildren.delete(id2);
|
|
28
35
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return () => presenceChildren.delete(id2);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
}, presenceAffectsLayout ? void 0 : [isPresent, exitVariant, enterVariant]);
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
presenceAffectsLayout ? void 0 : [isPresent, exitVariant, enterVariant]
|
|
39
|
+
);
|
|
37
40
|
React.useMemo(() => {
|
|
38
41
|
presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
|
|
39
42
|
}, [isPresent]);
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/PresenceChild.tsx"],
|
|
4
4
|
"sourcesContent": ["import { useConstant, useId } from '@tamagui/core'\nimport * as React from 'react'\n\nimport { PresenceContext, PresenceContextProps } from './PresenceContext'\nimport { VariantLabels } from './types'\n\ninterface PresenceChildProps {\n children: React.ReactElement<any>\n isPresent: boolean\n onExitComplete?: () => void\n initial?: false | VariantLabels\n custom?: any\n presenceAffectsLayout: boolean\n exitVariant?: string | null\n enterVariant?: string | null\n}\n\nexport const PresenceChild = ({\n children,\n initial,\n isPresent,\n onExitComplete,\n exitVariant,\n enterVariant,\n presenceAffectsLayout,\n}: PresenceChildProps) => {\n const presenceChildren = useConstant(newChildrenMap)\n const id = useId() || ''\n\n const context = React.useMemo(\n (): PresenceContextProps => {\n return {\n id,\n initial,\n isPresent,\n exitVariant,\n enterVariant,\n onExitComplete: (id: string) => {\n presenceChildren.set(id, true)\n for (const isComplete of presenceChildren.values()) {\n if (!isComplete) {\n return // can stop searching when any is incomplete\n }\n }\n onExitComplete?.()\n },\n register: (id: string) => {\n presenceChildren.set(id, false)\n return () => presenceChildren.delete(id)\n },\n }\n },\n /**\n * If the presence of a child affects the layout of the components around it,\n * we want to make a new context value to ensure they get re-rendered\n * so they can detect that layout change.\n */\n // eslint-disable-next-line react-hooks/exhaustive-deps\n presenceAffectsLayout ? undefined : [isPresent, exitVariant, enterVariant]\n )\n\n React.useMemo(() => {\n presenceChildren.forEach((_, key) => presenceChildren.set(key, false))\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isPresent])\n\n /**\n * If there's no animated components to fire exit animations, we want to remove this\n * component immediately.\n */\n React.useEffect(() => {\n !isPresent && !presenceChildren.size && onExitComplete?.()\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isPresent])\n\n return <PresenceContext.Provider value={context}>{children}</PresenceContext.Provider>\n}\n\nfunction newChildrenMap(): Map<string, boolean> {\n return new Map()\n}\n"],
|
|
5
|
-
"mappings": "AAAA;
|
|
6
|
-
"names": []
|
|
5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["../../src/PresenceContext.tsx"],
|
|
4
4
|
"sourcesContent": ["import { createContext } from 'react'\n\nimport { VariantLabels } from './types'\n\nexport interface PresenceContextProps {\n id: string\n isPresent: boolean\n register: (id: string) => () => void\n onExitComplete?: (id: string) => void\n initial?: false | VariantLabels\n custom?: any\n exitVariant?: string | null\n enterVariant?: string | null\n}\n\nexport const PresenceContext = createContext<PresenceContextProps | null>(null)\n"],
|
|
5
|
-
"mappings": "AAAA;
|
|
5
|
+
"mappings": "AAAA,SAAS,qBAAqB;AAevB,MAAM,kBAAkB,cAA2C,IAAI;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/jsx/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["export * from './AnimatePresence'\nexport * from './usePresence'\nexport { PresenceContext } from './PresenceContext'\n"],
|
|
5
|
-
"mappings": "AAAA;
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,SAAS,uBAAuB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/usePresence.ts"],
|
|
4
4
|
"sourcesContent": ["import { useId } from '@tamagui/core'\nimport { useContext, useEffect } from 'react'\n\nimport { PresenceContext, PresenceContextProps } from './PresenceContext'\n\nexport type SafeToRemove = () => void\ntype AlwaysPresent = [true, null]\ntype Present = [true]\ntype NotPresent = [false, SafeToRemove]\n\nexport function usePresence(): AlwaysPresent | Present | NotPresent {\n const context = useContext(PresenceContext)\n\n if (context === null) {\n return [true, null]\n }\n\n const { isPresent, onExitComplete, register } = context\n const id = useId() || ''\n useEffect(() => register(id), [id, register])\n\n const safeToRemove = () => onExitComplete?.(id)\n\n return !isPresent && onExitComplete ? [false, safeToRemove] : [true]\n}\n\n/**\n * Similar to `usePresence`, except `useIsPresent` simply returns whether or not the component is present.\n * There is no `safeToRemove` function. ```\n */\nexport function useIsPresent() {\n return isPresent(useContext(PresenceContext))\n}\n\nexport function isPresent(context: PresenceContextProps | null) {\n return context === null ? true : context.isPresent\n}\n"],
|
|
5
|
-
"mappings": "AAAA;
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AACtB,SAAS,YAAY,iBAAiB;AAEtC,SAAS,uBAA6C;AAO/C,SAAS,cAAoD;AAClE,QAAM,UAAU,WAAW,eAAe;AAE1C,MAAI,YAAY,MAAM;AACpB,WAAO,CAAC,MAAM,IAAI;AAAA,EACpB;AAEA,QAAM,EAAE,WAAAA,YAAW,gBAAgB,SAAS,IAAI;AAChD,QAAM,KAAK,MAAM,KAAK;AACtB,YAAU,MAAM,SAAS,EAAE,GAAG,CAAC,IAAI,QAAQ,CAAC;AAE5C,QAAM,eAAe,MAAM,iBAAiB,EAAE;AAE9C,SAAO,CAACA,cAAa,iBAAiB,CAAC,OAAO,YAAY,IAAI,CAAC,IAAI;AACrE;AAMO,SAAS,eAAe;AAC7B,SAAO,UAAU,WAAW,eAAe,CAAC;AAC9C;AAEO,SAAS,UAAU,SAAsC;AAC9D,SAAO,YAAY,OAAO,OAAO,QAAQ;AAC3C;",
|
|
6
|
+
"names": ["isPresent"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/animate-presence",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.152",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@tamagui/core": "^1.0.1-beta.
|
|
17
|
+
"@tamagui/core": "^1.0.1-beta.152"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
20
|
+
"@tamagui/build": "^1.0.1-beta.152"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "tamagui-build",
|