@tamagui/react-native-media-driver 2.7.7 → 3.0.0-beta.1093.1

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 (55) hide show
  1. package/dist/cjs/index.cjs +9 -12
  2. package/dist/cjs/index.native.cjs +20 -0
  3. package/dist/cjs/index.native.js +9 -11
  4. package/dist/cjs/index.native.js.map +1 -1
  5. package/dist/cjs/matchMedia.cjs +14 -18
  6. package/dist/cjs/matchMedia.native.cjs +29 -0
  7. package/dist/cjs/matchMedia.native.js +16 -19
  8. package/dist/cjs/matchMedia.native.js.map +1 -1
  9. package/dist/cjs/matchQuery.cjs +114 -132
  10. package/dist/cjs/matchQuery.native.cjs +144 -0
  11. package/dist/cjs/matchQuery.native.js +116 -133
  12. package/dist/cjs/matchQuery.native.js.map +1 -1
  13. package/dist/cjs/mediaQueryList.native.cjs +179 -0
  14. package/dist/cjs/mediaQueryList.native.js +159 -112
  15. package/dist/cjs/mediaQueryList.native.js.map +1 -1
  16. package/dist/esm/index.js +1 -3
  17. package/dist/esm/index.mjs +1 -3
  18. package/dist/esm/index.native.js +1 -3
  19. package/dist/esm/matchMedia.mjs +1 -0
  20. package/dist/esm/matchMedia.mjs.map +1 -1
  21. package/dist/esm/matchMedia.native.js +4 -2
  22. package/dist/esm/matchMedia.native.js.map +1 -1
  23. package/dist/esm/matchQuery.mjs +100 -115
  24. package/dist/esm/matchQuery.mjs.map +1 -1
  25. package/dist/esm/matchQuery.native.js +102 -117
  26. package/dist/esm/matchQuery.native.js.map +1 -1
  27. package/dist/esm/mediaQueryList.native.js +146 -94
  28. package/dist/esm/mediaQueryList.native.js.map +1 -1
  29. package/package.json +7 -4
  30. package/src/index.ts +0 -1
  31. package/src/matchMedia.native.ts +1 -1
  32. package/src/mediaQueryList.native.ts +115 -0
  33. package/types/index.d.ts +0 -1
  34. package/types/index.d.ts.map +2 -2
  35. package/types/matchMedia.native.d.ts.map +1 -1
  36. package/types/{mediaQueryList.d.ts → mediaQueryList.native.d.ts} +3 -3
  37. package/types/mediaQueryList.native.d.ts.map +11 -0
  38. package/dist/cjs/createMedia.cjs +0 -33
  39. package/dist/cjs/createMedia.native.js +0 -36
  40. package/dist/cjs/createMedia.native.js.map +0 -1
  41. package/dist/cjs/mediaQueryList.cjs +0 -78
  42. package/dist/esm/createMedia.mjs +0 -8
  43. package/dist/esm/createMedia.mjs.map +0 -1
  44. package/dist/esm/createMedia.native.js +0 -8
  45. package/dist/esm/createMedia.native.js.map +0 -1
  46. package/dist/esm/index.js.map +0 -1
  47. package/dist/esm/index.mjs.map +0 -1
  48. package/dist/esm/index.native.js.map +0 -1
  49. package/dist/esm/mediaQueryList.mjs +0 -53
  50. package/dist/esm/mediaQueryList.mjs.map +0 -1
  51. package/src/createMedia.ts +0 -19
  52. package/src/mediaQueryList.ts +0 -60
  53. package/types/createMedia.d.ts +0 -10
  54. package/types/createMedia.d.ts.map +0 -11
  55. package/types/mediaQueryList.d.ts.map +0 -11
@@ -0,0 +1,115 @@
1
+ import type { MediaQueryList } from '@tamagui/web'
2
+ import { AccessibilityInfo, Dimensions } from 'react-native'
3
+
4
+ import { matchQuery } from './matchQuery'
5
+
6
+ type Orientation = 'landscape' | 'portrait'
7
+
8
+ type Listener = () => void
9
+
10
+ // detect prefers-reduced-motion queries so we can subscribe to
11
+ // AccessibilityInfo instead of Dimensions
12
+ // matches "(prefers-reduced-motion: reduce)" / "(prefers-reduced-motion: no-preference)"
13
+ const REDUCED_MOTION_RE = /\(\s*prefers-reduced-motion\s*:\s*([a-z-]+)\s*\)/i
14
+
15
+ // shared subscription to AccessibilityInfo so we set up a single native listener
16
+ // regardless of how many media queries use it
17
+ let reducedMotionEnabled = false
18
+ let reducedMotionInitialized = false
19
+ const reducedMotionListeners = new Set<() => void>()
20
+
21
+ function ensureReducedMotionSubscription() {
22
+ if (reducedMotionInitialized) return
23
+ reducedMotionInitialized = true
24
+ AccessibilityInfo.isReduceMotionEnabled?.()
25
+ .then((value) => {
26
+ if (value !== reducedMotionEnabled) {
27
+ reducedMotionEnabled = value
28
+ reducedMotionListeners.forEach((cb) => cb())
29
+ }
30
+ })
31
+ .catch(() => {})
32
+ AccessibilityInfo.addEventListener?.('reduceMotionChanged', (value: boolean) => {
33
+ if (value === reducedMotionEnabled) return
34
+ reducedMotionEnabled = value
35
+ reducedMotionListeners.forEach((cb) => cb())
36
+ })
37
+ }
38
+
39
+ export class NativeMediaQueryList implements MediaQueryList {
40
+ private listeners: Listener[] = []
41
+ private reducedMotionExpected: 'reduce' | 'no-preference' | null = null
42
+
43
+ private get orientation(): Orientation {
44
+ const windowDimensions = Dimensions.get('window')
45
+ return windowDimensions.height > windowDimensions.width ? 'portrait' : 'landscape'
46
+ }
47
+
48
+ constructor(private query: string) {
49
+ const reducedMotionMatch = query.match(REDUCED_MOTION_RE)
50
+ if (reducedMotionMatch) {
51
+ // accessibility-driven query, ignore dimensions
52
+ this.reducedMotionExpected = reducedMotionMatch[1] as 'reduce' | 'no-preference'
53
+ ensureReducedMotionSubscription()
54
+ return
55
+ }
56
+ this.notify()
57
+ Dimensions.addEventListener('change', () => {
58
+ this.notify()
59
+ })
60
+ }
61
+
62
+ private notify() {
63
+ this.listeners.forEach((listener) => {
64
+ listener()
65
+ })
66
+ }
67
+
68
+ addListener(listener: Listener): void {
69
+ if (this.reducedMotionExpected) {
70
+ reducedMotionListeners.add(listener)
71
+ this.listeners.push(listener)
72
+ return
73
+ }
74
+ this.listeners.push(listener)
75
+ }
76
+
77
+ removeListener(listener: Listener): void {
78
+ if (this.reducedMotionExpected) {
79
+ reducedMotionListeners.delete(listener)
80
+ }
81
+ const index = this.listeners.indexOf(listener)
82
+ if (index !== -1) this.listeners.splice(index, 1)
83
+ }
84
+
85
+ match(query: string, { width, height }: { width: number; height: number }): boolean {
86
+ const reducedMotionMatch = query.match(REDUCED_MOTION_RE)
87
+ if (reducedMotionMatch) {
88
+ const expected = reducedMotionMatch[1]
89
+ return expected === 'reduce' ? reducedMotionEnabled : !reducedMotionEnabled
90
+ }
91
+ return matchQuery(query, {
92
+ type: 'screen',
93
+ orientation: height > width ? 'portrait' : 'landscape',
94
+ 'device-width': width,
95
+ 'device-height': height,
96
+ })
97
+ }
98
+
99
+ get matches(): boolean {
100
+ if (this.reducedMotionExpected) {
101
+ return this.reducedMotionExpected === 'reduce'
102
+ ? reducedMotionEnabled
103
+ : !reducedMotionEnabled
104
+ }
105
+ const windowDimensions = Dimensions.get('window')
106
+ const matches = matchQuery(this.query, {
107
+ type: 'screen',
108
+ orientation: this.orientation,
109
+ ...windowDimensions,
110
+ 'device-width': windowDimensions.width,
111
+ 'device-height': windowDimensions.height,
112
+ })
113
+ return matches
114
+ }
115
+ }
package/types/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from "./createMedia";
2
1
  export * from "./matchMedia";
3
2
 
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,11 +1,11 @@
1
1
  {
2
- "mappings": "AAAA,cAAc;AACd,cAAc",
2
+ "mappings": "AAAA,cAAc",
3
3
  "names": [],
4
4
  "sources": [
5
5
  "src/index.ts"
6
6
  ],
7
7
  "version": 3,
8
8
  "sourcesContent": [
9
- "export * from './createMedia'\nexport * from './matchMedia'\n"
9
+ "export * from './matchMedia'\n"
10
10
  ]
11
11
  }
@@ -6,6 +6,6 @@
6
6
  ],
7
7
  "version": 3,
8
8
  "sourcesContent": [
9
- "import type { MatchMedia } from '@tamagui/web'\n\nimport { NativeMediaQueryList } from './mediaQueryList'\n\nexport const matchMedia: MatchMedia = (query) => {\n return new NativeMediaQueryList(query)\n}\n"
9
+ "import type { MatchMedia } from '@tamagui/web'\n\nimport { NativeMediaQueryList } from './mediaQueryList.native'\n\nexport const matchMedia: MatchMedia = (query) => {\n return new NativeMediaQueryList(query)\n}\n"
10
10
  ]
11
11
  }
@@ -1,9 +1,9 @@
1
1
  import type { MediaQueryList } from "@tamagui/web";
2
- type Orientation = "landscape" | "portrait";
3
- type Listener = (orientation: Orientation) => void;
2
+ type Listener = () => void;
4
3
  export declare class NativeMediaQueryList implements MediaQueryList {
5
4
  private query;
6
5
  private listeners;
6
+ private reducedMotionExpected;
7
7
  private get orientation();
8
8
  constructor(query: string);
9
9
  private notify;
@@ -17,4 +17,4 @@ export declare class NativeMediaQueryList implements MediaQueryList {
17
17
  }
18
18
  export {};
19
19
 
20
- //# sourceMappingURL=mediaQueryList.d.ts.map
20
+ //# sourceMappingURL=mediaQueryList.native.d.ts.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "mappings": "AAAA,cAAc,sBAAsB;KAO/B;AA+BL,OAAO,cAAM,gCAAgC,eAAe;CAS9C;CARZ,QAAQ;CACR,QAAQ;CAER,YAAY;CAKZ,YAAY,AAAQ;CAcpB,QAAQ;CAMR,YAAY,UAAU;CAStB,eAAe,UAAU;CAQzB,MAAM,eAAe,EAAE,OAAO,UAAU;EAAE;EAAe;;CAczD,IAAI",
3
+ "names": [],
4
+ "sources": [
5
+ "src/mediaQueryList.native.ts"
6
+ ],
7
+ "version": 3,
8
+ "sourcesContent": [
9
+ "import type { MediaQueryList } from '@tamagui/web'\nimport { AccessibilityInfo, Dimensions } from 'react-native'\n\nimport { matchQuery } from './matchQuery'\n\ntype Orientation = 'landscape' | 'portrait'\n\ntype Listener = () => void\n\n// detect prefers-reduced-motion queries so we can subscribe to\n// AccessibilityInfo instead of Dimensions\n// matches \"(prefers-reduced-motion: reduce)\" / \"(prefers-reduced-motion: no-preference)\"\nconst REDUCED_MOTION_RE = /\\(\\s*prefers-reduced-motion\\s*:\\s*([a-z-]+)\\s*\\)/i\n\n// shared subscription to AccessibilityInfo so we set up a single native listener\n// regardless of how many media queries use it\nlet reducedMotionEnabled = false\nlet reducedMotionInitialized = false\nconst reducedMotionListeners = new Set<() => void>()\n\nfunction ensureReducedMotionSubscription() {\n if (reducedMotionInitialized) return\n reducedMotionInitialized = true\n AccessibilityInfo.isReduceMotionEnabled?.()\n .then((value) => {\n if (value !== reducedMotionEnabled) {\n reducedMotionEnabled = value\n reducedMotionListeners.forEach((cb) => cb())\n }\n })\n .catch(() => {})\n AccessibilityInfo.addEventListener?.('reduceMotionChanged', (value: boolean) => {\n if (value === reducedMotionEnabled) return\n reducedMotionEnabled = value\n reducedMotionListeners.forEach((cb) => cb())\n })\n}\n\nexport class NativeMediaQueryList implements MediaQueryList {\n private listeners: Listener[] = []\n private reducedMotionExpected: 'reduce' | 'no-preference' | null = null\n\n private get orientation(): Orientation {\n const windowDimensions = Dimensions.get('window')\n return windowDimensions.height > windowDimensions.width ? 'portrait' : 'landscape'\n }\n\n constructor(private query: string) {\n const reducedMotionMatch = query.match(REDUCED_MOTION_RE)\n if (reducedMotionMatch) {\n // accessibility-driven query, ignore dimensions\n this.reducedMotionExpected = reducedMotionMatch[1] as 'reduce' | 'no-preference'\n ensureReducedMotionSubscription()\n return\n }\n this.notify()\n Dimensions.addEventListener('change', () => {\n this.notify()\n })\n }\n\n private notify() {\n this.listeners.forEach((listener) => {\n listener()\n })\n }\n\n addListener(listener: Listener): void {\n if (this.reducedMotionExpected) {\n reducedMotionListeners.add(listener)\n this.listeners.push(listener)\n return\n }\n this.listeners.push(listener)\n }\n\n removeListener(listener: Listener): void {\n if (this.reducedMotionExpected) {\n reducedMotionListeners.delete(listener)\n }\n const index = this.listeners.indexOf(listener)\n if (index !== -1) this.listeners.splice(index, 1)\n }\n\n match(query: string, { width, height }: { width: number; height: number }): boolean {\n const reducedMotionMatch = query.match(REDUCED_MOTION_RE)\n if (reducedMotionMatch) {\n const expected = reducedMotionMatch[1]\n return expected === 'reduce' ? reducedMotionEnabled : !reducedMotionEnabled\n }\n return matchQuery(query, {\n type: 'screen',\n orientation: height > width ? 'portrait' : 'landscape',\n 'device-width': width,\n 'device-height': height,\n })\n }\n\n get matches(): boolean {\n if (this.reducedMotionExpected) {\n return this.reducedMotionExpected === 'reduce'\n ? reducedMotionEnabled\n : !reducedMotionEnabled\n }\n const windowDimensions = Dimensions.get('window')\n const matches = matchQuery(this.query, {\n type: 'screen',\n orientation: this.orientation,\n ...windowDimensions,\n 'device-width': windowDimensions.width,\n 'device-height': windowDimensions.height,\n })\n return matches\n }\n}\n"
10
+ ]
11
+ }
@@ -1,33 +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 __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- return to;
19
- };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
23
- var createMedia_exports = {};
24
- __export(createMedia_exports, {
25
- createMedia: () => createMedia
26
- });
27
- module.exports = __toCommonJS(createMedia_exports);
28
- var import_web = require("@tamagui/web");
29
- var import_matchMedia = require("./matchMedia.cjs");
30
- function createMedia(media) {
31
- (0, import_web.setupMatchMedia)(import_matchMedia.matchMedia);
32
- return media;
33
- }
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
21
- };
22
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
- value: true
24
- }), mod);
25
- var createMedia_exports = {};
26
- __export(createMedia_exports, {
27
- createMedia: () => createMedia
28
- });
29
- module.exports = __toCommonJS(createMedia_exports);
30
- var import_web = require("@tamagui/web");
31
- var import_matchMedia = require("./matchMedia.native.js");
32
- function createMedia(media) {
33
- (0, import_web.setupMatchMedia)(import_matchMedia.matchMedia);
34
- return media;
35
- }
36
- //# sourceMappingURL=createMedia.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","createMedia_exports","__export","createMedia","module","exports","import_web","require","import_matchMedia","media","setupMatchMedia","matchMedia"],"sources":["../../src/createMedia.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,mBAAA;AAAAC,QAAA,CAAAD,mBAAA;EAAAE,WAAA,EAAAA,CAAA,KAAAA;AAAA;AACAC,MAAA,CAAAC,OAAA,GAAgCT,YAAA,CAAAK,mBAAA;AAEhC,IAAAK,UAAA,GAAAC,OAA2B;AAMpB,IAAAC,iBAIL,GAAAD,OAAa;AAGb,SAAAJ,YAAAM,KAAA;EACA,IAAAH,UAAO,CAAAI,eAAA,EAAAF,iBAAA,CAAAG,UAAA;EACT,OAAAF,KAAA","ignoreList":[]}
@@ -1,78 +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 __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- return to;
19
- };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
23
- var mediaQueryList_exports = {};
24
- __export(mediaQueryList_exports, {
25
- NativeMediaQueryList: () => NativeMediaQueryList
26
- });
27
- module.exports = __toCommonJS(mediaQueryList_exports);
28
- var import_react_native = require("react-native-web");
29
- var import_matchQuery = require("./matchQuery.cjs");
30
- class NativeMediaQueryList {
31
- constructor(query) {
32
- this.query = query;
33
- this.notify();
34
- import_react_native.Dimensions.addEventListener("change", () => {
35
- this.notify();
36
- });
37
- }
38
- query;
39
- listeners = [];
40
- get orientation() {
41
- const windowDimensions = import_react_native.Dimensions.get("window");
42
- return windowDimensions.height > windowDimensions.width ? "portrait" : "landscape";
43
- }
44
- notify() {
45
- this.listeners.forEach(listener => {
46
- listener(this.orientation);
47
- });
48
- }
49
- addListener(listener) {
50
- this.listeners.push(listener);
51
- }
52
- removeListener(listener) {
53
- const index = this.listeners.indexOf(listener);
54
- if (index !== -1) this.listeners.splice(index, 1);
55
- }
56
- match(query, {
57
- width,
58
- height
59
- }) {
60
- return (0, import_matchQuery.matchQuery)(query, {
61
- type: "screen",
62
- orientation: height > width ? "portrait" : "landscape",
63
- "device-width": width,
64
- "device-height": height
65
- });
66
- }
67
- get matches() {
68
- const windowDimensions = import_react_native.Dimensions.get("window");
69
- const matches = (0, import_matchQuery.matchQuery)(this.query, {
70
- type: "screen",
71
- orientation: this.orientation,
72
- ...windowDimensions,
73
- "device-width": windowDimensions.width,
74
- "device-height": windowDimensions.height
75
- });
76
- return matches;
77
- }
78
- }
@@ -1,8 +0,0 @@
1
- import { setupMatchMedia } from "@tamagui/web";
2
- import { matchMedia } from "./matchMedia.mjs";
3
- function createMedia(media) {
4
- setupMatchMedia(matchMedia);
5
- return media;
6
- }
7
- export { createMedia };
8
- //# sourceMappingURL=createMedia.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["setupMatchMedia","matchMedia","createMedia","media"],"sources":["../../src/createMedia.ts"],"sourcesContent":[null],"mappings":"AACA,SAASA,eAAA,QAAuB;AAEhC,SAASC,UAAA,QAAkB;AAMpB,SAASC,YAIdC,KAAA,EAAa;EAGbH,eAAA,CAAgBC,UAAU;EAC1B,OAAOE,KAAA;AACT","ignoreList":[]}
@@ -1,8 +0,0 @@
1
- import { setupMatchMedia } from "@tamagui/web";
2
- import { matchMedia } from "./matchMedia.native.js";
3
- function createMedia(media) {
4
- setupMatchMedia(matchMedia);
5
- return media;
6
- }
7
- export { createMedia };
8
- //# sourceMappingURL=createMedia.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["setupMatchMedia","matchMedia","createMedia","media"],"sources":["../../src/createMedia.ts"],"sourcesContent":[null],"mappings":"AACA,SAASA,eAAA,QAAuB;AAEhC,SAASC,UAAA,QAAkB;AAMpB,SAASC,YAIdC,KAAA,EAAa;EAGbH,eAAA,CAAgBC,UAAU;EAC1B,OAAOE,KAAA;AACT","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc","ignoreList":[]}
@@ -1,53 +0,0 @@
1
- import { Dimensions } from "react-native-web";
2
- import { matchQuery } from "./matchQuery.mjs";
3
- class NativeMediaQueryList {
4
- constructor(query) {
5
- this.query = query;
6
- this.notify();
7
- Dimensions.addEventListener("change", () => {
8
- this.notify();
9
- });
10
- }
11
- query;
12
- listeners = [];
13
- get orientation() {
14
- const windowDimensions = Dimensions.get("window");
15
- return windowDimensions.height > windowDimensions.width ? "portrait" : "landscape";
16
- }
17
- notify() {
18
- this.listeners.forEach(listener => {
19
- listener(this.orientation);
20
- });
21
- }
22
- addListener(listener) {
23
- this.listeners.push(listener);
24
- }
25
- removeListener(listener) {
26
- const index = this.listeners.indexOf(listener);
27
- if (index !== -1) this.listeners.splice(index, 1);
28
- }
29
- match(query, {
30
- width,
31
- height
32
- }) {
33
- return matchQuery(query, {
34
- type: "screen",
35
- orientation: height > width ? "portrait" : "landscape",
36
- "device-width": width,
37
- "device-height": height
38
- });
39
- }
40
- get matches() {
41
- const windowDimensions = Dimensions.get("window");
42
- const matches = matchQuery(this.query, {
43
- type: "screen",
44
- orientation: this.orientation,
45
- ...windowDimensions,
46
- "device-width": windowDimensions.width,
47
- "device-height": windowDimensions.height
48
- });
49
- return matches;
50
- }
51
- }
52
- export { NativeMediaQueryList };
53
- //# sourceMappingURL=mediaQueryList.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["Dimensions","matchQuery","NativeMediaQueryList","constructor","query","notify","addEventListener","listeners","orientation","windowDimensions","get","height","width","forEach","listener","addListener","push","removeListener","index","indexOf","splice","match","type","matches"],"sources":["../../src/mediaQueryList.ts"],"sourcesContent":[null],"mappings":"AACA,SAASA,UAAA,QAAkB;AAE3B,SAASC,UAAA,QAAkB;AAMpB,MAAMC,oBAAA,CAA+C;EAQ1DC,YAAoBC,KAAA,EAAe;IAAf,KAAAA,KAAA,GAAAA,KAAA;IAClB,KAAKC,MAAA,CAAO;IACZL,UAAA,CAAWM,gBAAA,CAAiB,UAAU,MAAM;MAC1C,KAAKD,MAAA,CAAO;IACd,CAAC;EACH;EALoBD,KAAA;EAPZG,SAAA,GAAwB,EAAC;EAEjC,IAAYC,YAAA,EAA2B;IACrC,MAAMC,gBAAA,GAAmBT,UAAA,CAAWU,GAAA,CAAI,QAAQ;IAChD,OAAOD,gBAAA,CAAiBE,MAAA,GAASF,gBAAA,CAAiBG,KAAA,GAAQ,aAAa;EACzE;EASQP,OAAA,EAAS;IACf,KAAKE,SAAA,CAAUM,OAAA,CAASC,QAAA,IAAa;MACnCA,QAAA,CAAS,KAAKN,WAAW;IAC3B,CAAC;EACH;EAEAO,YAAYD,QAAA,EAA0B;IACpC,KAAKP,SAAA,CAAUS,IAAA,CAAKF,QAAQ;EAC9B;EAEAG,eAAeH,QAAA,EAA0B;IACvC,MAAMI,KAAA,GAAQ,KAAKX,SAAA,CAAUY,OAAA,CAAQL,QAAQ;IAC7C,IAAII,KAAA,KAAU,IAAI,KAAKX,SAAA,CAAUa,MAAA,CAAOF,KAAA,EAAO,CAAC;EAClD;EAEAG,MAAMjB,KAAA,EAAe;IAAEQ,KAAA;IAAOD;EAAO,GAA+C;IAClF,OAAOV,UAAA,CAAWG,KAAA,EAAO;MACvBkB,IAAA,EAAM;MACNd,WAAA,EAAaG,MAAA,GAASC,KAAA,GAAQ,aAAa;MAC3C,gBAAgBA,KAAA;MAChB,iBAAiBD;IACnB,CAAC;EACH;EAEA,IAAIY,QAAA,EAAmB;IACrB,MAAMd,gBAAA,GAAmBT,UAAA,CAAWU,GAAA,CAAI,QAAQ;IAChD,MAAMa,OAAA,GAAUtB,UAAA,CAAW,KAAKG,KAAA,EAAO;MACrCkB,IAAA,EAAM;MACNd,WAAA,EAAa,KAAKA,WAAA;MAClB,GAAGC,gBAAA;MACH,gBAAgBA,gBAAA,CAAiBG,KAAA;MACjC,iBAAiBH,gBAAA,CAAiBE;IACpC,CAAC;IACD,OAAOY,OAAA;EACT;AACF","ignoreList":[]}
@@ -1,19 +0,0 @@
1
- import type { MediaQueryObject } from '@tamagui/web'
2
- import { setupMatchMedia } from '@tamagui/web'
3
-
4
- import { matchMedia } from './matchMedia'
5
-
6
- /**
7
- * @deprecated you no longer need to call createMedia or import @tamagui/react-native-media-driver at all.
8
- * Tamagui now automatically handles setting this up, you can just pass a plain object to createTamagui.
9
- */
10
- export function createMedia<
11
- A extends {
12
- [key: string]: MediaQueryObject
13
- },
14
- >(media: A): A {
15
- // this should ideally return a diff object that is then passed to createTamagui
16
- // but works for now we dont really support swapping out media drivers
17
- setupMatchMedia(matchMedia)
18
- return media
19
- }
@@ -1,60 +0,0 @@
1
- import type { MediaQueryList } from '@tamagui/web'
2
- import { Dimensions } from 'react-native'
3
-
4
- import { matchQuery } from './matchQuery'
5
-
6
- type Orientation = 'landscape' | 'portrait'
7
-
8
- type Listener = (orientation: Orientation) => void
9
-
10
- export class NativeMediaQueryList implements MediaQueryList {
11
- private listeners: Listener[] = []
12
-
13
- private get orientation(): Orientation {
14
- const windowDimensions = Dimensions.get('window')
15
- return windowDimensions.height > windowDimensions.width ? 'portrait' : 'landscape'
16
- }
17
-
18
- constructor(private query: string) {
19
- this.notify()
20
- Dimensions.addEventListener('change', () => {
21
- this.notify()
22
- })
23
- }
24
-
25
- private notify() {
26
- this.listeners.forEach((listener) => {
27
- listener(this.orientation)
28
- })
29
- }
30
-
31
- addListener(listener: Listener): void {
32
- this.listeners.push(listener)
33
- }
34
-
35
- removeListener(listener: Listener): void {
36
- const index = this.listeners.indexOf(listener)
37
- if (index !== -1) this.listeners.splice(index, 1)
38
- }
39
-
40
- match(query: string, { width, height }: { width: number; height: number }): boolean {
41
- return matchQuery(query, {
42
- type: 'screen',
43
- orientation: height > width ? 'portrait' : 'landscape',
44
- 'device-width': width,
45
- 'device-height': height,
46
- })
47
- }
48
-
49
- get matches(): boolean {
50
- const windowDimensions = Dimensions.get('window')
51
- const matches = matchQuery(this.query, {
52
- type: 'screen',
53
- orientation: this.orientation,
54
- ...windowDimensions,
55
- 'device-width': windowDimensions.width,
56
- 'device-height': windowDimensions.height,
57
- })
58
- return matches
59
- }
60
- }
@@ -1,10 +0,0 @@
1
- import type { MediaQueryObject } from "@tamagui/web";
2
- /**
3
- * @deprecated you no longer need to call createMedia or import @tamagui/react-native-media-driver at all.
4
- * Tamagui now automatically handles setting this up, you can just pass a plain object to createTamagui.
5
- */
6
- export declare function createMedia<A extends {
7
- [key: string]: MediaQueryObject;
8
- }>(media: A): A;
9
-
10
- //# sourceMappingURL=createMedia.d.ts.map
@@ -1,11 +0,0 @@
1
- {
2
- "mappings": "AAAA,cAAc,wBAAwB;;;;;AAStC,OAAO,iBAAS,YACd,UAAU;gBACO;GAEjB,OAAO,IAAI",
3
- "names": [],
4
- "sources": [
5
- "src/createMedia.ts"
6
- ],
7
- "version": 3,
8
- "sourcesContent": [
9
- "import type { MediaQueryObject } from '@tamagui/web'\nimport { setupMatchMedia } from '@tamagui/web'\n\nimport { matchMedia } from './matchMedia'\n\n/**\n * @deprecated you no longer need to call createMedia or import @tamagui/react-native-media-driver at all.\n * Tamagui now automatically handles setting this up, you can just pass a plain object to createTamagui.\n */\nexport function createMedia<\n A extends {\n [key: string]: MediaQueryObject\n },\n>(media: A): A {\n // this should ideally return a diff object that is then passed to createTamagui\n // but works for now we dont really support swapping out media drivers\n setupMatchMedia(matchMedia)\n return media\n}\n"
10
- ]
11
- }
@@ -1,11 +0,0 @@
1
- {
2
- "mappings": "AAAA,cAAc,sBAAsB;KAK/B,cAAc,cAAc;KAE5B,YAAY,aAAa;AAE9B,OAAO,cAAM,gCAAgC,eAAe;CAQ9C;CAPZ,QAAQ;CAER,YAAY;CAKZ,YAAY,AAAQ;CAOpB,QAAQ;CAMR,YAAY,UAAU;CAItB,eAAe,UAAU;CAKzB,MAAM,eAAe,EAAE,OAAO,UAAU;EAAE;EAAe;;CASzD,IAAI",
3
- "names": [],
4
- "sources": [
5
- "src/mediaQueryList.ts"
6
- ],
7
- "version": 3,
8
- "sourcesContent": [
9
- "import type { MediaQueryList } from '@tamagui/web'\nimport { Dimensions } from 'react-native'\n\nimport { matchQuery } from './matchQuery'\n\ntype Orientation = 'landscape' | 'portrait'\n\ntype Listener = (orientation: Orientation) => void\n\nexport class NativeMediaQueryList implements MediaQueryList {\n private listeners: Listener[] = []\n\n private get orientation(): Orientation {\n const windowDimensions = Dimensions.get('window')\n return windowDimensions.height > windowDimensions.width ? 'portrait' : 'landscape'\n }\n\n constructor(private query: string) {\n this.notify()\n Dimensions.addEventListener('change', () => {\n this.notify()\n })\n }\n\n private notify() {\n this.listeners.forEach((listener) => {\n listener(this.orientation)\n })\n }\n\n addListener(listener: Listener): void {\n this.listeners.push(listener)\n }\n\n removeListener(listener: Listener): void {\n const index = this.listeners.indexOf(listener)\n if (index !== -1) this.listeners.splice(index, 1)\n }\n\n match(query: string, { width, height }: { width: number; height: number }): boolean {\n return matchQuery(query, {\n type: 'screen',\n orientation: height > width ? 'portrait' : 'landscape',\n 'device-width': width,\n 'device-height': height,\n })\n }\n\n get matches(): boolean {\n const windowDimensions = Dimensions.get('window')\n const matches = matchQuery(this.query, {\n type: 'screen',\n orientation: this.orientation,\n ...windowDimensions,\n 'device-width': windowDimensions.width,\n 'device-height': windowDimensions.height,\n })\n return matches\n }\n}\n"
10
- ]
11
- }