@tamagui/adapt 2.0.0-rc.4 → 2.0.0-rc.40

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/src/Adapt.tsx CHANGED
@@ -8,10 +8,55 @@ import {
8
8
  import type { AllPlatforms, MediaQueryKey } from '@tamagui/core'
9
9
  import { createStyledContext, useMedia } from '@tamagui/core'
10
10
  import { withStaticProperties } from '@tamagui/helpers'
11
+ import { getPortal } from '@tamagui/native'
11
12
  import { PortalHost, PortalItem } from '@tamagui/portal'
12
13
  import { StackZIndexContext } from '@tamagui/z-index-stack'
13
14
  import React, { createContext, useContext, useId, useMemo } from 'react'
14
15
 
16
+ /**
17
+ * External store for passing children from AdaptPortalContents to Adapt.Contents
18
+ * when teleport is enabled. This bypasses PortalItem to avoid nested teleport
19
+ * (inner portal inside an already-teleported Sheet) which breaks touch
20
+ * coordinate mapping on iOS.
21
+ */
22
+ type AdaptChildrenStore = {
23
+ set(children: React.ReactNode): void
24
+ get(): React.ReactNode
25
+ subscribe(callback: () => void): () => void
26
+ }
27
+
28
+ function createAdaptChildrenStore(): AdaptChildrenStore {
29
+ let children: React.ReactNode = null
30
+ const listeners = new Set<() => void>()
31
+ return {
32
+ set(c) {
33
+ children = c
34
+ for (const l of listeners) l()
35
+ },
36
+ get: () => children,
37
+ subscribe(callback) {
38
+ listeners.add(callback)
39
+ return () => listeners.delete(callback)
40
+ },
41
+ }
42
+ }
43
+
44
+ const AdaptChildrenStoreContext = createContext<AdaptChildrenStore | null>(null)
45
+
46
+ const emptySubscribe = () => () => {}
47
+ const emptyGet = () => null
48
+
49
+ /** Renders adapt children from external store (used when teleport is enabled) */
50
+ function TeleportAdaptContents() {
51
+ const store = useContext(AdaptChildrenStoreContext)
52
+ const children = React.useSyncExternalStore(
53
+ store?.subscribe ?? emptySubscribe,
54
+ store?.get ?? emptyGet,
55
+ store?.get ?? emptyGet
56
+ )
57
+ return <>{children}</>
58
+ }
59
+
15
60
  /**
16
61
  * Interfaces
17
62
  */
@@ -26,7 +71,6 @@ export type AdaptParentContextI = {
26
71
  setPlatform: (when: AdaptPlatform) => any
27
72
  when: AdaptWhen
28
73
  setWhen: (when: AdaptWhen) => any
29
- setChildren: (children: any) => any
30
74
  portalName?: string
31
75
  lastScope?: string
32
76
  }
@@ -49,7 +93,6 @@ export const AdaptContext = createStyledContext<AdaptParentContextI>({
49
93
  platform: null as any,
50
94
  setPlatform: (x: AdaptPlatform) => {},
51
95
  when: null as any,
52
- setChildren: null as any,
53
96
  setWhen: () => {},
54
97
  })
55
98
 
@@ -102,13 +145,30 @@ export const AdaptParent = ({ children, Contents, scope, portal }: AdaptParentPr
102
145
  const id = useId()
103
146
  const portalName = `AdaptPortal${scope}${id}`
104
147
 
148
+ const childrenStoreRef = React.useRef<AdaptChildrenStore | null>(null)
149
+ if (!childrenStoreRef.current) {
150
+ childrenStoreRef.current = createAdaptChildrenStore()
151
+ }
152
+
153
+ const isTeleport =
154
+ process.env.TAMAGUI_TARGET === 'native' && getPortal().state.type === 'teleport'
155
+
105
156
  const FinalContents = useMemo(() => {
106
157
  if (Contents) {
107
158
  return Contents
108
159
  }
160
+
161
+ // When teleport is enabled, use store-based children passing to avoid
162
+ // nested teleport (inner PortalItem inside already-teleported Sheet)
163
+ // which breaks touch coordinate mapping on iOS.
164
+ if (isTeleport) {
165
+ return TeleportAdaptContents
166
+ }
167
+
109
168
  if (AdaptPortals.has(portalName)) {
110
169
  return AdaptPortals.get(portalName)
111
170
  }
171
+
112
172
  const element = () => {
113
173
  return (
114
174
  <PortalHost
@@ -118,38 +178,40 @@ export const AdaptParent = ({ children, Contents, scope, portal }: AdaptParentPr
118
178
  />
119
179
  )
120
180
  }
181
+
121
182
  AdaptPortals.set(portalName, element)
183
+
122
184
  return element
123
- }, [portalName, Contents])
185
+ }, [portalName, Contents, isTeleport])
124
186
 
125
187
  useIsomorphicLayoutEffect(() => {
126
- AdaptPortals.set(portalName, FinalContents)
127
- return () => {
128
- AdaptPortals.delete(portalName)
188
+ if (!isTeleport) {
189
+ AdaptPortals.set(portalName, FinalContents)
190
+ return () => {
191
+ AdaptPortals.delete(portalName)
192
+ }
129
193
  }
130
- }, [portalName])
194
+ }, [portalName, isTeleport])
131
195
 
132
196
  const [when, setWhen] = React.useState<AdaptWhen>(null)
133
197
  const [platform, setPlatform] = React.useState<AdaptPlatform>(null)
134
198
 
135
- // TODO for inline adapt
136
- const [children2, setChildren] = React.useState(null)
137
-
138
199
  return (
139
- <LastAdaptContextScope.Provider value={scope}>
140
- <ProvideAdaptContext
141
- Contents={FinalContents}
142
- when={when}
143
- platform={platform}
144
- setPlatform={setPlatform}
145
- setWhen={setWhen}
146
- setChildren={setChildren}
147
- portalName={portalName}
148
- scopeName={scope}
149
- >
150
- {children}
151
- </ProvideAdaptContext>
152
- </LastAdaptContextScope.Provider>
200
+ <AdaptChildrenStoreContext.Provider value={childrenStoreRef.current}>
201
+ <LastAdaptContextScope.Provider value={scope}>
202
+ <ProvideAdaptContext
203
+ Contents={FinalContents}
204
+ when={when}
205
+ platform={platform}
206
+ setPlatform={setPlatform}
207
+ setWhen={setWhen}
208
+ portalName={portalName}
209
+ scopeName={scope}
210
+ >
211
+ {children}
212
+ </ProvideAdaptContext>
213
+ </LastAdaptContextScope.Provider>
214
+ </AdaptChildrenStoreContext.Provider>
153
215
  )
154
216
  }
155
217
 
@@ -201,14 +263,6 @@ export const Adapt = withStaticProperties(
201
263
  output = children
202
264
  }
203
265
 
204
- // TODO this isn't ideal using an effect to set children, will cause double-renders
205
- // on every change
206
- useIsomorphicLayoutEffect(() => {
207
- if (typeof children === 'function' && output !== undefined) {
208
- context?.setChildren(output)
209
- }
210
- }, [output])
211
-
212
266
  return <StackZIndexContext>{!enabled ? null : output}</StackZIndexContext>
213
267
  },
214
268
  {
@@ -223,6 +277,20 @@ export const AdaptPortalContents = (props: {
223
277
  }) => {
224
278
  const isActive = useAdaptIsActive(props.scope)
225
279
  const { portalName } = useAdaptContext(props.scope)
280
+ const childrenStore = useContext(AdaptChildrenStoreContext)
281
+ const isTeleport = !isWeb && getPortal().state.type === 'teleport'
282
+
283
+ // When teleport is enabled, bypass PortalItem to avoid nested teleport
284
+ // (inner portal inside already-teleported Sheet) which breaks touch
285
+ // coordinate mapping on iOS. Children are passed via external store
286
+ // to TeleportAdaptContents rendered at Adapt.Contents.
287
+ if (isTeleport && childrenStore) {
288
+ return (
289
+ <AdaptPortalTeleport isActive={isActive} store={childrenStore}>
290
+ {props.children}
291
+ </AdaptPortalTeleport>
292
+ )
293
+ }
226
294
 
227
295
  return (
228
296
  <PortalItem passThrough={!isActive} hostName={portalName}>
@@ -231,6 +299,24 @@ export const AdaptPortalContents = (props: {
231
299
  )
232
300
  }
233
301
 
302
+ function AdaptPortalTeleport({
303
+ isActive,
304
+ store,
305
+ children,
306
+ }: {
307
+ isActive: boolean
308
+ store: AdaptChildrenStore
309
+ children: React.ReactNode
310
+ }) {
311
+ useIsomorphicLayoutEffect(() => {
312
+ if (!isActive) return
313
+ store.set(children)
314
+ return () => store.set(null)
315
+ })
316
+
317
+ return isActive ? null : <>{children}</>
318
+ }
319
+
234
320
  const useAdaptIsActiveGiven = ({
235
321
  when,
236
322
  platform,
package/types/Adapt.d.ts CHANGED
@@ -12,7 +12,6 @@ export type AdaptParentContextI = {
12
12
  setPlatform: (when: AdaptPlatform) => any;
13
13
  when: AdaptWhen;
14
14
  setWhen: (when: AdaptWhen) => any;
15
- setChildren: (children: any) => any;
16
15
  portalName?: string;
17
16
  lastScope?: string;
18
17
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Adapt.d.ts","sourceRoot":"","sources":["../src/Adapt.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAKhE,OAAO,KAAoD,MAAM,OAAO,CAAA;AAExE;;GAEG;AAEH,MAAM,MAAM,SAAS,GAAG,mBAAmB,GAAG,OAAO,GAAG,IAAI,CAAA;AA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M,CAAA;SAAE;;;CAiDnE,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,OAAO;IACzC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,4CAuBA,CAAA;AAqDD,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,YAG9C,CAAA"}
package/dist/cjs/Adapt.js DELETED
@@ -1,146 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: !0 });
9
- }, __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from == "object" || typeof from == "function")
11
- for (let key of __getOwnPropNames(from))
12
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- return to;
14
- };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
- mod
22
- )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
- var Adapt_exports = {};
24
- __export(Adapt_exports, {
25
- Adapt: () => Adapt,
26
- AdaptContents: () => AdaptContents,
27
- AdaptContext: () => AdaptContext,
28
- AdaptParent: () => AdaptParent,
29
- AdaptPortalContents: () => AdaptPortalContents,
30
- ProvideAdaptContext: () => ProvideAdaptContext,
31
- useAdaptContext: () => useAdaptContext,
32
- useAdaptIsActive: () => useAdaptIsActive
33
- });
34
- module.exports = __toCommonJS(Adapt_exports);
35
- var import_constants = require("@tamagui/constants"), import_core = require("@tamagui/core"), import_helpers = require("@tamagui/helpers"), import_portal = require("@tamagui/portal"), import_z_index_stack = require("@tamagui/z-index-stack"), import_react = __toESM(require("react"), 1), import_jsx_runtime = require("react/jsx-runtime");
36
- const AdaptContext = (0, import_core.createStyledContext)({
37
- Contents: null,
38
- scopeName: "",
39
- portalName: "",
40
- platform: null,
41
- setPlatform: (x) => {
42
- },
43
- when: null,
44
- setChildren: null,
45
- setWhen: () => {
46
- }
47
- }), LastAdaptContextScope = (0, import_react.createContext)(""), ProvideAdaptContext = ({
48
- children,
49
- ...context
50
- }) => {
51
- const scope = context.scopeName || "", lastScope = (0, import_react.useContext)(LastAdaptContextScope);
52
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LastAdaptContextScope.Provider, { value: lastScope || context.lastScope || "", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
53
- AdaptContext.Provider,
54
- {
55
- scope,
56
- lastScope: lastScope || context.lastScope,
57
- ...context,
58
- children
59
- }
60
- ) });
61
- }, useAdaptContext = (scope) => {
62
- const lastScope = (0, import_react.useContext)(LastAdaptContextScope), adaptScope = scope ?? lastScope;
63
- return AdaptContext.useStyledContext(adaptScope);
64
- }, AdaptPortals = /* @__PURE__ */ new Map(), AdaptParent = ({ children, Contents, scope, portal }) => {
65
- const id = (0, import_react.useId)(), portalName = `AdaptPortal${scope}${id}`, FinalContents = (0, import_react.useMemo)(() => {
66
- if (Contents)
67
- return Contents;
68
- if (AdaptPortals.has(portalName))
69
- return AdaptPortals.get(portalName);
70
- const element = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
71
- import_portal.PortalHost,
72
- {
73
- name: portalName,
74
- forwardProps: typeof portal == "boolean" ? void 0 : portal?.forwardProps
75
- },
76
- id
77
- );
78
- return AdaptPortals.set(portalName, element), element;
79
- }, [portalName, Contents]);
80
- (0, import_constants.useIsomorphicLayoutEffect)(() => (AdaptPortals.set(portalName, FinalContents), () => {
81
- AdaptPortals.delete(portalName);
82
- }), [portalName]);
83
- const [when, setWhen] = import_react.default.useState(null), [platform, setPlatform] = import_react.default.useState(null), [children2, setChildren] = import_react.default.useState(null);
84
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LastAdaptContextScope.Provider, { value: scope, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
85
- ProvideAdaptContext,
86
- {
87
- Contents: FinalContents,
88
- when,
89
- platform,
90
- setPlatform,
91
- setWhen,
92
- setChildren,
93
- portalName,
94
- scopeName: scope,
95
- children
96
- }
97
- ) });
98
- }, AdaptContents = ({ scope, ...rest }) => {
99
- const context = useAdaptContext(scope);
100
- if (!context?.Contents)
101
- throw new Error(
102
- process.env.NODE_ENV === "production" ? "tamagui.dev/docs/intro/errors#warning-002" : "You're rendering a Tamagui <Adapt /> component without nesting it inside a parent that is able to adapt."
103
- );
104
- return import_react.default.createElement(context.Contents, { ...rest, key: "stable" });
105
- };
106
- AdaptContents.shouldForwardSpace = !0;
107
- const Adapt = (0, import_helpers.withStaticProperties)(
108
- function(props) {
109
- const { platform, when, children, scope } = props, context = useAdaptContext(scope), enabled = useAdaptIsActiveGiven(props);
110
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
111
- context?.setWhen?.(when || enabled), context?.setPlatform?.(platform || null);
112
- }, [when, platform, enabled, context.setWhen, context.setPlatform]), (0, import_constants.useIsomorphicLayoutEffect)(() => () => {
113
- context?.setWhen?.(null), context?.setPlatform?.(null);
114
- }, []);
115
- let output;
116
- if (typeof children == "function") {
117
- const Component = context?.Contents;
118
- output = children(Component ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}) : null);
119
- } else
120
- output = children;
121
- return (0, import_constants.useIsomorphicLayoutEffect)(() => {
122
- typeof children == "function" && output !== void 0 && context?.setChildren(output);
123
- }, [output]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, { children: enabled ? output : null });
124
- },
125
- {
126
- Contents: AdaptContents
127
- }
128
- ), AdaptPortalContents = (props) => {
129
- const isActive = useAdaptIsActive(props.scope), { portalName } = useAdaptContext(props.scope);
130
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.PortalItem, { passThrough: !isActive, hostName: portalName, children: props.children });
131
- }, useAdaptIsActiveGiven = ({
132
- when,
133
- platform
134
- }) => {
135
- const media = (0, import_core.useMedia)();
136
- if (when == null && platform == null)
137
- return !1;
138
- if (when === !0)
139
- return !0;
140
- let enabled = !1;
141
- return platform === "touch" ? enabled = import_constants.isTouchable : platform === "native" ? enabled = !import_constants.isWeb : platform === "web" ? enabled = import_constants.isWeb : platform === "ios" ? enabled = import_constants.isIos : platform === "android" && (enabled = import_constants.isAndroid), platform && enabled == !1 ? !1 : (when && typeof when == "string" && (enabled = media[when]), enabled);
142
- }, useAdaptIsActive = (scope) => {
143
- const props = useAdaptContext(scope);
144
- return useAdaptIsActiveGiven(props);
145
- };
146
- //# sourceMappingURL=Adapt.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/Adapt.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAMO,+BAEP,cAA8C,0BAC9C,iBAAqC,6BACrC,gBAAuC,4BACvC,uBAAmC,mCACnC,eAAiE,8BAsD3D;AAtBC,MAAM,mBAAe,iCAAyC;AAAA,EACnE,UAAU;AAAA,EACV,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,aAAa,CAAC,MAAqB;AAAA,EAAC;AAAA,EACpC,MAAM;AAAA,EACN,aAAa;AAAA,EACb,SAAS,MAAM;AAAA,EAAC;AAClB,CAA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,MAAc;AAAA,EACvD;AAAA,EACA;AAAA,IACE,UAAU;AAAA,EACZ;AACF,GAEa,sBAAsB,CAAC,UAI9B;AACJ,QAAM,WAAW,iBAAiB,MAAM,KAAK,GACvC,EAAE,WAAW,IAAI,gBAAgB,MAAM,KAAK;AAElD,SACE,4CAAC,4BAAW,aAAa,CAAC,UAAU,UAAU,YAC3C,gBAAM,UACT;AAEJ,GAEM,wBAAwB,CAAC;AAAA,EAC7B;AAAA,EACA;AACF,MAA6C;AAC3C,QAAM,YAAQ,sBAAS;AAEvB,MAAI,QAAQ,QAAQ,YAAY;AAC9B,WAAO;AAGT,MAAI,SAAS;AACX,WAAO;AAGT,MAAI,UAAU;AAQd,SANI,aAAa,UAAS,UAAU,+BAC3B,aAAa,WAAU,UAAU,CAAC,yBAClC,aAAa,QAAO,UAAU,yBAC9B,aAAa,QAAO,UAAU,yBAC9B,aAAa,cAAW,UAAU,6BAEvC,YAAY,WAAW,KAClB,MAGL,QAAQ,OAAO,QAAS,aAC1B,UAAU,MAAM,IAAI,IAGf;AACT,GAEa,mBAAmB,CAAC,UAAmB;AAClD,QAAM,QAAQ,gBAAgB,KAAK;AACnC,SAAO,sBAAsB,KAAK;AACpC;",
5
- "names": ["React"]
6
- }
package/dist/cjs/index.js DELETED
@@ -1,15 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from == "object" || typeof from == "function")
7
- for (let key of __getOwnPropNames(from))
8
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
- return to;
10
- }, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
11
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
12
- var index_exports = {};
13
- module.exports = __toCommonJS(index_exports);
14
- __reExport(index_exports, require("./Adapt"), module.exports);
15
- //# sourceMappingURL=index.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/index.tsx"],
4
- "mappings": ";;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,oBAAd;",
5
- "names": []
6
- }
package/dist/esm/Adapt.js DELETED
@@ -1,134 +0,0 @@
1
- import {
2
- isAndroid,
3
- isIos,
4
- isTouchable,
5
- isWeb,
6
- useIsomorphicLayoutEffect
7
- } from "@tamagui/constants";
8
- import { createStyledContext, useMedia } from "@tamagui/core";
9
- import { withStaticProperties } from "@tamagui/helpers";
10
- import { PortalHost, PortalItem } from "@tamagui/portal";
11
- import { StackZIndexContext } from "@tamagui/z-index-stack";
12
- import React, { createContext, useContext, useId, useMemo } from "react";
13
- import { jsx } from "react/jsx-runtime";
14
- const AdaptContext = createStyledContext({
15
- Contents: null,
16
- scopeName: "",
17
- portalName: "",
18
- platform: null,
19
- setPlatform: (x) => {
20
- },
21
- when: null,
22
- setChildren: null,
23
- setWhen: () => {
24
- }
25
- }), LastAdaptContextScope = createContext(""), ProvideAdaptContext = ({
26
- children,
27
- ...context
28
- }) => {
29
- const scope = context.scopeName || "", lastScope = useContext(LastAdaptContextScope);
30
- return /* @__PURE__ */ jsx(LastAdaptContextScope.Provider, { value: lastScope || context.lastScope || "", children: /* @__PURE__ */ jsx(
31
- AdaptContext.Provider,
32
- {
33
- scope,
34
- lastScope: lastScope || context.lastScope,
35
- ...context,
36
- children
37
- }
38
- ) });
39
- }, useAdaptContext = (scope) => {
40
- const lastScope = useContext(LastAdaptContextScope), adaptScope = scope ?? lastScope;
41
- return AdaptContext.useStyledContext(adaptScope);
42
- }, AdaptPortals = /* @__PURE__ */ new Map(), AdaptParent = ({ children, Contents, scope, portal }) => {
43
- const id = useId(), portalName = `AdaptPortal${scope}${id}`, FinalContents = useMemo(() => {
44
- if (Contents)
45
- return Contents;
46
- if (AdaptPortals.has(portalName))
47
- return AdaptPortals.get(portalName);
48
- const element = () => /* @__PURE__ */ jsx(
49
- PortalHost,
50
- {
51
- name: portalName,
52
- forwardProps: typeof portal == "boolean" ? void 0 : portal?.forwardProps
53
- },
54
- id
55
- );
56
- return AdaptPortals.set(portalName, element), element;
57
- }, [portalName, Contents]);
58
- useIsomorphicLayoutEffect(() => (AdaptPortals.set(portalName, FinalContents), () => {
59
- AdaptPortals.delete(portalName);
60
- }), [portalName]);
61
- const [when, setWhen] = React.useState(null), [platform, setPlatform] = React.useState(null), [children2, setChildren] = React.useState(null);
62
- return /* @__PURE__ */ jsx(LastAdaptContextScope.Provider, { value: scope, children: /* @__PURE__ */ jsx(
63
- ProvideAdaptContext,
64
- {
65
- Contents: FinalContents,
66
- when,
67
- platform,
68
- setPlatform,
69
- setWhen,
70
- setChildren,
71
- portalName,
72
- scopeName: scope,
73
- children
74
- }
75
- ) });
76
- }, AdaptContents = ({ scope, ...rest }) => {
77
- const context = useAdaptContext(scope);
78
- if (!context?.Contents)
79
- throw new Error(
80
- process.env.NODE_ENV === "production" ? "tamagui.dev/docs/intro/errors#warning-002" : "You're rendering a Tamagui <Adapt /> component without nesting it inside a parent that is able to adapt."
81
- );
82
- return React.createElement(context.Contents, { ...rest, key: "stable" });
83
- };
84
- AdaptContents.shouldForwardSpace = !0;
85
- const Adapt = withStaticProperties(
86
- function(props) {
87
- const { platform, when, children, scope } = props, context = useAdaptContext(scope), enabled = useAdaptIsActiveGiven(props);
88
- useIsomorphicLayoutEffect(() => {
89
- context?.setWhen?.(when || enabled), context?.setPlatform?.(platform || null);
90
- }, [when, platform, enabled, context.setWhen, context.setPlatform]), useIsomorphicLayoutEffect(() => () => {
91
- context?.setWhen?.(null), context?.setPlatform?.(null);
92
- }, []);
93
- let output;
94
- if (typeof children == "function") {
95
- const Component = context?.Contents;
96
- output = children(Component ? /* @__PURE__ */ jsx(Component, {}) : null);
97
- } else
98
- output = children;
99
- return useIsomorphicLayoutEffect(() => {
100
- typeof children == "function" && output !== void 0 && context?.setChildren(output);
101
- }, [output]), /* @__PURE__ */ jsx(StackZIndexContext, { children: enabled ? output : null });
102
- },
103
- {
104
- Contents: AdaptContents
105
- }
106
- ), AdaptPortalContents = (props) => {
107
- const isActive = useAdaptIsActive(props.scope), { portalName } = useAdaptContext(props.scope);
108
- return /* @__PURE__ */ jsx(PortalItem, { passThrough: !isActive, hostName: portalName, children: props.children });
109
- }, useAdaptIsActiveGiven = ({
110
- when,
111
- platform
112
- }) => {
113
- const media = useMedia();
114
- if (when == null && platform == null)
115
- return !1;
116
- if (when === !0)
117
- return !0;
118
- let enabled = !1;
119
- return platform === "touch" ? enabled = isTouchable : platform === "native" ? enabled = !isWeb : platform === "web" ? enabled = isWeb : platform === "ios" ? enabled = isIos : platform === "android" && (enabled = isAndroid), platform && enabled == !1 ? !1 : (when && typeof when == "string" && (enabled = media[when]), enabled);
120
- }, useAdaptIsActive = (scope) => {
121
- const props = useAdaptContext(scope);
122
- return useAdaptIsActiveGiven(props);
123
- };
124
- export {
125
- Adapt,
126
- AdaptContents,
127
- AdaptContext,
128
- AdaptParent,
129
- AdaptPortalContents,
130
- ProvideAdaptContext,
131
- useAdaptContext,
132
- useAdaptIsActive
133
- };
134
- //# sourceMappingURL=Adapt.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/Adapt.tsx"],
4
- "mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,qBAAqB,gBAAgB;AAC9C,SAAS,4BAA4B;AACrC,SAAS,YAAY,kBAAkB;AACvC,SAAS,0BAA0B;AACnC,OAAO,SAAS,eAAe,YAAY,OAAO,eAAe;AAsD3D;AAtBC,MAAM,eAAe,oBAAyC;AAAA,EACnE,UAAU;AAAA,EACV,WAAW;AAAA,EACX,YAAY;AAAA,EACZ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