@tamagui/animate-presence 1.0.0-beta.187 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/cjs/AnimatePresence.js +47 -40
  2. package/dist/cjs/AnimatePresence.js.map +2 -2
  3. package/dist/cjs/AnimatePresenceContext.js +4 -0
  4. package/dist/cjs/AnimatePresenceContext.js.map +2 -2
  5. package/dist/cjs/LayoutGroupContext.js +4 -0
  6. package/dist/cjs/PresenceChild.js +30 -23
  7. package/dist/cjs/PresenceChild.js.map +2 -2
  8. package/dist/cjs/index.js +5 -1
  9. package/dist/cjs/index.js.map +1 -1
  10. package/dist/cjs/{usePresence.js → useEntering.js} +25 -19
  11. package/dist/cjs/useEntering.js.map +7 -0
  12. package/dist/esm/AnimatePresence.js +42 -43
  13. package/dist/esm/AnimatePresence.js.map +2 -2
  14. package/dist/esm/AnimatePresenceContext.js.map +2 -2
  15. package/dist/esm/PresenceChild.js +26 -23
  16. package/dist/esm/PresenceChild.js.map +2 -2
  17. package/dist/esm/index.js +1 -1
  18. package/dist/esm/index.js.map +1 -1
  19. package/dist/esm/useEntering.js +33 -0
  20. package/dist/esm/useEntering.js.map +7 -0
  21. package/dist/jsx/AnimatePresence.js +25 -30
  22. package/dist/jsx/PresenceChild.js +26 -23
  23. package/dist/jsx/index.js +1 -1
  24. package/dist/jsx/{usePresence.js → useEntering.js} +15 -15
  25. package/package.json +4 -4
  26. package/types/AnimatePresence.d.ts +4 -3
  27. package/types/AnimatePresence.d.ts.map +1 -1
  28. package/types/AnimatePresenceContext.d.ts +3 -2
  29. package/types/AnimatePresenceContext.d.ts.map +1 -1
  30. package/types/PresenceChild.d.ts +4 -3
  31. package/types/PresenceChild.d.ts.map +1 -1
  32. package/types/index.d.ts +1 -1
  33. package/types/useEntering.d.ts +6 -0
  34. package/types/useEntering.d.ts.map +1 -0
  35. package/dist/cjs/usePresence.js.map +0 -7
  36. package/dist/esm/usePresence.js +0 -33
  37. package/dist/esm/usePresence.js.map +0 -7
  38. package/types/usePresence.d.ts +0 -10
  39. package/types/usePresence.d.ts.map +0 -1
@@ -25,22 +25,22 @@ __export(AnimatePresence_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(AnimatePresence_exports);
27
27
  var import_core = require("@tamagui/core");
28
- var React = __toESM(require("react"));
29
- var import_react = require("react");
28
+ var import_react = __toESM(require("react"));
30
29
  var import_LayoutGroupContext = require("./LayoutGroupContext");
31
30
  var import_PresenceChild = require("./PresenceChild");
31
+ import_react.default["keep"];
32
32
  const getChildKey = /* @__PURE__ */ __name((child) => child.key || "", "getChildKey");
33
33
  const isDev = process.env.NODE_ENV !== "production";
34
34
  function updateChildLookup(children, allChildren) {
35
35
  const seenChildren = isDev ? /* @__PURE__ */ new Set() : null;
36
- for (const child of children) {
36
+ children.forEach((child) => {
37
37
  const key = getChildKey(child);
38
38
  if (isDev && seenChildren && seenChildren.has(key)) {
39
39
  console.warn(`Children of AnimatePresence require unique keys. "${key}" is a duplicate.`);
40
40
  seenChildren.add(key);
41
41
  }
42
42
  allChildren.set(key, child);
43
- }
43
+ });
44
44
  }
45
45
  __name(updateChildLookup, "updateChildLookup");
46
46
  function onlyElements(children) {
@@ -54,7 +54,8 @@ function onlyElements(children) {
54
54
  __name(onlyElements, "onlyElements");
55
55
  const AnimatePresence = /* @__PURE__ */ __name(({
56
56
  children,
57
- custom,
57
+ enterVariant,
58
+ exitVariant,
58
59
  initial = true,
59
60
  onExitComplete,
60
61
  exitBeforeEnter,
@@ -64,7 +65,10 @@ const AnimatePresence = /* @__PURE__ */ __name(({
64
65
  const forceRenderLayoutGroup = (0, import_react.useContext)(import_LayoutGroupContext.LayoutGroupContext).forceRender;
65
66
  if (forceRenderLayoutGroup)
66
67
  forceRender = forceRenderLayoutGroup;
67
- const isMounted = (0, import_core.useIsMounted)();
68
+ const [isMounted, setIsMounted] = (0, import_react.useState)(false);
69
+ (0, import_core.useIsomorphicLayoutEffect)(() => {
70
+ setIsMounted(true);
71
+ }, []);
68
72
  const filteredChildren = onlyElements(children);
69
73
  let childrenToRender = filteredChildren;
70
74
  const exiting = /* @__PURE__ */ new Set();
@@ -82,9 +86,11 @@ const AnimatePresence = /* @__PURE__ */ __name(({
82
86
  exiting.clear();
83
87
  });
84
88
  if (isInitialRender.current) {
85
- return /* @__PURE__ */ React.createElement(React.Fragment, null, childrenToRender.map((child) => /* @__PURE__ */ React.createElement(import_PresenceChild.PresenceChild, {
89
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, childrenToRender.map((child) => /* @__PURE__ */ import_react.default.createElement(import_PresenceChild.PresenceChild, {
86
90
  key: getChildKey(child),
87
- isPresent: true,
91
+ isEntering: true,
92
+ exitVariant,
93
+ enterVariant,
88
94
  initial: initial ? void 0 : false,
89
95
  presenceAffectsLayout
90
96
  }, child)));
@@ -102,48 +108,49 @@ const AnimatePresence = /* @__PURE__ */ __name(({
102
108
  if (exitBeforeEnter && exiting.size) {
103
109
  childrenToRender = [];
104
110
  }
105
- for (const key of exiting) {
106
- if (targetKeys.indexOf(key) !== -1) {
107
- continue;
108
- }
111
+ exiting.forEach((key) => {
112
+ if (targetKeys.indexOf(key) !== -1)
113
+ return;
109
114
  const child = allChildren.get(key);
110
- if (!child) {
111
- continue;
112
- }
115
+ if (!child)
116
+ return;
113
117
  const insertionIndex = presentKeys.indexOf(key);
114
- const onExit = /* @__PURE__ */ __name(() => {
115
- allChildren.delete(key);
116
- exiting.delete(key);
117
- const removeIndex = presentChildren.current.findIndex((presentChild) => presentChild.key === key);
118
- presentChildren.current.splice(removeIndex, 1);
119
- if (!exiting.size) {
120
- presentChildren.current = filteredChildren;
121
- if (isMounted.current === false) {
122
- return;
123
- }
124
- forceRender();
125
- onExitComplete == null ? void 0 : onExitComplete();
126
- }
127
- }, "onExit");
128
- childrenToRender.splice(insertionIndex, 0, /* @__PURE__ */ React.createElement(import_PresenceChild.PresenceChild, {
118
+ childrenToRender.splice(insertionIndex, 0, /* @__PURE__ */ import_react.default.createElement(import_PresenceChild.PresenceChild, {
129
119
  key: getChildKey(child),
130
- isPresent: false,
131
- onExitComplete: onExit,
132
- custom,
120
+ isEntering: false,
121
+ onExitComplete: () => {
122
+ allChildren.delete(key);
123
+ exiting.delete(key);
124
+ const removeIndex = presentChildren.current.findIndex((presentChild) => presentChild.key === key);
125
+ presentChildren.current.splice(removeIndex, 1);
126
+ if (!exiting.size) {
127
+ presentChildren.current = filteredChildren;
128
+ if (isMounted === false)
129
+ return;
130
+ forceRender();
131
+ onExitComplete == null ? void 0 : onExitComplete();
132
+ }
133
+ },
134
+ exitVariant,
135
+ enterVariant,
133
136
  presenceAffectsLayout
134
137
  }, child));
135
- }
138
+ });
136
139
  childrenToRender = childrenToRender.map((child) => {
137
140
  const key = child.key;
138
- return exiting.has(key) ? child : /* @__PURE__ */ React.createElement(import_PresenceChild.PresenceChild, {
141
+ return exiting.has(key) ? child : /* @__PURE__ */ import_react.default.createElement(import_PresenceChild.PresenceChild, {
139
142
  key: getChildKey(child),
140
- isPresent: true,
143
+ isEntering: void 0,
144
+ exitVariant,
145
+ enterVariant,
141
146
  presenceAffectsLayout
142
147
  }, child);
143
148
  });
144
- if (process.env.NODE_ENV !== "production" && exitBeforeEnter && childrenToRender.length > 1) {
145
- console.warn(`You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`);
146
- }
147
- return /* @__PURE__ */ React.createElement(React.Fragment, null, exiting.size ? childrenToRender : childrenToRender.map((child) => (0, import_react.cloneElement)(child)));
149
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, exiting.size ? childrenToRender : childrenToRender.map((child) => (0, import_react.cloneElement)(child)));
148
150
  }, "AnimatePresence");
151
+ AnimatePresence.displayName = "AnimatePresence";
152
+ // Annotate the CommonJS export names for ESM import in node:
153
+ 0 && (module.exports = {
154
+ AnimatePresence
155
+ });
149
156
  //# sourceMappingURL=AnimatePresence.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/AnimatePresence.tsx"],
4
- "sourcesContent": ["import {\n useForceUpdate,\n useIsMounted,\n useIsomorphicLayoutEffect,\n useUnmountEffect,\n} from '@tamagui/core'\nimport * as React from 'react'\nimport {\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'\n\nexport interface AnimatePresenceProps {\n /**\n * By passing `initial={false}`, `AnimatePresence` will disable any initial animations on children\n * that are present when the component is first rendered.\n */\n initial?: boolean\n\n /**\n * When a component is removed, there's no longer a chance to update its props. So if a component's `exit`\n * prop is defined as a dynamic variant and you want to pass a new `custom` prop, you can do so via `AnimatePresence`.\n * This will ensure all leaving components animate using the latest data.\n */\n custom?: any\n\n /**\n * Fires when all exiting nodes have completed animating out.\n */\n onExitComplete?: () => void\n\n /**\n * If set to `true`, `AnimatePresence` will only render one component at a time. The exiting component\n * will finish its exit animation before the entering component is rendered.\n */\n exitBeforeEnter?: boolean\n\n /**\n * Used in Framer to flag that sibling children *shouldn't* re-render as a result of a\n * child being removed.\n */\n presenceAffectsLayout?: boolean\n}\n\ntype ComponentKey = string | number\n\nconst getChildKey = (child: ReactElement<any>): ComponentKey => child.key || ''\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 for (const child of children) {\n const key = getChildKey(child)\n if (isDev && seenChildren && seenChildren.has(key)) {\n console.warn(`Children of AnimatePresence require unique keys. \"${key}\" is a duplicate.`)\n seenChildren.add(key)\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) => {\n if (isValidElement(child)) filtered.push(child)\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 animated components that have an `exit` property defined will animate out when removed from\n * the tree.\n *\n * ```jsx\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 animated components with `exit` props, it will only unmount the child\n * once all animated 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<AnimatePresenceProps> = ({\n children,\n custom,\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 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 for (const key of exiting) {\n // If this component is actually entering again, early return\n if (targetKeys.indexOf(key) !== -1) {\n continue\n }\n\n const child = allChildren.get(key)\n if (!child) {\n continue\n }\n\n const insertionIndex = presentKeys.indexOf(key)\n\n const onExit = () => {\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 if (isMounted.current === false) {\n return\n }\n forceRender()\n onExitComplete?.()\n }\n }\n\n childrenToRender.splice(\n insertionIndex,\n 0,\n <PresenceChild\n key={getChildKey(child)}\n isPresent={false}\n onExitComplete={onExit}\n custom={custom}\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 presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n )\n })\n\n if (process.env.NODE_ENV !== 'production' && exitBeforeEnter && childrenToRender.length > 1) {\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"],
5
- "mappings": "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",
4
+ "sourcesContent": ["import { useForceUpdate, useIsomorphicLayoutEffect, useUnmountEffect } from '@tamagui/core'\nimport React, {\n Children,\n ReactElement,\n ReactNode,\n cloneElement,\n isValidElement,\n useContext,\n useRef,\n useState,\n} from 'react'\n\nimport { LayoutGroupContext } from './LayoutGroupContext'\nimport { PresenceChild } from './PresenceChild'\n\nReact['keep']\n\nexport interface AnimatePresenceProps {\n /**\n * By passing `initial={false}`, `AnimatePresence` will disable any initial animations on children\n * that are present when the component is first rendered.\n */\n initial?: boolean\n\n /**\n * When a component is removed, there's no longer a chance to update its props. So if a component's `exit`\n * prop is defined as a dynamic variant and you want to pass a new `custom` prop, you can do so via `AnimatePresence`.\n * This will ensure all leaving components animate using the latest data.\n */\n exitVariant?: string | null\n\n enterVariant?: string | null\n\n /**\n * Fires when all exiting nodes have completed animating out.\n */\n onExitComplete?: () => void\n\n /**\n * If set to `true`, `AnimatePresence` will only render one component at a time. The exiting component\n * will finish its exit animation before the entering component is rendered.\n */\n exitBeforeEnter?: boolean\n\n /**\n * Used in Framer to flag that sibling children *shouldn't* re-render as a result of a\n * child being removed.\n */\n presenceAffectsLayout?: boolean\n}\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 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) => {\n if (isValidElement(child)) filtered.push(child)\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 * ```jsx\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 * `useEntering` 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, setIsMounted] = useState(false)\n\n useIsomorphicLayoutEffect(() => {\n setIsMounted(true)\n }, [])\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 isEntering\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\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 isEntering={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 === 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 isEntering={undefined}\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 // 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": "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",
6
6
  "names": []
7
7
  }
@@ -22,4 +22,8 @@ __export(AnimatePresenceContext_exports, {
22
22
  module.exports = __toCommonJS(AnimatePresenceContext_exports);
23
23
  var import_react = require("react");
24
24
  const AnimatePresenceContext = (0, import_react.createContext)(null);
25
+ // Annotate the CommonJS export names for ESM import in node:
26
+ 0 && (module.exports = {
27
+ AnimatePresenceContext
28
+ });
25
29
  //# sourceMappingURL=AnimatePresenceContext.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/AnimatePresenceContext.tsx"],
4
- "sourcesContent": ["import { createContext } from 'react'\n\nimport { VariantLabels } from './types'\n\nexport interface AnimatePresenceContextProps {\n id: string\n isPresent: boolean\n register: (id: string) => () => void\n onExitComplete?: (id: string) => void\n initial?: false | VariantLabels\n custom?: any\n}\n\nexport const AnimatePresenceContext = createContext<AnimatePresenceContextProps | null>(null)\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;AAavB,MAAM,yBAAyB,gCAAkD,IAAI;",
4
+ "sourcesContent": ["import { createContext } from 'react'\n\nimport { VariantLabels } from './types'\n\nexport interface AnimatePresenceContextProps {\n id: string\n isEntering: boolean | undefined\n register: (id: string) => () => void\n onExitComplete?: (id: string) => void\n initial?: false | VariantLabels\n exitVariant?: string | null\n enterVariant?: string | null\n}\n\nexport const AnimatePresenceContext = createContext<AnimatePresenceContextProps | null>(null)\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;AAcvB,MAAM,yBAAyB,gCAAkD,IAAI;",
6
6
  "names": []
7
7
  }
@@ -22,4 +22,8 @@ __export(LayoutGroupContext_exports, {
22
22
  module.exports = __toCommonJS(LayoutGroupContext_exports);
23
23
  var import_react = require("react");
24
24
  const LayoutGroupContext = (0, import_react.createContext)({});
25
+ // Annotate the CommonJS export names for ESM import in node:
26
+ 0 && (module.exports = {
27
+ LayoutGroupContext
28
+ });
25
29
  //# sourceMappingURL=LayoutGroupContext.js.map
@@ -31,41 +31,44 @@ var import_AnimatePresenceContext = require("./AnimatePresenceContext");
31
31
  const PresenceChild = /* @__PURE__ */ __name(({
32
32
  children,
33
33
  initial,
34
- isPresent,
34
+ isEntering,
35
35
  onExitComplete,
36
- custom,
36
+ exitVariant,
37
+ enterVariant,
37
38
  presenceAffectsLayout
38
39
  }) => {
39
40
  const presenceChildren = (0, import_core.useConstant)(newChildrenMap);
40
41
  const id = (0, import_utils.useId)();
41
- const context = React.useMemo(() => ({
42
- id,
43
- initial,
44
- isPresent,
45
- custom,
46
- onExitComplete: (childId) => {
47
- presenceChildren.set(childId, true);
48
- for (const isComplete of presenceChildren.values()) {
49
- if (!isComplete) {
50
- return;
42
+ const context = React.useMemo(() => {
43
+ return {
44
+ id,
45
+ initial,
46
+ isEntering,
47
+ exitVariant,
48
+ enterVariant,
49
+ onExitComplete: (childId) => {
50
+ presenceChildren.set(childId, true);
51
+ for (const isComplete of presenceChildren.values()) {
52
+ if (!isComplete) {
53
+ return;
54
+ }
51
55
  }
56
+ onExitComplete == null ? void 0 : onExitComplete();
57
+ },
58
+ register: (childId) => {
59
+ presenceChildren.set(childId, false);
60
+ return () => presenceChildren.delete(childId);
52
61
  }
53
- onExitComplete == null ? void 0 : onExitComplete();
54
- },
55
- register: (childId) => {
56
- presenceChildren.set(childId, false);
57
- return () => presenceChildren.delete(childId);
58
- }
59
- }), presenceAffectsLayout ? void 0 : [isPresent]);
62
+ };
63
+ }, presenceAffectsLayout ? void 0 : [isEntering, onExitComplete, exitVariant, enterVariant]);
60
64
  React.useMemo(() => {
61
65
  presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
62
- }, [isPresent]);
66
+ }, [isEntering]);
63
67
  React.useEffect(() => {
64
- if (!isPresent && !presenceChildren.size) {
65
- console.log("on exit complete");
68
+ if (isEntering === false && !presenceChildren.size) {
66
69
  onExitComplete == null ? void 0 : onExitComplete();
67
70
  }
68
- }, [isPresent]);
71
+ }, [isEntering]);
69
72
  return /* @__PURE__ */ React.createElement(import_AnimatePresenceContext.AnimatePresenceContext.Provider, {
70
73
  value: context
71
74
  }, children);
@@ -74,4 +77,8 @@ function newChildrenMap() {
74
77
  return /* @__PURE__ */ new Map();
75
78
  }
76
79
  __name(newChildrenMap, "newChildrenMap");
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ PresenceChild
83
+ });
77
84
  //# sourceMappingURL=PresenceChild.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/PresenceChild.tsx"],
4
- "sourcesContent": ["import { useId } from '@react-aria/utils'\nimport { useConstant } from '@tamagui/core'\nimport * as React from 'react'\n\nimport { AnimatePresenceContext, AnimatePresenceContextProps } from './AnimatePresenceContext'\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}\n\nexport const PresenceChild = ({\n children,\n initial,\n isPresent,\n onExitComplete,\n custom,\n presenceAffectsLayout,\n}: PresenceChildProps) => {\n const presenceChildren = useConstant(newChildrenMap)\n const id = useId()\n\n const context = React.useMemo(\n (): AnimatePresenceContextProps => ({\n id,\n initial,\n isPresent,\n custom,\n onExitComplete: (childId: string) => {\n presenceChildren.set(childId, 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: (childId: string) => {\n presenceChildren.set(childId, false)\n return () => presenceChildren.delete(childId)\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 presenceAffectsLayout ? undefined : [isPresent]\n )\n\n // cant this be a useEffect?\n React.useMemo(() => {\n presenceChildren.forEach((_, key) => presenceChildren.set(key, false))\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 if (!isPresent && !presenceChildren.size) {\n console.log('on exit complete')\n onExitComplete?.()\n }\n }, [isPresent])\n\n return (\n <AnimatePresenceContext.Provider value={context}>{children}</AnimatePresenceContext.Provider>\n )\n}\n\nfunction newChildrenMap(): Map<string, boolean> {\n return new Map()\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AACtB,kBAA4B;AAC5B,YAAuB;AAEvB,oCAAoE;AAY7D,MAAM,gBAAgB,wBAAC;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MACwB;AACxB,QAAM,mBAAmB,6BAAY,cAAc;AACnD,QAAM,KAAK,wBAAM;AAEjB,QAAM,UAAU,MAAM,QACpB,MAAoC;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB,CAAC,YAAoB;AACnC,uBAAiB,IAAI,SAAS,IAAI;AAClC,iBAAW,cAAc,iBAAiB,OAAO,GAAG;AAClD,YAAI,CAAC,YAAY;AACf;AAAA,QACF;AAAA,MACF;AACA;AAAA,IACF;AAAA,IACA,UAAU,CAAC,YAAoB;AAC7B,uBAAiB,IAAI,SAAS,KAAK;AACnC,aAAO,MAAM,iBAAiB,OAAO,OAAO;AAAA,IAC9C;AAAA,EACF,IAMA,wBAAwB,SAAY,CAAC,SAAS,CAChD;AAGA,QAAM,QAAQ,MAAM;AAClB,qBAAiB,QAAQ,CAAC,GAAG,QAAQ,iBAAiB,IAAI,KAAK,KAAK,CAAC;AAAA,EACvE,GAAG,CAAC,SAAS,CAAC;AAMd,QAAM,UAAU,MAAM;AACpB,QAAI,CAAC,aAAa,CAAC,iBAAiB,MAAM;AACxC,cAAQ,IAAI,kBAAkB;AAC9B;AAAA,IACF;AAAA,EACF,GAAG,CAAC,SAAS,CAAC;AAEd,SACE,oCAAC,qDAAuB,UAAvB;AAAA,IAAgC,OAAO;AAAA,KAAU,QAAS;AAE/D,GA1D6B;AA4D7B,0BAAgD;AAC9C,SAAO,oBAAI,IAAI;AACjB;AAFS;",
4
+ "sourcesContent": ["import { useId } from '@react-aria/utils'\nimport { useConstant } from '@tamagui/core'\nimport * as React from 'react'\n\nimport { AnimatePresenceContext, AnimatePresenceContextProps } from './AnimatePresenceContext'\nimport { VariantLabels } from './types'\n\ninterface PresenceChildProps {\n children: React.ReactElement<any>\n isEntering: boolean | undefined\n onExitComplete?: () => void\n initial?: false | VariantLabels\n exitVariant?: string | null\n enterVariant?: string | null\n presenceAffectsLayout: boolean\n}\n\nexport const PresenceChild = ({\n children,\n initial,\n isEntering,\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 (): AnimatePresenceContextProps => {\n return {\n id,\n initial,\n isEntering,\n exitVariant,\n enterVariant,\n onExitComplete: (childId: string) => {\n presenceChildren.set(childId, 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: (childId: string) => {\n presenceChildren.set(childId, false)\n return () => presenceChildren.delete(childId)\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 presenceAffectsLayout ? undefined : [isEntering, onExitComplete, exitVariant, enterVariant]\n )\n\n // cant this be a useEffect?\n React.useMemo(() => {\n presenceChildren.forEach((_, key) => presenceChildren.set(key, false))\n }, [isEntering])\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 if (isEntering === false && !presenceChildren.size) {\n onExitComplete?.()\n }\n }, [isEntering])\n\n return (\n <AnimatePresenceContext.Provider value={context}>{children}</AnimatePresenceContext.Provider>\n )\n}\n\nfunction newChildrenMap(): Map<string, boolean> {\n return new Map()\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AACtB,kBAA4B;AAC5B,YAAuB;AAEvB,oCAAoE;AAa7D,MAAM,gBAAgB,wBAAC;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MACwB;AACxB,QAAM,mBAAmB,6BAAY,cAAc;AACnD,QAAM,KAAK,wBAAM;AAEjB,QAAM,UAAU,MAAM,QACpB,MAAmC;AACjC,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,gBAAgB,CAAC,YAAoB;AACnC,yBAAiB,IAAI,SAAS,IAAI;AAClC,mBAAW,cAAc,iBAAiB,OAAO,GAAG;AAClD,cAAI,CAAC,YAAY;AACf;AAAA,UACF;AAAA,QACF;AACA;AAAA,MACF;AAAA,MACA,UAAU,CAAC,YAAoB;AAC7B,yBAAiB,IAAI,SAAS,KAAK;AACnC,eAAO,MAAM,iBAAiB,OAAO,OAAO;AAAA,MAC9C;AAAA,IACF;AAAA,EACF,GAMA,wBAAwB,SAAY,CAAC,YAAY,gBAAgB,aAAa,YAAY,CAC5F;AAGA,QAAM,QAAQ,MAAM;AAClB,qBAAiB,QAAQ,CAAC,GAAG,QAAQ,iBAAiB,IAAI,KAAK,KAAK,CAAC;AAAA,EACvE,GAAG,CAAC,UAAU,CAAC;AAMf,QAAM,UAAU,MAAM;AACpB,QAAI,eAAe,SAAS,CAAC,iBAAiB,MAAM;AAClD;AAAA,IACF;AAAA,EACF,GAAG,CAAC,UAAU,CAAC;AAEf,SACE,oCAAC,qDAAuB,UAAvB;AAAA,IAAgC,OAAO;AAAA,KAAU,QAAS;AAE/D,GA7D6B;AA+D7B,0BAAgD;AAC9C,SAAO,oBAAI,IAAI;AACjB;AAFS;",
6
6
  "names": []
7
7
  }
package/dist/cjs/index.js CHANGED
@@ -22,6 +22,10 @@ __export(src_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(src_exports);
24
24
  __reExport(src_exports, require("./AnimatePresence"), module.exports);
25
- __reExport(src_exports, require("./usePresence"), module.exports);
25
+ __reExport(src_exports, require("./useEntering"), module.exports);
26
26
  var import_AnimatePresenceContext = require("./AnimatePresenceContext");
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ AnimatePresenceContext
30
+ });
27
31
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export * from './AnimatePresence'\nexport * from './usePresence'\nexport { AnimatePresenceContext } from './AnimatePresenceContext'\n"],
4
+ "sourcesContent": ["export * from './AnimatePresence'\nexport * from './useEntering'\nexport { AnimatePresenceContext } from './AnimatePresenceContext'\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,8BAAd;AACA,wBAAc,0BADd;AAEA,oCAAuC;",
6
6
  "names": []
7
7
  }
@@ -16,36 +16,42 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var usePresence_exports = {};
20
- __export(usePresence_exports, {
21
- isPresent: () => isPresent,
22
- useIsPresent: () => useIsPresent,
23
- usePresence: () => usePresence
19
+ var useEntering_exports = {};
20
+ __export(useEntering_exports, {
21
+ isEntering: () => isEntering,
22
+ useEntering: () => useEntering,
23
+ useIsEntering: () => useIsEntering
24
24
  });
25
- module.exports = __toCommonJS(usePresence_exports);
25
+ module.exports = __toCommonJS(useEntering_exports);
26
26
  var import_utils = require("@react-aria/utils");
27
27
  var import_react = require("react");
28
28
  var import_AnimatePresenceContext = require("./AnimatePresenceContext");
29
- function usePresence() {
29
+ function useEntering() {
30
30
  const context = (0, import_react.useContext)(import_AnimatePresenceContext.AnimatePresenceContext);
31
31
  if (context === null) {
32
- return [true, null];
32
+ return [void 0, void 0];
33
33
  }
34
- const { isPresent: isPresent2, onExitComplete, register } = context;
34
+ const { isEntering: isEntering2, onExitComplete, register } = context;
35
35
  const id = (0, import_utils.useId)();
36
+ const safeToRemove = /* @__PURE__ */ __name(() => onExitComplete == null ? void 0 : onExitComplete(id), "safeToRemove");
36
37
  (0, import_react.useEffect)(() => {
37
38
  register(id);
38
39
  }, []);
39
- const safeToRemove = /* @__PURE__ */ __name(() => onExitComplete == null ? void 0 : onExitComplete(id), "safeToRemove");
40
- return !isPresent2 ? [false, safeToRemove] : [true];
40
+ return isEntering2 === false ? [false, safeToRemove] : isEntering2 === true ? [true, safeToRemove] : [void 0, safeToRemove];
41
41
  }
42
- __name(usePresence, "usePresence");
43
- function useIsPresent() {
44
- return isPresent((0, import_react.useContext)(import_AnimatePresenceContext.AnimatePresenceContext));
42
+ __name(useEntering, "useEntering");
43
+ function useIsEntering() {
44
+ return isEntering((0, import_react.useContext)(import_AnimatePresenceContext.AnimatePresenceContext));
45
45
  }
46
- __name(useIsPresent, "useIsPresent");
47
- function isPresent(context) {
48
- return context === null ? true : context.isPresent;
46
+ __name(useIsEntering, "useIsEntering");
47
+ function isEntering(context) {
48
+ return context === null ? void 0 : context.isEntering;
49
49
  }
50
- __name(isPresent, "isPresent");
51
- //# sourceMappingURL=usePresence.js.map
50
+ __name(isEntering, "isEntering");
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ isEntering,
54
+ useEntering,
55
+ useIsEntering
56
+ });
57
+ //# sourceMappingURL=useEntering.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/useEntering.ts"],
4
+ "sourcesContent": ["import { useId } from '@react-aria/utils'\nimport { useContext, useEffect } from 'react'\n\nimport { AnimatePresenceContext, AnimatePresenceContextProps } from './AnimatePresenceContext'\n\nexport type SafeToRemove = () => void\n\nexport function useEntering(): [boolean | undefined, undefined | (() => void)] {\n const context = useContext(AnimatePresenceContext)\n\n if (context === null) {\n return [undefined, undefined]\n }\n\n const { isEntering, onExitComplete, register } = context\n // Replace with useId when released in React\n const id = useId()\n const safeToRemove = () => onExitComplete?.(id)\n\n // It's safe to call the following hooks conditionally (after an early return) because the context will always\n // either be null or non-null for the lifespan of the component.\n\n useEffect(() => {\n register(id)\n }, [])\n\n return isEntering === false\n ? [false, safeToRemove]\n : isEntering === true\n ? [true, safeToRemove]\n : [undefined, safeToRemove]\n}\n\n/**\n * Similar to `useEntering`, except `useIsEntering` simply returns whether or not the component is present.\n * There is no `safeToRemove` function. ```\n */\nexport function useIsEntering() {\n return isEntering(useContext(AnimatePresenceContext))\n}\n\nexport function isEntering(context: AnimatePresenceContextProps | null) {\n return context === null ? undefined : context.isEntering\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AACtB,mBAAsC;AAEtC,oCAAoE;AAI7D,uBAAwE;AAC7E,QAAM,UAAU,6BAAW,oDAAsB;AAEjD,MAAI,YAAY,MAAM;AACpB,WAAO,CAAC,QAAW,MAAS;AAAA,EAC9B;AAEA,QAAM,EAAE,yBAAY,gBAAgB,aAAa;AAEjD,QAAM,KAAK,wBAAM;AACjB,QAAM,eAAe,6BAAM,iDAAiB,KAAvB;AAKrB,8BAAU,MAAM;AACd,aAAS,EAAE;AAAA,EACb,GAAG,CAAC,CAAC;AAEL,SAAO,gBAAe,QAClB,CAAC,OAAO,YAAY,IACpB,gBAAe,OACf,CAAC,MAAM,YAAY,IACnB,CAAC,QAAW,YAAY;AAC9B;AAxBgB;AA8BT,yBAAyB;AAC9B,SAAO,WAAW,6BAAW,oDAAsB,CAAC;AACtD;AAFgB;AAIT,oBAAoB,SAA6C;AACtE,SAAO,YAAY,OAAO,SAAY,QAAQ;AAChD;AAFgB;",
6
+ "names": []
7
+ }
@@ -1,33 +1,29 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- import {
4
- useForceUpdate,
5
- useIsMounted,
6
- useIsomorphicLayoutEffect,
7
- useUnmountEffect
8
- } from "@tamagui/core";
9
- import * as React from "react";
10
- import {
3
+ import { useForceUpdate, useIsomorphicLayoutEffect, useUnmountEffect } from "@tamagui/core";
4
+ import React, {
11
5
  Children,
12
6
  cloneElement,
13
7
  isValidElement,
14
8
  useContext,
15
- useRef
9
+ useRef,
10
+ useState
16
11
  } from "react";
17
12
  import { LayoutGroupContext } from "./LayoutGroupContext";
18
13
  import { PresenceChild } from "./PresenceChild";
14
+ React["keep"];
19
15
  const getChildKey = /* @__PURE__ */ __name((child) => child.key || "", "getChildKey");
20
16
  const isDev = process.env.NODE_ENV !== "production";
21
17
  function updateChildLookup(children, allChildren) {
22
18
  const seenChildren = isDev ? /* @__PURE__ */ new Set() : null;
23
- for (const child of children) {
19
+ children.forEach((child) => {
24
20
  const key = getChildKey(child);
25
21
  if (isDev && seenChildren && seenChildren.has(key)) {
26
22
  console.warn(`Children of AnimatePresence require unique keys. "${key}" is a duplicate.`);
27
23
  seenChildren.add(key);
28
24
  }
29
25
  allChildren.set(key, child);
30
- }
26
+ });
31
27
  }
32
28
  __name(updateChildLookup, "updateChildLookup");
33
29
  function onlyElements(children) {
@@ -41,7 +37,8 @@ function onlyElements(children) {
41
37
  __name(onlyElements, "onlyElements");
42
38
  const AnimatePresence = /* @__PURE__ */ __name(({
43
39
  children,
44
- custom,
40
+ enterVariant,
41
+ exitVariant,
45
42
  initial = true,
46
43
  onExitComplete,
47
44
  exitBeforeEnter,
@@ -51,7 +48,10 @@ const AnimatePresence = /* @__PURE__ */ __name(({
51
48
  const forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender;
52
49
  if (forceRenderLayoutGroup)
53
50
  forceRender = forceRenderLayoutGroup;
54
- const isMounted = useIsMounted();
51
+ const [isMounted, setIsMounted] = useState(false);
52
+ useIsomorphicLayoutEffect(() => {
53
+ setIsMounted(true);
54
+ }, []);
55
55
  const filteredChildren = onlyElements(children);
56
56
  let childrenToRender = filteredChildren;
57
57
  const exiting = /* @__PURE__ */ new Set();
@@ -71,7 +71,9 @@ const AnimatePresence = /* @__PURE__ */ __name(({
71
71
  if (isInitialRender.current) {
72
72
  return /* @__PURE__ */ React.createElement(React.Fragment, null, childrenToRender.map((child) => /* @__PURE__ */ React.createElement(PresenceChild, {
73
73
  key: getChildKey(child),
74
- isPresent: true,
74
+ isEntering: true,
75
+ exitVariant,
76
+ enterVariant,
75
77
  initial: initial ? void 0 : false,
76
78
  presenceAffectsLayout
77
79
  }, child)));
@@ -89,50 +91,47 @@ const AnimatePresence = /* @__PURE__ */ __name(({
89
91
  if (exitBeforeEnter && exiting.size) {
90
92
  childrenToRender = [];
91
93
  }
92
- for (const key of exiting) {
93
- if (targetKeys.indexOf(key) !== -1) {
94
- continue;
95
- }
94
+ exiting.forEach((key) => {
95
+ if (targetKeys.indexOf(key) !== -1)
96
+ return;
96
97
  const child = allChildren.get(key);
97
- if (!child) {
98
- continue;
99
- }
98
+ if (!child)
99
+ return;
100
100
  const insertionIndex = presentKeys.indexOf(key);
101
- const onExit = /* @__PURE__ */ __name(() => {
102
- allChildren.delete(key);
103
- exiting.delete(key);
104
- const removeIndex = presentChildren.current.findIndex((presentChild) => presentChild.key === key);
105
- presentChildren.current.splice(removeIndex, 1);
106
- if (!exiting.size) {
107
- presentChildren.current = filteredChildren;
108
- if (isMounted.current === false) {
109
- return;
110
- }
111
- forceRender();
112
- onExitComplete == null ? void 0 : onExitComplete();
113
- }
114
- }, "onExit");
115
101
  childrenToRender.splice(insertionIndex, 0, /* @__PURE__ */ React.createElement(PresenceChild, {
116
102
  key: getChildKey(child),
117
- isPresent: false,
118
- onExitComplete: onExit,
119
- custom,
103
+ isEntering: false,
104
+ onExitComplete: () => {
105
+ allChildren.delete(key);
106
+ exiting.delete(key);
107
+ const removeIndex = presentChildren.current.findIndex((presentChild) => presentChild.key === key);
108
+ presentChildren.current.splice(removeIndex, 1);
109
+ if (!exiting.size) {
110
+ presentChildren.current = filteredChildren;
111
+ if (isMounted === false)
112
+ return;
113
+ forceRender();
114
+ onExitComplete == null ? void 0 : onExitComplete();
115
+ }
116
+ },
117
+ exitVariant,
118
+ enterVariant,
120
119
  presenceAffectsLayout
121
120
  }, child));
122
- }
121
+ });
123
122
  childrenToRender = childrenToRender.map((child) => {
124
123
  const key = child.key;
125
124
  return exiting.has(key) ? child : /* @__PURE__ */ React.createElement(PresenceChild, {
126
125
  key: getChildKey(child),
127
- isPresent: true,
126
+ isEntering: void 0,
127
+ exitVariant,
128
+ enterVariant,
128
129
  presenceAffectsLayout
129
130
  }, child);
130
131
  });
131
- if (process.env.NODE_ENV !== "production" && exitBeforeEnter && childrenToRender.length > 1) {
132
- console.warn(`You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`);
133
- }
134
132
  return /* @__PURE__ */ React.createElement(React.Fragment, null, exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child)));
135
133
  }, "AnimatePresence");
134
+ AnimatePresence.displayName = "AnimatePresence";
136
135
  export {
137
136
  AnimatePresence
138
137
  };