@tamagui/adapt 1.0.1-beta.228 → 1.0.1-rc.0

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/index.js CHANGED
@@ -52,11 +52,23 @@ const useAdaptParent = ({ Contents }) => {
52
52
  };
53
53
  };
54
54
  const Adapt = (0, import_core.withStaticProperties)(
55
- function Adapt2({ when, children }) {
55
+ function Adapt2({ platform, when, children }) {
56
56
  const context = (0, import_react.useContext)(AdaptParentContext);
57
- (0, import_react.useLayoutEffect)(() => {
57
+ let enabled = !platform;
58
+ if (platform === "touch")
59
+ enabled = import_core.isTouchable;
60
+ if (platform === "native")
61
+ enabled = !import_core.isWeb;
62
+ if (platform === "web")
63
+ enabled = import_core.isWeb;
64
+ (0, import_core.useIsomorphicLayoutEffect)(() => {
65
+ if (!enabled)
66
+ return;
58
67
  context == null ? void 0 : context.setWhen(when);
59
- }, [when, context]);
68
+ }, [when, context, enabled]);
69
+ if (!enabled) {
70
+ return null;
71
+ }
60
72
  return children;
61
73
  },
62
74
  {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.tsx"],
4
- "sourcesContent": ["import { MediaQueryKey, withStaticProperties } from '@tamagui/core'\nimport { createContext, createElement, useContext, useLayoutEffect, useMemo, useState } from 'react'\n\nexport type AdaptProps = {\n when?: MediaQueryKey\n children?: any\n}\n\ntype Component = (props: any) => any\n\ntype AdaptParentContextI = {\n Contents: Component\n setWhen: (when: MediaQueryKey) => any\n}\n\nconst AdaptParentContext = createContext<AdaptParentContextI | null>(null)\n\nexport const AdaptContents = () => {\n const context = useContext(AdaptParentContext)\n if (!context || !context.Contents) {\n throw new Error(`Missing parent adapatable component, Adapt not supported here`)\n }\n return createElement(context.Contents)\n}\n\nexport const useAdaptParent = ({ Contents }: { Contents: AdaptParentContextI['Contents'] }) => {\n const [when, setWhen] = useState<MediaQueryKey | null>(null)\n\n const AdaptProvider = useMemo(() => {\n const context: AdaptParentContextI = {\n Contents,\n setWhen,\n }\n\n return (props: { children?: any }) => (\n <AdaptParentContext.Provider value={context}>{props.children}</AdaptParentContext.Provider>\n )\n }, [Contents])\n\n return {\n AdaptProvider,\n when,\n }\n}\n\nexport const Adapt = withStaticProperties(\n function Adapt({ when, children }: AdaptProps) {\n const context = useContext(AdaptParentContext)\n\n useLayoutEffect(() => {\n context?.setWhen(when as MediaQueryKey)\n }, [when, context])\n\n return children\n },\n {\n Contents: AdaptContents,\n }\n)\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCM;AAnCN,kBAAoD;AACpD,mBAA6F;AAc7F,MAAM,yBAAqB,4BAA0C,IAAI;AAElE,MAAM,gBAAgB,MAAM;AACjC,QAAM,cAAU,yBAAW,kBAAkB;AAC7C,MAAI,CAAC,WAAW,CAAC,QAAQ,UAAU;AACjC,UAAM,IAAI,MAAM,+DAA+D;AAAA,EACjF;AACA,aAAO,4BAAc,QAAQ,QAAQ;AACvC;AAEO,MAAM,iBAAiB,CAAC,EAAE,SAAS,MAAqD;AAC7F,QAAM,CAAC,MAAM,OAAO,QAAI,uBAA+B,IAAI;AAE3D,QAAM,oBAAgB,sBAAQ,MAAM;AAClC,UAAM,UAA+B;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,WAAO,CAAC,UACN,4CAAC,mBAAmB,UAAnB;AAAA,MAA4B,OAAO;AAAA,MAAU,gBAAM;AAAA,KAAS;AAAA,EAEjE,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,YAAQ;AAAA,EACnB,SAASA,OAAM,EAAE,MAAM,SAAS,GAAe;AAC7C,UAAM,cAAU,yBAAW,kBAAkB;AAE7C,sCAAgB,MAAM;AACpB,yCAAS,QAAQ;AAAA,IACnB,GAAG,CAAC,MAAM,OAAO,CAAC;AAElB,WAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,UAAU;AAAA,EACZ;AACF;",
4
+ "sourcesContent": ["import {\n MediaQueryKey,\n isTouchable,\n isWeb,\n useIsomorphicLayoutEffect,\n withStaticProperties,\n} from '@tamagui/core'\nimport { createContext, createElement, useContext, useMemo, useState } from 'react'\n\nexport type AdaptProps = {\n when?: MediaQueryKey\n platform?: 'native' | 'web' | 'touch'\n children?: any\n}\n\ntype Component = (props: any) => any\ntype AdaptParentContextI = {\n Contents: Component\n setWhen: (when: MediaQueryKey) => any\n}\n\nconst AdaptParentContext = createContext<AdaptParentContextI | null>(null)\n\nexport const AdaptContents = () => {\n const context = useContext(AdaptParentContext)\n if (!context || !context.Contents) {\n throw new Error(`Missing parent adapatable component, Adapt not supported here`)\n }\n return createElement(context.Contents)\n}\n\nexport const useAdaptParent = ({ Contents }: { Contents: AdaptParentContextI['Contents'] }) => {\n const [when, setWhen] = useState<MediaQueryKey | null>(null)\n\n const AdaptProvider = useMemo(() => {\n const context: AdaptParentContextI = {\n Contents,\n setWhen,\n }\n\n return (props: { children?: any }) => (\n <AdaptParentContext.Provider value={context}>{props.children}</AdaptParentContext.Provider>\n )\n }, [Contents])\n\n return {\n AdaptProvider,\n when,\n }\n}\n\nexport const Adapt = withStaticProperties(\n function Adapt({ platform, when, children }: AdaptProps) {\n const context = useContext(AdaptParentContext)\n\n let enabled = !platform\n if (platform === 'touch') enabled = isTouchable\n if (platform === 'native') enabled = !isWeb\n if (platform === 'web') enabled = isWeb\n\n useIsomorphicLayoutEffect(() => {\n if (!enabled) return\n context?.setWhen(when as MediaQueryKey)\n }, [when, context, enabled])\n\n if (!enabled) {\n return null\n }\n\n return children\n },\n {\n Contents: AdaptContents,\n }\n)\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCM;AAzCN,kBAMO;AACP,mBAA4E;AAc5E,MAAM,yBAAqB,4BAA0C,IAAI;AAElE,MAAM,gBAAgB,MAAM;AACjC,QAAM,cAAU,yBAAW,kBAAkB;AAC7C,MAAI,CAAC,WAAW,CAAC,QAAQ,UAAU;AACjC,UAAM,IAAI,MAAM,+DAA+D;AAAA,EACjF;AACA,aAAO,4BAAc,QAAQ,QAAQ;AACvC;AAEO,MAAM,iBAAiB,CAAC,EAAE,SAAS,MAAqD;AAC7F,QAAM,CAAC,MAAM,OAAO,QAAI,uBAA+B,IAAI;AAE3D,QAAM,oBAAgB,sBAAQ,MAAM;AAClC,UAAM,UAA+B;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,WAAO,CAAC,UACN,4CAAC,mBAAmB,UAAnB;AAAA,MAA4B,OAAO;AAAA,MAAU,gBAAM;AAAA,KAAS;AAAA,EAEjE,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,YAAQ;AAAA,EACnB,SAASA,OAAM,EAAE,UAAU,MAAM,SAAS,GAAe;AACvD,UAAM,cAAU,yBAAW,kBAAkB;AAE7C,QAAI,UAAU,CAAC;AACf,QAAI,aAAa;AAAS,gBAAU;AACpC,QAAI,aAAa;AAAU,gBAAU,CAAC;AACtC,QAAI,aAAa;AAAO,gBAAU;AAElC,+CAA0B,MAAM;AAC9B,UAAI,CAAC;AAAS;AACd,yCAAS,QAAQ;AAAA,IACnB,GAAG,CAAC,MAAM,SAAS,OAAO,CAAC;AAE3B,QAAI,CAAC,SAAS;AACZ,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,UAAU;AAAA,EACZ;AACF;",
6
6
  "names": ["Adapt"]
7
7
  }
package/dist/esm/index.js CHANGED
@@ -1,6 +1,11 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { withStaticProperties } from "@tamagui/core";
3
- import { createContext, createElement, useContext, useLayoutEffect, useMemo, useState } from "react";
2
+ import {
3
+ isTouchable,
4
+ isWeb,
5
+ useIsomorphicLayoutEffect,
6
+ withStaticProperties
7
+ } from "@tamagui/core";
8
+ import { createContext, createElement, useContext, useMemo, useState } from "react";
4
9
  const AdaptParentContext = createContext(null);
5
10
  const AdaptContents = () => {
6
11
  const context = useContext(AdaptParentContext);
@@ -27,11 +32,23 @@ const useAdaptParent = ({ Contents }) => {
27
32
  };
28
33
  };
29
34
  const Adapt = withStaticProperties(
30
- function Adapt2({ when, children }) {
35
+ function Adapt2({ platform, when, children }) {
31
36
  const context = useContext(AdaptParentContext);
32
- useLayoutEffect(() => {
37
+ let enabled = !platform;
38
+ if (platform === "touch")
39
+ enabled = isTouchable;
40
+ if (platform === "native")
41
+ enabled = !isWeb;
42
+ if (platform === "web")
43
+ enabled = isWeb;
44
+ useIsomorphicLayoutEffect(() => {
45
+ if (!enabled)
46
+ return;
33
47
  context == null ? void 0 : context.setWhen(when);
34
- }, [when, context]);
48
+ }, [when, context, enabled]);
49
+ if (!enabled) {
50
+ return null;
51
+ }
35
52
  return children;
36
53
  },
37
54
  {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.tsx"],
4
- "sourcesContent": ["import { MediaQueryKey, withStaticProperties } from '@tamagui/core'\nimport { createContext, createElement, useContext, useLayoutEffect, useMemo, useState } from 'react'\n\nexport type AdaptProps = {\n when?: MediaQueryKey\n children?: any\n}\n\ntype Component = (props: any) => any\n\ntype AdaptParentContextI = {\n Contents: Component\n setWhen: (when: MediaQueryKey) => any\n}\n\nconst AdaptParentContext = createContext<AdaptParentContextI | null>(null)\n\nexport const AdaptContents = () => {\n const context = useContext(AdaptParentContext)\n if (!context || !context.Contents) {\n throw new Error(`Missing parent adapatable component, Adapt not supported here`)\n }\n return createElement(context.Contents)\n}\n\nexport const useAdaptParent = ({ Contents }: { Contents: AdaptParentContextI['Contents'] }) => {\n const [when, setWhen] = useState<MediaQueryKey | null>(null)\n\n const AdaptProvider = useMemo(() => {\n const context: AdaptParentContextI = {\n Contents,\n setWhen,\n }\n\n return (props: { children?: any }) => (\n <AdaptParentContext.Provider value={context}>{props.children}</AdaptParentContext.Provider>\n )\n }, [Contents])\n\n return {\n AdaptProvider,\n when,\n }\n}\n\nexport const Adapt = withStaticProperties(\n function Adapt({ when, children }: AdaptProps) {\n const context = useContext(AdaptParentContext)\n\n useLayoutEffect(() => {\n context?.setWhen(when as MediaQueryKey)\n }, [when, context])\n\n return children\n },\n {\n Contents: AdaptContents,\n }\n)\n"],
5
- "mappings": "AAmCM;AAnCN,SAAwB,4BAA4B;AACpD,SAAS,eAAe,eAAe,YAAY,iBAAiB,SAAS,gBAAgB;AAc7F,MAAM,qBAAqB,cAA0C,IAAI;AAElE,MAAM,gBAAgB,MAAM;AACjC,QAAM,UAAU,WAAW,kBAAkB;AAC7C,MAAI,CAAC,WAAW,CAAC,QAAQ,UAAU;AACjC,UAAM,IAAI,MAAM,+DAA+D;AAAA,EACjF;AACA,SAAO,cAAc,QAAQ,QAAQ;AACvC;AAEO,MAAM,iBAAiB,CAAC,EAAE,SAAS,MAAqD;AAC7F,QAAM,CAAC,MAAM,OAAO,IAAI,SAA+B,IAAI;AAE3D,QAAM,gBAAgB,QAAQ,MAAM;AAClC,UAAM,UAA+B;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,WAAO,CAAC,UACN,oBAAC,mBAAmB,UAAnB;AAAA,MAA4B,OAAO;AAAA,MAAU,gBAAM;AAAA,KAAS;AAAA,EAEjE,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,QAAQ;AAAA,EACnB,SAASA,OAAM,EAAE,MAAM,SAAS,GAAe;AAC7C,UAAM,UAAU,WAAW,kBAAkB;AAE7C,oBAAgB,MAAM;AACpB,yCAAS,QAAQ;AAAA,IACnB,GAAG,CAAC,MAAM,OAAO,CAAC;AAElB,WAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,UAAU;AAAA,EACZ;AACF;",
4
+ "sourcesContent": ["import {\n MediaQueryKey,\n isTouchable,\n isWeb,\n useIsomorphicLayoutEffect,\n withStaticProperties,\n} from '@tamagui/core'\nimport { createContext, createElement, useContext, useMemo, useState } from 'react'\n\nexport type AdaptProps = {\n when?: MediaQueryKey\n platform?: 'native' | 'web' | 'touch'\n children?: any\n}\n\ntype Component = (props: any) => any\ntype AdaptParentContextI = {\n Contents: Component\n setWhen: (when: MediaQueryKey) => any\n}\n\nconst AdaptParentContext = createContext<AdaptParentContextI | null>(null)\n\nexport const AdaptContents = () => {\n const context = useContext(AdaptParentContext)\n if (!context || !context.Contents) {\n throw new Error(`Missing parent adapatable component, Adapt not supported here`)\n }\n return createElement(context.Contents)\n}\n\nexport const useAdaptParent = ({ Contents }: { Contents: AdaptParentContextI['Contents'] }) => {\n const [when, setWhen] = useState<MediaQueryKey | null>(null)\n\n const AdaptProvider = useMemo(() => {\n const context: AdaptParentContextI = {\n Contents,\n setWhen,\n }\n\n return (props: { children?: any }) => (\n <AdaptParentContext.Provider value={context}>{props.children}</AdaptParentContext.Provider>\n )\n }, [Contents])\n\n return {\n AdaptProvider,\n when,\n }\n}\n\nexport const Adapt = withStaticProperties(\n function Adapt({ platform, when, children }: AdaptProps) {\n const context = useContext(AdaptParentContext)\n\n let enabled = !platform\n if (platform === 'touch') enabled = isTouchable\n if (platform === 'native') enabled = !isWeb\n if (platform === 'web') enabled = isWeb\n\n useIsomorphicLayoutEffect(() => {\n if (!enabled) return\n context?.setWhen(when as MediaQueryKey)\n }, [when, context, enabled])\n\n if (!enabled) {\n return null\n }\n\n return children\n },\n {\n Contents: AdaptContents,\n }\n)\n"],
5
+ "mappings": "AAyCM;AAzCN;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe,eAAe,YAAY,SAAS,gBAAgB;AAc5E,MAAM,qBAAqB,cAA0C,IAAI;AAElE,MAAM,gBAAgB,MAAM;AACjC,QAAM,UAAU,WAAW,kBAAkB;AAC7C,MAAI,CAAC,WAAW,CAAC,QAAQ,UAAU;AACjC,UAAM,IAAI,MAAM,+DAA+D;AAAA,EACjF;AACA,SAAO,cAAc,QAAQ,QAAQ;AACvC;AAEO,MAAM,iBAAiB,CAAC,EAAE,SAAS,MAAqD;AAC7F,QAAM,CAAC,MAAM,OAAO,IAAI,SAA+B,IAAI;AAE3D,QAAM,gBAAgB,QAAQ,MAAM;AAClC,UAAM,UAA+B;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,WAAO,CAAC,UACN,oBAAC,mBAAmB,UAAnB;AAAA,MAA4B,OAAO;AAAA,MAAU,gBAAM;AAAA,KAAS;AAAA,EAEjE,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,QAAQ;AAAA,EACnB,SAASA,OAAM,EAAE,UAAU,MAAM,SAAS,GAAe;AACvD,UAAM,UAAU,WAAW,kBAAkB;AAE7C,QAAI,UAAU,CAAC;AACf,QAAI,aAAa;AAAS,gBAAU;AACpC,QAAI,aAAa;AAAU,gBAAU,CAAC;AACtC,QAAI,aAAa;AAAO,gBAAU;AAElC,8BAA0B,MAAM;AAC9B,UAAI,CAAC;AAAS;AACd,yCAAS,QAAQ;AAAA,IACnB,GAAG,CAAC,MAAM,SAAS,OAAO,CAAC;AAE3B,QAAI,CAAC,SAAS;AACZ,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,UAAU;AAAA,EACZ;AACF;",
6
6
  "names": ["Adapt"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/adapt",
3
- "version": "1.0.1-beta.228",
3
+ "version": "1.0.1-rc.0",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -18,10 +18,10 @@
18
18
  "clean:build": "tamagui-build clean:build"
19
19
  },
20
20
  "dependencies": {
21
- "@tamagui/core": "^1.0.1-beta.228"
21
+ "@tamagui/core": "^1.0.1-rc.0"
22
22
  },
23
23
  "devDependencies": {
24
- "@tamagui/build": "^1.0.1-beta.228"
24
+ "@tamagui/build": "^1.0.1-rc.0"
25
25
  },
26
26
  "publishConfig": {
27
27
  "access": "public"
package/src/index.tsx CHANGED
@@ -1,13 +1,19 @@
1
- import { MediaQueryKey, withStaticProperties } from '@tamagui/core'
2
- import { createContext, createElement, useContext, useLayoutEffect, useMemo, useState } from 'react'
1
+ import {
2
+ MediaQueryKey,
3
+ isTouchable,
4
+ isWeb,
5
+ useIsomorphicLayoutEffect,
6
+ withStaticProperties,
7
+ } from '@tamagui/core'
8
+ import { createContext, createElement, useContext, useMemo, useState } from 'react'
3
9
 
4
10
  export type AdaptProps = {
5
11
  when?: MediaQueryKey
12
+ platform?: 'native' | 'web' | 'touch'
6
13
  children?: any
7
14
  }
8
15
 
9
16
  type Component = (props: any) => any
10
-
11
17
  type AdaptParentContextI = {
12
18
  Contents: Component
13
19
  setWhen: (when: MediaQueryKey) => any
@@ -44,12 +50,22 @@ export const useAdaptParent = ({ Contents }: { Contents: AdaptParentContextI['Co
44
50
  }
45
51
 
46
52
  export const Adapt = withStaticProperties(
47
- function Adapt({ when, children }: AdaptProps) {
53
+ function Adapt({ platform, when, children }: AdaptProps) {
48
54
  const context = useContext(AdaptParentContext)
49
55
 
50
- useLayoutEffect(() => {
56
+ let enabled = !platform
57
+ if (platform === 'touch') enabled = isTouchable
58
+ if (platform === 'native') enabled = !isWeb
59
+ if (platform === 'web') enabled = isWeb
60
+
61
+ useIsomorphicLayoutEffect(() => {
62
+ if (!enabled) return
51
63
  context?.setWhen(when as MediaQueryKey)
52
- }, [when, context])
64
+ }, [when, context, enabled])
65
+
66
+ if (!enabled) {
67
+ return null
68
+ }
53
69
 
54
70
  return children
55
71
  },
package/types/index.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  import { MediaQueryKey } from '@tamagui/core';
3
3
  export declare type AdaptProps = {
4
4
  when?: MediaQueryKey;
5
+ platform?: 'native' | 'web' | 'touch';
5
6
  children?: any;
6
7
  };
7
8
  declare type Component = (props: any) => any;
@@ -18,7 +19,7 @@ export declare const useAdaptParent: ({ Contents }: {
18
19
  }) => JSX.Element;
19
20
  when: string | number | null;
20
21
  };
21
- export declare const Adapt: (({ when, children }: AdaptProps) => any) & {
22
+ export declare const Adapt: (({ platform, when, children }: AdaptProps) => any) & {
22
23
  Contents: () => import("react").FunctionComponentElement<any>;
23
24
  };
24
25
  export {};