@tamagui/adapt 1.106.0 → 1.108.0-1722728147390

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/Adapt.js CHANGED
@@ -1,7 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
5
6
  var __export = (target, all) => {
6
7
  for (var name in all)
7
8
  __defProp(target, name, { get: all[name], enumerable: !0 });
@@ -11,7 +12,14 @@ var __export = (target, all) => {
11
12
  !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
13
  return to;
13
14
  };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
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);
15
23
  var Adapt_exports = {};
16
24
  __export(Adapt_exports, {
17
25
  Adapt: () => Adapt,
@@ -20,22 +28,22 @@ __export(Adapt_exports, {
20
28
  useAdaptParent: () => useAdaptParent
21
29
  });
22
30
  module.exports = __toCommonJS(Adapt_exports);
23
- var import_constants = require("@tamagui/constants"), import_constants2 = require("@tamagui/constants"), import_core = require("@tamagui/core"), import_helpers = require("@tamagui/helpers"), import_react = require("react"), import_jsx_runtime = require("react/jsx-runtime");
24
- const AdaptParentContext = (0, import_react.createContext)(null), AdaptContents = (props) => {
25
- const context = (0, import_react.useContext)(AdaptParentContext);
31
+ var import_react = __toESM(require("react")), import_constants = require("@tamagui/constants"), import_core = require("@tamagui/core"), import_helpers = require("@tamagui/helpers"), import_jsx_runtime = require("react/jsx-runtime");
32
+ const AdaptParentContext = import_react.default.createContext(null), AdaptContents = (props) => {
33
+ const context = import_react.default.useContext(AdaptParentContext);
26
34
  if (!context?.Contents)
27
35
  throw new Error(
28
36
  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."
29
37
  );
30
- return (0, import_react.createElement)(context.Contents, props);
38
+ return import_react.default.createElement(context.Contents, props);
31
39
  };
32
40
  AdaptContents.shouldForwardSpace = !0;
33
41
  const useAdaptParent = ({
34
42
  Contents
35
43
  }) => {
36
- const [when, setWhen] = (0, import_react.useState)(null);
44
+ const [when, setWhen] = import_react.default.useState(null);
37
45
  return {
38
- AdaptProvider: (0, import_react.useMemo)(() => {
46
+ AdaptProvider: import_react.default.useMemo(() => {
39
47
  const context = {
40
48
  Contents,
41
49
  setWhen
@@ -49,11 +57,11 @@ const useAdaptParent = ({
49
57
  };
50
58
  }, Adapt = (0, import_helpers.withStaticProperties)(
51
59
  function({ platform, when, children }) {
52
- const context = (0, import_react.useContext)(AdaptParentContext), media = (0, import_core.useMedia)();
53
- let enabled = !platform;
54
- return platform === "touch" && (enabled = import_constants2.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), when && !media[when] && (enabled = !1), (0, import_constants.useIsomorphicLayoutEffect)(() => {
60
+ const context = import_react.default.useContext(AdaptParentContext), media = (0, import_core.useMedia)();
61
+ let enabled = !1;
62
+ return typeof when == "function" ? enabled = when({ media }) : (enabled = !platform, 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), when && !media[when] && (enabled = !1)), (0, import_constants.useIsomorphicLayoutEffect)(() => {
55
63
  enabled && context?.setWhen(when || enabled);
56
- }, [when, context, enabled]), enabled ? children : null;
64
+ }, [when, context, enabled]), enabled ? typeof children == "function" ? children({ enabled, media }) : children : null;
57
65
  },
58
66
  {
59
67
  Contents: AdaptContents
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Adapt.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmE,+BACnEA,oBAA4B,+BAE5B,cAAyB,0BACzB,iBAAqC,6BACrC,eAOO,kBAkDC;AAhCD,MAAM,yBAAqB,4BAA0C,IAAI,GAGnE,gBAAgB,CAAC,UAAe;AAC3C,QAAM,cAAU,yBAAW,kBAAkB;AAC7C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR,QAAQ,IAAI,aAAa,eACrB,8CACA;AAAA,IACN;AAEF,aAAO,4BAAc,QAAQ,UAAU,KAAK;AAC9C;AAEA,cAAc,qBAAqB;AAE5B,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AACF,MAEM;AACJ,QAAM,CAAC,MAAM,OAAO,QAAI,uBAAe,IAAI;AAmB3C,SAAO;AAAA,IACL,mBAlBoB,sBAAQ,MAAM;AAClC,YAAM,UAA+B;AAAA,QACnC;AAAA,QACA;AAAA,MACF;AAEA,eAAS,kBAAkB,OAA2B;AACpD,eACE,4CAAC,mBAAmB,UAAnB,EAA4B,OAAO,SACjC,gBAAM,UACT;AAAA,MAEJ;AAEA,aAAO;AAAA,IACT,GAAG,CAAC,QAAQ,C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QACA;AAAA,MACF;AAEA,eAAS,kBAAkB,OAA2B;AACpD,eACE,4CAAC,mBAAmB,UAAnB,EAA4B,OAAO,SACjC,gBAAM,UACT;AAAA,MAEJ;AAEA,aAAO;AAAA,IACT,GAAG,CAAC,QAAQ,CAAC;AAAA,IAIX;AAAA,EACF;AACF,GAEa,YAAQ;AAAA,EACnB,SAAe,EAAE,UAAU,MAAM,SAAS,GAAe;AACvD,UAAM,UAAU,aAAAA,QAAM,WAAW,kBAAkB,GAC7C,YAAQ,sBAAS;AAEvB,QAAI,UAAU;AAuBd,WArBI,OAAO,QAAS,aAClB,UAAU,KAAK,EAAE,MAAM,CAAC,KAExB,UAAU,CAAC,UAEP,aAAa,YAAS,UAAU,+BAChC,aAAa,aAAU,UAAU,CAAC,yBAClC,aAAa,UAAO,UAAU,yBAC9B,aAAa,UAAO,UAAU,yBAC9B,aAAa,cAAW,UAAU,6BAElC,QAAQ,CAAC,MAAM,IAAI,MACrB,UAAU,UAId,4CAA0B,MAAM;AAC9B,MAAK,WACL,SAAS,QAAS,QAAQ,OAAgB;AAAA,IAC5C,GAAG,CAAC,MAAM,SAAS,OAAO,CAAC,GAEtB,UAID,OAAO,YAAa,aACf,SAAS,EAAE,SAAS,MAAM,CAAC,IAG7B,WAPE;AAAA,EAQX;AAAA,EACA;AAAA,IACE,UAAU;AAAA,EACZ;AACF;",
5
+ "names": ["React"]
6
6
  }
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: !0 });
@@ -12,7 +13,14 @@ var __export = (target, all) => {
12
13
  !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
14
  return to;
14
15
  };
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
22
+ mod
23
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
16
24
  var Adapt_exports = {};
17
25
  __export(Adapt_exports, {
18
26
  Adapt: () => Adapt,
@@ -21,7 +29,7 @@ __export(Adapt_exports, {
21
29
  useAdaptParent: () => useAdaptParent
22
30
  });
23
31
  module.exports = __toCommonJS(Adapt_exports);
24
- var import_jsx_runtime = require("react/jsx-runtime"), import_constants = require("@tamagui/constants"), import_constants2 = require("@tamagui/constants"), import_core = require("@tamagui/core"), import_helpers = require("@tamagui/helpers"), import_react = require("react");
32
+ var import_jsx_runtime = require("react/jsx-runtime"), import_react = __toESM(require("react")), import_constants = require("@tamagui/constants"), import_core = require("@tamagui/core"), import_helpers = require("@tamagui/helpers");
25
33
  function _array_like_to_array(arr, len) {
26
34
  (len == null || len > arr.length) && (len = arr.length);
27
35
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
@@ -63,15 +71,15 @@ function _unsupported_iterable_to_array(o, minLen) {
63
71
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
64
72
  }
65
73
  }
66
- var AdaptParentContext = /* @__PURE__ */ (0, import_react.createContext)(null), AdaptContents = function(props) {
67
- var context = (0, import_react.useContext)(AdaptParentContext);
74
+ var AdaptParentContext = /* @__PURE__ */ import_react.default.createContext(null), AdaptContents = function(props) {
75
+ var context = import_react.default.useContext(AdaptParentContext);
68
76
  if (!(context != null && context.Contents))
69
77
  throw new Error(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.");
70
- return /* @__PURE__ */ (0, import_react.createElement)(context.Contents, props);
78
+ return /* @__PURE__ */ import_react.default.createElement(context.Contents, props);
71
79
  };
72
80
  AdaptContents.shouldForwardSpace = !0;
73
81
  var useAdaptParent = function(param) {
74
- var Contents = param.Contents, _useState = _sliced_to_array((0, import_react.useState)(null), 2), when = _useState[0], setWhen = _useState[1], AdaptProvider = (0, import_react.useMemo)(function() {
82
+ var Contents = param.Contents, _React_useState = _sliced_to_array(import_react.default.useState(null), 2), when = _React_useState[0], setWhen = _React_useState[1], AdaptProvider = import_react.default.useMemo(function() {
75
83
  var AdaptProviderView = function(props) {
76
84
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AdaptParentContext.Provider, {
77
85
  value: context,
@@ -90,14 +98,19 @@ var useAdaptParent = function(param) {
90
98
  when
91
99
  };
92
100
  }, Adapt = (0, import_helpers.withStaticProperties)(function(param) {
93
- var platform = param.platform, when = param.when, children = param.children, context = (0, import_react.useContext)(AdaptParentContext), media = (0, import_core.useMedia)(), enabled = !platform;
94
- return platform === "touch" && (enabled = import_constants2.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), when && !media[when] && (enabled = !1), (0, import_constants.useIsomorphicLayoutEffect)(function() {
101
+ var platform = param.platform, when = param.when, children = param.children, context = import_react.default.useContext(AdaptParentContext), media = (0, import_core.useMedia)(), enabled = !1;
102
+ return typeof when == "function" ? enabled = when({
103
+ media
104
+ }) : (enabled = !platform, 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), when && !media[when] && (enabled = !1)), (0, import_constants.useIsomorphicLayoutEffect)(function() {
95
105
  enabled && (context == null || context.setWhen(when || enabled));
96
106
  }, [
97
107
  when,
98
108
  context,
99
109
  enabled
100
- ]), enabled ? children : null;
110
+ ]), enabled ? typeof children == "function" ? children({
111
+ enabled,
112
+ media
113
+ }) : children : null;
101
114
  }, {
102
115
  Contents: AdaptContents
103
116
  });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Users/n8/tamagui/code/ui/adapt/src/Adapt.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;uDAAA,mBAAmE,+BACnEA,oBAA4B,+BAE5B,cAAyB,0BACzB,iBAAqC,6BACrC,eAOO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,IAAMC,qBAAqBC,gDAA0C,IAAA,GAG/DC,gBAAgB,SAACC,OAAAA;AAC5B,MAAMC,cAAUC,yBAAWL,kBAAAA;AAC3B,MAAI,EAACI,WAAAA,QAAAA,QAASE;AACZ,UAAM,IAAIC,MACRC,QAAQC,IAAIC,aAAa,eACpB,8CACA,0GAAA;AAGT,SAAOC,gDAAcP,QAAQE,UAAUH,KAAAA;AACzC;AAEAD,cAAcU,qBAAqB;AAE5B,IAAMC,iBAAiB,SAAA,OAAA;MAC5BP,WAAAA,MAAAA,UAIwBQ,YAAAA,qBAAAA,uBAAe,IAAA,GAAA,CAAA,GAAhCC,OAAiBD,UAAAA,CAAAA,GAAXE,UAAWF,UAAAA,CAAAA,GAElBG,oBAAgBC,sBAAQ,WAAA;QAMnBC,oBAAT,SAA2BhB,OAAyB;AAClD,aACE,uCAAAiB,KAACpB,mBAAmBqB,UAAQ;QAACC,OAAOlB;kBACjCD,MAAMoB;;IAGb,GAXMnB,UAA+B;MACnCE;MACAU;IACF;AAUA,WAAOG;EACT,GAAG;IAACb;GAAS;AAEb,SAAO;IACLW;IACAF;EACF;AACF,GAEaS,YAAQC,qCACnB,SAAe,OAAwC;MAAtCC,WAAF,MAAEA,UAAUX,OAAZ,MAAYA,MAAMQ,WAAlB,MAAkBA,UACzBnB,cAAUC,yBAAWL,kBAAAA,GACrB2B,YAAQC,sBAAAA,GAEVC,UAAU,CAACH;AAgBf,SAfIA,aAAa,YAASG,UAAUC,gCAChCJ,aAAa,aAAUG,UAAU,CAACE,yBAClCL,aAAa,UAAOG,UAAUE,yBAC9BL,aAAa,UAAOG,UAAUG,yBAC9BN,aAAa,cAAWG,UAAUI,6BAElClB,QAAQ,CAACY,MAAMZ,IAAAA,MACjBc,UAAU,SAGZK,4CAA0B,WAAA;AACxB,IAAKL,YACLzB,WAAAA,QAAAA,QAASY,QAASD,QAAQc,OAAAA;EAC5B,GAAG;IAACd;IAAMX;IAASyB;GAAQ,GAEtBA,UAIEN,WAHE;AAIX,GACA;EACEjB,UAAUJ;AACZ,CAAA;",
5
- "names": ["import_constants", "AdaptParentContext", "createContext", "AdaptContents", "props", "context", "useContext", "Contents", "Error", "process", "env", "NODE_ENV", "createElement", "shouldForwardSpace", "useAdaptParent", "useState", "when", "setWhen", "AdaptProvider", "useMemo", "AdaptProviderView", "_jsx", "Provider", "value", "children", "Adapt", "withStaticProperties", "platform", "media", "useMedia", "enabled", "isTouchable", "isWeb", "isIos", "isAndroid", "useIsomorphicLayoutEffect"]
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uDAAA,eAAkB,2BAClB,mBAMO,+BAEP,cAAyB,0BACzB,iBAAqC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoB9B,IAAMA,qBAAqBC,6BAAAA,QAAMC,cAA0C,IAAA,GAGrEC,gBAAgB,SAACC,OAAAA;AAC5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QAASD,QAAQc,OAAAA;EAC5B,GAAG;IAACd;IAAMX;IAASyB;GAAQ,GAEtBA,UAID,OAAON,YAAa,aACfA,SAAS;IAAEM;IAASF;EAAM,CAAA,IAG5BJ,WAPE;AAQX,GACA;EACEjB,UAAUJ;AACZ,CAAA;",
5
+ "names": ["AdaptParentContext", "React", "createContext", "AdaptContents", "props", "context", "useContext", "Contents", "Error", "process", "env", "NODE_ENV", "createElement", "shouldForwardSpace", "useAdaptParent", "useState", "when", "setWhen", "AdaptProvider", "useMemo", "AdaptProviderView", "_jsx", "Provider", "value", "children", "Adapt", "withStaticProperties", "platform", "media", "useMedia", "enabled", "isTouchable", "isWeb", "isIos", "isAndroid", "useIsomorphicLayoutEffect"]
6
6
  }
package/dist/esm/Adapt.js CHANGED
@@ -1,30 +1,29 @@
1
- import { isAndroid, isIos, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
2
- import { isTouchable } from "@tamagui/constants";
1
+ import React from "react";
2
+ import {
3
+ isAndroid,
4
+ isIos,
5
+ isTouchable,
6
+ isWeb,
7
+ useIsomorphicLayoutEffect
8
+ } from "@tamagui/constants";
3
9
  import { useMedia } from "@tamagui/core";
4
10
  import { withStaticProperties } from "@tamagui/helpers";
5
- import {
6
- createContext,
7
- createElement,
8
- useContext,
9
- useMemo,
10
- useState
11
- } from "react";
12
11
  import { jsx } from "react/jsx-runtime";
13
- const AdaptParentContext = createContext(null), AdaptContents = (props) => {
14
- const context = useContext(AdaptParentContext);
12
+ const AdaptParentContext = React.createContext(null), AdaptContents = (props) => {
13
+ const context = React.useContext(AdaptParentContext);
15
14
  if (!context?.Contents)
16
15
  throw new Error(
17
16
  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."
18
17
  );
19
- return createElement(context.Contents, props);
18
+ return React.createElement(context.Contents, props);
20
19
  };
21
20
  AdaptContents.shouldForwardSpace = !0;
22
21
  const useAdaptParent = ({
23
22
  Contents
24
23
  }) => {
25
- const [when, setWhen] = useState(null);
24
+ const [when, setWhen] = React.useState(null);
26
25
  return {
27
- AdaptProvider: useMemo(() => {
26
+ AdaptProvider: React.useMemo(() => {
28
27
  const context = {
29
28
  Contents,
30
29
  setWhen
@@ -38,11 +37,11 @@ const useAdaptParent = ({
38
37
  };
39
38
  }, Adapt = withStaticProperties(
40
39
  function({ platform, when, children }) {
41
- const context = useContext(AdaptParentContext), media = useMedia();
42
- let enabled = !platform;
43
- return platform === "touch" && (enabled = isTouchable), platform === "native" && (enabled = !isWeb), platform === "web" && (enabled = isWeb), platform === "ios" && (enabled = isIos), platform === "android" && (enabled = isAndroid), when && !media[when] && (enabled = !1), useIsomorphicLayoutEffect(() => {
40
+ const context = React.useContext(AdaptParentContext), media = useMedia();
41
+ let enabled = !1;
42
+ return typeof when == "function" ? enabled = when({ media }) : (enabled = !platform, platform === "touch" && (enabled = isTouchable), platform === "native" && (enabled = !isWeb), platform === "web" && (enabled = isWeb), platform === "ios" && (enabled = isIos), platform === "android" && (enabled = isAndroid), when && !media[when] && (enabled = !1)), useIsomorphicLayoutEffect(() => {
44
43
  enabled && context?.setWhen(when || enabled);
45
- }, [when, context, enabled]), enabled ? children : null;
44
+ }, [when, context, enabled]), enabled ? typeof children == "function" ? children({ enabled, media }) : children : null;
46
45
  },
47
46
  {
48
47
  Contents: AdaptContents
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Adapt.tsx"],
4
- "mappings": "AAAA,SAAS,WAAW,OAAO,OAAO,iCAAiC;AACnE,SAAS,mBAAmB;AAE5B,SAAS,gBAAgB;AACzB,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAkDC;AAhCD,MAAM,qBAAqB,cAA0C,IAAI,GAGnE,gBAAgB,CAAC,UAAe;AAC3C,QAAM,UAAU,WAAW,kBAAkB;AAC7C,M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AAA,IACE,UAAU;AAAA,EACZ;AACF;",
5
5
  "names": []
6
6
  }
@@ -1,22 +1,21 @@
1
- import { isAndroid, isIos, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
2
- import { isTouchable } from "@tamagui/constants";
1
+ import React from "react";
2
+ import { isAndroid, isIos, isTouchable, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
3
3
  import { useMedia } from "@tamagui/core";
4
4
  import { withStaticProperties } from "@tamagui/helpers";
5
- import { createContext, createElement, useContext, useMemo, useState } from "react";
6
5
  import { jsx } from "react/jsx-runtime";
7
- const AdaptParentContext = createContext(null),
6
+ const AdaptParentContext = React.createContext(null),
8
7
  AdaptContents = props => {
9
- const context = useContext(AdaptParentContext);
8
+ const context = React.useContext(AdaptParentContext);
10
9
  if (!context?.Contents) throw new Error(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.");
11
- return createElement(context.Contents, props);
10
+ return React.createElement(context.Contents, props);
12
11
  };
13
12
  AdaptContents.shouldForwardSpace = !0;
14
13
  const useAdaptParent = ({
15
14
  Contents
16
15
  }) => {
17
- const [when, setWhen] = useState(null);
16
+ const [when, setWhen] = React.useState(null);
18
17
  return {
19
- AdaptProvider: useMemo(() => {
18
+ AdaptProvider: React.useMemo(() => {
20
19
  const context = {
21
20
  Contents,
22
21
  setWhen
@@ -37,12 +36,17 @@ const useAdaptParent = ({
37
36
  when,
38
37
  children
39
38
  }) {
40
- const context = useContext(AdaptParentContext),
39
+ const context = React.useContext(AdaptParentContext),
41
40
  media = useMedia();
42
- let enabled = !platform;
43
- return platform === "touch" && (enabled = isTouchable), platform === "native" && (enabled = !isWeb), platform === "web" && (enabled = isWeb), platform === "ios" && (enabled = isIos), platform === "android" && (enabled = isAndroid), when && !media[when] && (enabled = !1), useIsomorphicLayoutEffect(() => {
41
+ let enabled = !1;
42
+ return typeof when == "function" ? enabled = when({
43
+ media
44
+ }) : (enabled = !platform, platform === "touch" && (enabled = isTouchable), platform === "native" && (enabled = !isWeb), platform === "web" && (enabled = isWeb), platform === "ios" && (enabled = isIos), platform === "android" && (enabled = isAndroid), when && !media[when] && (enabled = !1)), useIsomorphicLayoutEffect(() => {
44
45
  enabled && context?.setWhen(when || enabled);
45
- }, [when, context, enabled]), enabled ? children : null;
46
+ }, [when, context, enabled]), enabled ? typeof children == "function" ? children({
47
+ enabled,
48
+ media
49
+ }) : children : null;
46
50
  }, {
47
51
  Contents: AdaptContents
48
52
  });
@@ -1 +1 @@
1
- {"version":3,"names":["isAndroid","isIos","isWeb","useIsomorphicLayoutEffect","isTouchable","useMedia","withStaticProperties","createContext","createElement","useContext","useMemo","useState","jsx","AdaptParentContext","AdaptContents","props","context","Contents","Error","process","env","NODE_ENV","shouldForwardSpace","useAdaptParent","when","setWhen","AdaptProvider","AdaptProviderView","Provider","value","children","Adapt","platform","media","enabled"],"sources":["../../src/Adapt.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,SAAA,EAAWC,KAAA,EAAOC,KAAA,EAAOC,yBAAA,QAAiC;AACnE,SAASC,WAAA,QAAmB;AAE5B,SAASC,QAAA,QAAgB;AACzB,SAASC,oBAAA,QAA4B;AACrC,SACEC,aAAA,EACAC,aAAA,EACAC,UAAA,EACAC,OAAA,EACAC,QAAA,QAEK;AAkDC,SAAAC,GAAA;AAhCD,MAAMC,kBAAA,GAAqBN,aAAA,CAA0C,IAAI;EAGnEO,aAAA,GAAiBC,KAAA,IAAe;IAC3C,MAAMC,OAAA,GAAUP,UAAA,CAAWI,kBAAkB;IAC7C,IAAI,CAACG,OAAA,EAASC,QAAA,EACZ,MAAM,IAAIC,KAAA,CACRC,OAAA,CAAQC,GAAA,CAAIC,QAAA,KAAa,eACrB,8CACA,0GACN;IAEF,OAAOb,aAAA,CAAcQ,OAAA,CAAQC,QAAA,EAAUF,KAAK;EAC9C;AAEAD,aAAA,CAAcQ,kBAAA,GAAqB;AAE5B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1
+ {"version":3,"names":["React","isAndroid","isIos","isTouchable","isWeb","useIsomorphicLayoutEffect","useMedia","withStaticProperties","jsx","AdaptParentContext","createContext","AdaptContents","props","context","useContext","Contents","Error","process","env","NODE_ENV","createElement","shouldForwardSpace","useAdaptParent","when","setWhen","useState","AdaptProvider","useMemo","AdaptProviderView","Provider","value","children","Adapt","platform","media","enabled"],"sources":["../../src/Adapt.tsx"],"sourcesContent":[null],"mappings":"AAAA,OAAOA,KAAA,MAAW;AAClB,SACEC,SAAA,EACAC,KAAA,EACAC,WAAA,EACAC,KAAA,EACAC,yBAAA,QACK;AAEP,SAASC,QAAA,QAAgB;AACzB,SAASC,oBAAA,QAA4B;AAkD7B,SAAAC,GAAA;AA9BD,MAAMC,kBAAA,GAAqBT,KAAA,CAAMU,aAAA,CAA0C,IAAI;EAGzEC,aAAA,GAAiBC,KAAA,IAAe;IAC3C,MAAMC,OAAA,GAAUb,KAAA,CAAMc,UAAA,CAAWL,kBAAkB;IACnD,IAAI,CAACI,OAAA,EAASE,QAAA,EACZ,MAAM,IAAIC,KAAA,CACRC,OAAA,CAAQC,GAAA,CAAIC,QAAA,KAAa,eACrB,8CACA,0GACN;IAEF,OAAOnB,KAAA,CAAMoB,aAAA,CAAcP,OAAA,CAAQE,QAAA,EAAUH,KAAK;EACpD;AAEAD,aAAA,CAAcU,kBAAA,GAAqB;AAE5B,MAAMC,cAAA,GAAiBA,CAAC;IAC7BP;EACF,MAAqD;IACnD,MAAM,CAACQ,IAAA,EAAMC,OAAO,IAAIxB,KAAA,CAAMyB,QAAA,CAAe,IAAI;IAmBjD,OAAO;MACLC,aAAA,EAlBoB1B,KAAA,CAAM2B,OAAA,CAAQ,MAAM;QACxC,MAAMd,OAAA,GAA+B;UACnCE,QAAA;UACAS;QACF;QAEA,SAASI,kBAAkBhB,KAAA,EAA2B;UACpD,OACE,eAAAJ,GAAA,CAACC,kBAAA,CAAmBoB,QAAA,EAAnB;YAA4BC,KAAA,EAAOjB,OAAA;YACjCkB,QAAA,EAAAnB,KAAA,CAAMmB;UAAA,CACT;QAEJ;QAEA,OAAOH,iBAAA;MACT,GAAG,CAACb,QAAQ,CAAC;MAIXQ;IACF;EACF;EAEaS,KAAA,GAAQzB,oBAAA,CACnB,UAAe;IAAE0B,QAAA;IAAUV,IAAA;IAAMQ;EAAS,GAAe;IACvD,MAAMlB,OAAA,GAAUb,KAAA,CAAMc,UAAA,CAAWL,kBAAkB;MAC7CyB,KAAA,GAAQ5B,QAAA,CAAS;IAEvB,IAAI6B,OAAA,GAAU;IAuBd,OArBI,OAAOZ,IAAA,IAAS,aAClBY,OAAA,GAAUZ,IAAA,CAAK;MAAEW;IAAM,CAAC,KAExBC,OAAA,GAAU,CAACF,QAAA,EAEPA,QAAA,KAAa,YAASE,OAAA,GAAUhC,WAAA,GAChC8B,QAAA,KAAa,aAAUE,OAAA,GAAU,CAAC/B,KAAA,GAClC6B,QAAA,KAAa,UAAOE,OAAA,GAAU/B,KAAA,GAC9B6B,QAAA,KAAa,UAAOE,OAAA,GAAUjC,KAAA,GAC9B+B,QAAA,KAAa,cAAWE,OAAA,GAAUlC,SAAA,GAElCsB,IAAA,IAAQ,CAACW,KAAA,CAAMX,IAAI,MACrBY,OAAA,GAAU,MAId9B,yBAAA,CAA0B,MAAM;MACzB8B,OAAA,IACLtB,OAAA,EAASW,OAAA,CAASD,IAAA,IAAQY,OAAgB;IAC5C,GAAG,CAACZ,IAAA,EAAMV,OAAA,EAASsB,OAAO,CAAC,GAEtBA,OAAA,GAID,OAAOJ,QAAA,IAAa,aACfA,QAAA,CAAS;MAAEI,OAAA;MAASD;IAAM,CAAC,IAG7BH,QAAA,GAPE;EAQX,GACA;IACEhB,QAAA,EAAUJ;EACZ,CACF","ignoreList":[]}
@@ -1,9 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { isAndroid, isIos, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
3
- import { isTouchable } from "@tamagui/constants";
2
+ import React from "react";
3
+ import { isAndroid, isIos, isTouchable, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
4
4
  import { useMedia } from "@tamagui/core";
5
5
  import { withStaticProperties } from "@tamagui/helpers";
6
- import { createContext, createElement, useContext, useMemo, useState } from "react";
7
6
  function _array_like_to_array(arr, len) {
8
7
  (len == null || len > arr.length) && (len = arr.length);
9
8
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
@@ -45,15 +44,15 @@ function _unsupported_iterable_to_array(o, minLen) {
45
44
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
46
45
  }
47
46
  }
48
- var AdaptParentContext = /* @__PURE__ */ createContext(null), AdaptContents = function(props) {
49
- var context = useContext(AdaptParentContext);
47
+ var AdaptParentContext = /* @__PURE__ */ React.createContext(null), AdaptContents = function(props) {
48
+ var context = React.useContext(AdaptParentContext);
50
49
  if (!(context != null && context.Contents))
51
50
  throw new Error(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.");
52
- return /* @__PURE__ */ createElement(context.Contents, props);
51
+ return /* @__PURE__ */ React.createElement(context.Contents, props);
53
52
  };
54
53
  AdaptContents.shouldForwardSpace = !0;
55
54
  var useAdaptParent = function(param) {
56
- var Contents = param.Contents, _useState = _sliced_to_array(useState(null), 2), when = _useState[0], setWhen = _useState[1], AdaptProvider = useMemo(function() {
55
+ var Contents = param.Contents, _React_useState = _sliced_to_array(React.useState(null), 2), when = _React_useState[0], setWhen = _React_useState[1], AdaptProvider = React.useMemo(function() {
57
56
  var AdaptProviderView = function(props) {
58
57
  return /* @__PURE__ */ _jsx(AdaptParentContext.Provider, {
59
58
  value: context,
@@ -72,14 +71,19 @@ var useAdaptParent = function(param) {
72
71
  when
73
72
  };
74
73
  }, Adapt = withStaticProperties(function(param) {
75
- var platform = param.platform, when = param.when, children = param.children, context = useContext(AdaptParentContext), media = useMedia(), enabled = !platform;
76
- return platform === "touch" && (enabled = isTouchable), platform === "native" && (enabled = !isWeb), platform === "web" && (enabled = isWeb), platform === "ios" && (enabled = isIos), platform === "android" && (enabled = isAndroid), when && !media[when] && (enabled = !1), useIsomorphicLayoutEffect(function() {
74
+ var platform = param.platform, when = param.when, children = param.children, context = React.useContext(AdaptParentContext), media = useMedia(), enabled = !1;
75
+ return typeof when == "function" ? enabled = when({
76
+ media
77
+ }) : (enabled = !platform, platform === "touch" && (enabled = isTouchable), platform === "native" && (enabled = !isWeb), platform === "web" && (enabled = isWeb), platform === "ios" && (enabled = isIos), platform === "android" && (enabled = isAndroid), when && !media[when] && (enabled = !1)), useIsomorphicLayoutEffect(function() {
77
78
  enabled && (context == null || context.setWhen(when || enabled));
78
79
  }, [
79
80
  when,
80
81
  context,
81
82
  enabled
82
- ]), enabled ? children : null;
83
+ ]), enabled ? typeof children == "function" ? children({
84
+ enabled,
85
+ media
86
+ }) : children : null;
83
87
  }, {
84
88
  Contents: AdaptContents
85
89
  });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Users/n8/tamagui/code/ui/adapt/src/Adapt.tsx"],
4
- "mappings": ";AAAA,SAASA,WAAWC,OAAOC,OAAOC,iCAAiC;AACnE,SAASC,mBAAmB;AAE5B,SAASC,gBAAgB;AACzB,SAASC,4BAA4B;AACrC,SACEC,eACAC,eACAC,YACAC,SACAC,gBAEK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,IAAMC,qBAAqBL,8BAA0C,IAAA,GAG/DM,gBAAgB,SAACC,OAAAA;AAC5B,MAAMC,UAAUN,WAAWG,kBAAAA;AAC3B,MAAI,EAACG,WAAAA,QAAAA,QAASC;AACZ,UAAM,IAAIC,MACRC,QAAQC,IAAIC,aAAa,eACpB,8CACA,0GAAA;AAGT,SAAOZ,8BAAcO,QAAQC,UAAUF,KAAAA;AACzC;AAEAD,cAAcQ,qBAAqB;AAE5B,IAAMC,iBAAiB,SAAA,OAAA;MAC5BN,WAAAA,MAAAA,UAIwBL,YAAAA,iBAAAA,SAAe,IAAA,GAAA,CAAA,GAAhCY,OAAiBZ,UAAAA,CAAAA,GAAXa,UAAWb,UAAAA,CAAAA,GAElBc,gBAAgBf,QAAQ,WAAA;QAMnBgB,oBAAT,SAA2BZ,OAAyB;AAClD,aACE,qBAACF,mBAAmBe,UAAQ;QAACC,OAAOb;kBACjCD,MAAMe;;IAGb,GAXMd,UAA+B;MACnCC;MACAQ;IACF;AAUA,WAAOE;EACT,GAAG;IAACV;GAAS;AAEb,SAAO;IACLS;IACAF;EACF;AACF,GAEaO,QAAQxB,qBACnB,SAAe,OAAwC;MAAtCyB,WAAF,MAAEA,UAAUR,OAAZ,MAAYA,MAAMM,WAAlB,MAAkBA,UACzBd,UAAUN,WAAWG,kBAAAA,GACrBoB,QAAQ3B,SAAAA,GAEV4B,UAAU,CAACF;AAgBf,SAfIA,aAAa,YAASE,UAAU7B,cAChC2B,aAAa,aAAUE,UAAU,CAAC/B,QAClC6B,aAAa,UAAOE,UAAU/B,QAC9B6B,aAAa,UAAOE,UAAUhC,QAC9B8B,aAAa,cAAWE,UAAUjC,YAElCuB,QAAQ,CAACS,MAAMT,IAAAA,MACjBU,UAAU,KAGZ9B,0BAA0B,WAAA;AACxB,IAAK8B,YACLlB,WAAAA,QAAAA,QAASS,QAASD,QAAQU,OAAAA;EAC5B,GAAG;IAACV;IAAMR;IAASkB;GAAQ,GAEtBA,UAIEJ,WAHE;AAIX,GACA;EACEb,UAAUH;AACZ,CAAA;",
5
- "names": ["isAndroid", "isIos", "isWeb", "useIsomorphicLayoutEffect", "isTouchable", "useMedia", "withStaticProperties", "createContext", "createElement", "useContext", "useMemo", "useState", "AdaptParentContext", "AdaptContents", "props", "context", "Contents", "Error", "process", "env", "NODE_ENV", "shouldForwardSpace", "useAdaptParent", "when", "setWhen", "AdaptProvider", "Ada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Aa,YAASE,UAAU/B,cAChC6B,aAAa,aAAUE,UAAU,CAAC9B,QAClC4B,aAAa,UAAOE,UAAU9B,QAC9B4B,aAAa,UAAOE,UAAUhC,QAC9B8B,aAAa,cAAWE,UAAUjC,YAElCsB,QAAQ,CAACU,MAAMV,IAAAA,MACjBW,UAAU,MAId7B,0BAA0B,WAAA;AACxB,IAAK6B,YACLtB,WAAAA,QAAAA,QAASY,QAASD,QAAQW,OAAAA;EAC5B,GAAG;IAACX;IAAMX;IAASsB;GAAQ,GAEtBA,UAID,OAAOJ,YAAa,aACfA,SAAS;IAAEI;IAASD;EAAM,CAAA,IAG5BH,WAPE;AAQX,GACA;EACEhB,UAAUJ;AACZ,CAAA;",
5
+ "names": ["React", "isAndroid", "isIos", "isTouchable", "isWeb", "useIsomorphicLayoutEffect", "useMedia", "withStaticProperties", "AdaptParentContext", "createContext", "AdaptContents", "props", "context", "useContext", "Contents", "Error", "process", "env", "NODE_ENV", "createElement", "shouldForwardSpace", "useAdaptParent", "useState", "when", "setWhen", "AdaptProvider", "useMemo", "AdaptProviderView", "Provider", "value", "children", "Adapt", "platform", "media", "enabled"]
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/adapt",
3
- "version": "1.106.0",
3
+ "version": "1.108.0-1722728147390",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -27,12 +27,12 @@
27
27
  }
28
28
  },
29
29
  "dependencies": {
30
- "@tamagui/constants": "1.106.0",
31
- "@tamagui/core": "1.106.0",
32
- "@tamagui/helpers": "1.106.0"
30
+ "@tamagui/constants": "1.108.0-1722728147390",
31
+ "@tamagui/core": "1.108.0-1722728147390",
32
+ "@tamagui/helpers": "1.108.0-1722728147390"
33
33
  },
34
34
  "devDependencies": {
35
- "@tamagui/build": "1.106.0"
35
+ "@tamagui/build": "1.108.0-1722728147390"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
package/src/Adapt.tsx CHANGED
@@ -1,23 +1,23 @@
1
- import { isAndroid, isIos, isWeb, useIsomorphicLayoutEffect } from '@tamagui/constants'
2
- import { isTouchable } from '@tamagui/constants'
3
- import type { MediaQueryKey } from '@tamagui/core'
1
+ import React from 'react'
2
+ import {
3
+ isAndroid,
4
+ isIos,
5
+ isTouchable,
6
+ isWeb,
7
+ useIsomorphicLayoutEffect,
8
+ } from '@tamagui/constants'
9
+ import type { MediaQueryKey, UseMediaState } from '@tamagui/core'
4
10
  import { useMedia } from '@tamagui/core'
5
11
  import { withStaticProperties } from '@tamagui/helpers'
6
- import {
7
- createContext,
8
- createElement,
9
- useContext,
10
- useMemo,
11
- useState,
12
- useRef,
13
- } from 'react'
14
12
 
15
13
  type MediaQueryKeyString = MediaQueryKey extends string ? MediaQueryKey : never
16
14
 
17
15
  export type AdaptProps = {
18
- when?: MediaQueryKeyString
16
+ when?: MediaQueryKeyString | ((state: { media: UseMediaState }) => boolean)
19
17
  platform?: 'native' | 'web' | 'touch' | 'ios' | 'android'
20
- children?: any
18
+ children?:
19
+ | React.ReactNode
20
+ | ((state: { enabled: boolean; media: UseMediaState }) => React.ReactNode)
21
21
  }
22
22
 
23
23
  type When = MediaQueryKeyString | boolean | null
@@ -28,11 +28,11 @@ type AdaptParentContextI = {
28
28
  setWhen: (when: When) => any
29
29
  }
30
30
 
31
- export const AdaptParentContext = createContext<AdaptParentContextI | null>(null)
31
+ export const AdaptParentContext = React.createContext<AdaptParentContextI | null>(null)
32
32
 
33
33
  // forward props
34
34
  export const AdaptContents = (props: any) => {
35
- const context = useContext(AdaptParentContext)
35
+ const context = React.useContext(AdaptParentContext)
36
36
  if (!context?.Contents) {
37
37
  throw new Error(
38
38
  process.env.NODE_ENV === 'production'
@@ -40,19 +40,17 @@ export const AdaptContents = (props: any) => {
40
40
  : `You're rendering a Tamagui <Adapt /> component without nesting it inside a parent that is able to adapt.`
41
41
  )
42
42
  }
43
- return createElement(context.Contents, props)
43
+ return React.createElement(context.Contents, props)
44
44
  }
45
45
 
46
46
  AdaptContents.shouldForwardSpace = true
47
47
 
48
48
  export const useAdaptParent = ({
49
49
  Contents,
50
- }: {
51
- Contents: AdaptParentContextI['Contents']
52
- }) => {
53
- const [when, setWhen] = useState<When>(null)
50
+ }: { Contents: AdaptParentContextI['Contents'] }) => {
51
+ const [when, setWhen] = React.useState<When>(null)
54
52
 
55
- const AdaptProvider = useMemo(() => {
53
+ const AdaptProvider = React.useMemo(() => {
56
54
  const context: AdaptParentContextI = {
57
55
  Contents,
58
56
  setWhen,
@@ -77,18 +75,25 @@ export const useAdaptParent = ({
77
75
 
78
76
  export const Adapt = withStaticProperties(
79
77
  function Adapt({ platform, when, children }: AdaptProps) {
80
- const context = useContext(AdaptParentContext)
78
+ const context = React.useContext(AdaptParentContext)
81
79
  const media = useMedia()
82
80
 
83
- let enabled = !platform
84
- if (platform === 'touch') enabled = isTouchable
85
- if (platform === 'native') enabled = !isWeb
86
- if (platform === 'web') enabled = isWeb
87
- if (platform === 'ios') enabled = isIos
88
- if (platform === 'android') enabled = isAndroid
81
+ let enabled = false
82
+
83
+ if (typeof when === 'function') {
84
+ enabled = when({ media })
85
+ } else {
86
+ enabled = !platform
89
87
 
90
- if (when && !media[when]) {
91
- enabled = false
88
+ if (platform === 'touch') enabled = isTouchable
89
+ if (platform === 'native') enabled = !isWeb
90
+ if (platform === 'web') enabled = isWeb
91
+ if (platform === 'ios') enabled = isIos
92
+ if (platform === 'android') enabled = isAndroid
93
+
94
+ if (when && !media[when]) {
95
+ enabled = false
96
+ }
92
97
  }
93
98
 
94
99
  useIsomorphicLayoutEffect(() => {
@@ -100,6 +105,10 @@ export const Adapt = withStaticProperties(
100
105
  return null
101
106
  }
102
107
 
108
+ if (typeof children === 'function') {
109
+ return children({ enabled, media })
110
+ }
111
+
103
112
  return children
104
113
  },
105
114
  {
package/types/Adapt.d.ts CHANGED
@@ -1,9 +1,15 @@
1
- import type { MediaQueryKey } from '@tamagui/core';
1
+ import React from 'react';
2
+ import type { MediaQueryKey, UseMediaState } from '@tamagui/core';
2
3
  type MediaQueryKeyString = MediaQueryKey extends string ? MediaQueryKey : never;
3
4
  export type AdaptProps = {
4
- when?: MediaQueryKeyString;
5
+ when?: MediaQueryKeyString | ((state: {
6
+ media: UseMediaState;
7
+ }) => boolean);
5
8
  platform?: 'native' | 'web' | 'touch' | 'ios' | 'android';
6
- children?: any;
9
+ children?: React.ReactNode | ((state: {
10
+ enabled: boolean;
11
+ media: UseMediaState;
12
+ }) => React.ReactNode);
7
13
  };
8
14
  type When = MediaQueryKeyString | boolean | null;
9
15
  type Component = (props: any) => any;
@@ -11,9 +17,9 @@ type AdaptParentContextI = {
11
17
  Contents: Component;
12
18
  setWhen: (when: When) => any;
13
19
  };
14
- export declare const AdaptParentContext: import("react").Context<AdaptParentContextI | null>;
20
+ export declare const AdaptParentContext: React.Context<AdaptParentContextI | null>;
15
21
  export declare const AdaptContents: {
16
- (props: any): import("react").FunctionComponentElement<any>;
22
+ (props: any): React.FunctionComponentElement<any>;
17
23
  shouldForwardSpace: boolean;
18
24
  };
19
25
  export declare const useAdaptParent: ({ Contents, }: {
@@ -24,9 +30,9 @@ export declare const useAdaptParent: ({ Contents, }: {
24
30
  }) => import("react/jsx-runtime").JSX.Element;
25
31
  when: When;
26
32
  };
27
- export declare const Adapt: (({ platform, when, children }: AdaptProps) => any) & {
33
+ export declare const Adapt: (({ platform, when, children }: AdaptProps) => React.ReactNode) & {
28
34
  Contents: {
29
- (props: any): import("react").FunctionComponentElement<any>;
35
+ (props: any): React.FunctionComponentElement<any>;
30
36
  shouldForwardSpace: boolean;
31
37
  };
32
38
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Adapt.d.ts","sourceRoot":"","sources":["../src/Adapt.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAYlD,KAAK,mBAAmB,GAAG,aAAa,SAAS,MAAM,GAAG,aAAa,GAAG,K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