@tamagui/react-native-media-driver 2.7.7 → 3.0.0-beta.637.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 (51) hide show
  1. package/dist/cjs/index.cjs +10 -12
  2. package/dist/cjs/index.native.cjs +21 -0
  3. package/dist/cjs/index.native.js +10 -11
  4. package/dist/cjs/index.native.js.map +1 -1
  5. package/dist/cjs/matchMedia.cjs +15 -18
  6. package/dist/cjs/matchMedia.native.cjs +30 -0
  7. package/dist/cjs/matchMedia.native.js +17 -19
  8. package/dist/cjs/matchMedia.native.js.map +1 -1
  9. package/dist/cjs/matchQuery.cjs +115 -132
  10. package/dist/cjs/matchQuery.native.cjs +145 -0
  11. package/dist/cjs/matchQuery.native.js +117 -133
  12. package/dist/cjs/matchQuery.native.js.map +1 -1
  13. package/dist/cjs/mediaQueryList.cjs +102 -66
  14. package/dist/cjs/mediaQueryList.native.cjs +180 -0
  15. package/dist/cjs/mediaQueryList.native.js +158 -110
  16. package/dist/cjs/mediaQueryList.native.js.map +1 -1
  17. package/dist/esm/index.js +1 -3
  18. package/dist/esm/index.mjs +1 -3
  19. package/dist/esm/index.native.js +1 -3
  20. package/dist/esm/matchMedia.mjs +1 -0
  21. package/dist/esm/matchMedia.mjs.map +1 -1
  22. package/dist/esm/matchMedia.native.js +4 -2
  23. package/dist/esm/matchMedia.native.js.map +1 -1
  24. package/dist/esm/matchQuery.mjs +100 -115
  25. package/dist/esm/matchQuery.mjs.map +1 -1
  26. package/dist/esm/matchQuery.native.js +102 -117
  27. package/dist/esm/matchQuery.native.js.map +1 -1
  28. package/dist/esm/mediaQueryList.mjs +90 -49
  29. package/dist/esm/mediaQueryList.mjs.map +1 -1
  30. package/dist/esm/mediaQueryList.native.js +146 -94
  31. package/dist/esm/mediaQueryList.native.js.map +1 -1
  32. package/package.json +7 -4
  33. package/src/index.ts +0 -1
  34. package/src/mediaQueryList.ts +58 -3
  35. package/types/index.d.ts +0 -1
  36. package/types/index.d.ts.map +2 -2
  37. package/types/mediaQueryList.d.ts +2 -2
  38. package/types/mediaQueryList.d.ts.map +2 -2
  39. package/dist/cjs/createMedia.cjs +0 -33
  40. package/dist/cjs/createMedia.native.js +0 -36
  41. package/dist/cjs/createMedia.native.js.map +0 -1
  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/src/createMedia.ts +0 -19
  50. package/types/createMedia.d.ts +0 -10
  51. package/types/createMedia.d.ts.map +0 -11
@@ -1,53 +1,94 @@
1
- import { Dimensions } from "react-native-web";
1
+ import { AccessibilityInfo, Dimensions } from "react-native-web";
2
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
- }
3
+
4
+ const REDUCED_MOTION_RE = /\(\s*prefers-reduced-motion\s*:\s*([a-z-]+)\s*\)/i;
5
+ let reducedMotionEnabled = false;
6
+ let reducedMotionInitialized = false;
7
+ const reducedMotionListeners = /* @__PURE__ */ new Set();
8
+ function ensureReducedMotionSubscription() {
9
+ if (reducedMotionInitialized) return;
10
+ reducedMotionInitialized = true;
11
+ AccessibilityInfo.isReduceMotionEnabled?.().then((value) => {
12
+ if (value !== reducedMotionEnabled) {
13
+ reducedMotionEnabled = value;
14
+ reducedMotionListeners.forEach((cb) => cb());
15
+ }
16
+ }).catch(() => {});
17
+ AccessibilityInfo.addEventListener?.("reduceMotionChanged", (value) => {
18
+ if (value === reducedMotionEnabled) return;
19
+ reducedMotionEnabled = value;
20
+ reducedMotionListeners.forEach((cb) => cb());
21
+ });
51
22
  }
23
+ var NativeMediaQueryList = class {
24
+ constructor(query) {
25
+ this.query = query;
26
+ const reducedMotionMatch = query.match(REDUCED_MOTION_RE);
27
+ if (reducedMotionMatch) {
28
+ this.reducedMotionExpected = reducedMotionMatch[1];
29
+ ensureReducedMotionSubscription();
30
+ return;
31
+ }
32
+ this.notify();
33
+ Dimensions.addEventListener("change", () => {
34
+ this.notify();
35
+ });
36
+ }
37
+ query;
38
+ listeners = [];
39
+ reducedMotionExpected = null;
40
+ get orientation() {
41
+ const windowDimensions = Dimensions.get("window");
42
+ return windowDimensions.height > windowDimensions.width ? "portrait" : "landscape";
43
+ }
44
+ notify() {
45
+ this.listeners.forEach((listener) => {
46
+ listener();
47
+ });
48
+ }
49
+ addListener(listener) {
50
+ if (this.reducedMotionExpected) {
51
+ reducedMotionListeners.add(listener);
52
+ this.listeners.push(listener);
53
+ return;
54
+ }
55
+ this.listeners.push(listener);
56
+ }
57
+ removeListener(listener) {
58
+ if (this.reducedMotionExpected) {
59
+ reducedMotionListeners.delete(listener);
60
+ }
61
+ const index = this.listeners.indexOf(listener);
62
+ if (index !== -1) this.listeners.splice(index, 1);
63
+ }
64
+ match(query, { width, height }) {
65
+ const reducedMotionMatch = query.match(REDUCED_MOTION_RE);
66
+ if (reducedMotionMatch) {
67
+ const expected = reducedMotionMatch[1];
68
+ return expected === "reduce" ? reducedMotionEnabled : !reducedMotionEnabled;
69
+ }
70
+ return matchQuery(query, {
71
+ type: "screen",
72
+ orientation: height > width ? "portrait" : "landscape",
73
+ "device-width": width,
74
+ "device-height": height
75
+ });
76
+ }
77
+ get matches() {
78
+ if (this.reducedMotionExpected) {
79
+ return this.reducedMotionExpected === "reduce" ? reducedMotionEnabled : !reducedMotionEnabled;
80
+ }
81
+ const windowDimensions = Dimensions.get("window");
82
+ const matches = matchQuery(this.query, {
83
+ type: "screen",
84
+ orientation: this.orientation,
85
+ ...windowDimensions,
86
+ "device-width": windowDimensions.width,
87
+ "device-height": windowDimensions.height
88
+ });
89
+ return matches;
90
+ }
91
+ };
92
+
52
93
  export { NativeMediaQueryList };
53
94
  //# sourceMappingURL=mediaQueryList.mjs.map
@@ -1 +1 @@
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
+ {"version":3,"file":"mediaQueryList.js","names":[],"sources":["esm/mediaQueryList.js"],"sourcesContent":["import { AccessibilityInfo, Dimensions } from \"react-native-web\";\nimport { matchQuery } from \"./matchQuery\";\nconst REDUCED_MOTION_RE = /\\(\\s*prefers-reduced-motion\\s*:\\s*([a-z-]+)\\s*\\)/i;\nlet reducedMotionEnabled = false;\nlet reducedMotionInitialized = false;\nconst reducedMotionListeners = /* @__PURE__ */ new Set();\nfunction ensureReducedMotionSubscription() {\n if (reducedMotionInitialized) return;\n reducedMotionInitialized = true;\n AccessibilityInfo.isReduceMotionEnabled?.().then((value) => {\n if (value !== reducedMotionEnabled) {\n reducedMotionEnabled = value;\n reducedMotionListeners.forEach((cb) => cb());\n }\n }).catch(() => {\n });\n AccessibilityInfo.addEventListener?.(\"reduceMotionChanged\", (value) => {\n if (value === reducedMotionEnabled) return;\n reducedMotionEnabled = value;\n reducedMotionListeners.forEach((cb) => cb());\n });\n}\nclass NativeMediaQueryList {\n constructor(query) {\n this.query = query;\n const reducedMotionMatch = query.match(REDUCED_MOTION_RE);\n if (reducedMotionMatch) {\n this.reducedMotionExpected = reducedMotionMatch[1];\n ensureReducedMotionSubscription();\n return;\n }\n this.notify();\n Dimensions.addEventListener(\"change\", () => {\n this.notify();\n });\n }\n query;\n listeners = [];\n reducedMotionExpected = null;\n get orientation() {\n const windowDimensions = Dimensions.get(\"window\");\n return windowDimensions.height > windowDimensions.width ? \"portrait\" : \"landscape\";\n }\n notify() {\n this.listeners.forEach((listener) => {\n listener();\n });\n }\n addListener(listener) {\n if (this.reducedMotionExpected) {\n reducedMotionListeners.add(listener);\n this.listeners.push(listener);\n return;\n }\n this.listeners.push(listener);\n }\n removeListener(listener) {\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 match(query, { width, height }) {\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 get matches() {\n if (this.reducedMotionExpected) {\n return this.reducedMotionExpected === \"reduce\" ? reducedMotionEnabled : !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}\nexport {\n NativeMediaQueryList\n};\n//# sourceMappingURL=mediaQueryList.js.map\n"],"mappings":";;;;AAEA,MAAM,oBAAoB;AAC1B,IAAI,uBAAuB;AAC3B,IAAI,2BAA2B;AAC/B,MAAM,yCAAyC,IAAI,IAAI;AACvD,SAAS,kCAAkC;CACzC,IAAI,0BAA0B;CAC9B,2BAA2B;CAC3B,kBAAkB,wBAAwB,EAAE,MAAM,UAAU;EAC1D,IAAI,UAAU,sBAAsB;GAClC,uBAAuB;GACvB,uBAAuB,SAAS,OAAO,GAAG,CAAC;EAC7C;CACF,CAAC,EAAE,YAAY,CACf,CAAC;CACD,kBAAkB,mBAAmB,wBAAwB,UAAU;EACrE,IAAI,UAAU,sBAAsB;EACpC,uBAAuB;EACvB,uBAAuB,SAAS,OAAO,GAAG,CAAC;CAC7C,CAAC;AACH;AACA,IAAM,uBAAN,MAA2B;CACzB,YAAY,OAAO;EACjB,KAAK,QAAQ;EACb,MAAM,qBAAqB,MAAM,MAAM,iBAAiB;EACxD,IAAI,oBAAoB;GACtB,KAAK,wBAAwB,mBAAmB;GAChD,gCAAgC;GAChC;EACF;EACA,KAAK,OAAO;EACZ,WAAW,iBAAiB,gBAAgB;GAC1C,KAAK,OAAO;EACd,CAAC;CACH;CACA;CACA,YAAY,CAAC;CACb,wBAAwB;CACxB,IAAI,cAAc;EAChB,MAAM,mBAAmB,WAAW,IAAI,QAAQ;EAChD,OAAO,iBAAiB,SAAS,iBAAiB,QAAQ,aAAa;CACzE;CACA,SAAS;EACP,KAAK,UAAU,SAAS,aAAa;GACnC,SAAS;EACX,CAAC;CACH;CACA,YAAY,UAAU;EACpB,IAAI,KAAK,uBAAuB;GAC9B,uBAAuB,IAAI,QAAQ;GACnC,KAAK,UAAU,KAAK,QAAQ;GAC5B;EACF;EACA,KAAK,UAAU,KAAK,QAAQ;CAC9B;CACA,eAAe,UAAU;EACvB,IAAI,KAAK,uBAAuB;GAC9B,uBAAuB,OAAO,QAAQ;EACxC;EACA,MAAM,QAAQ,KAAK,UAAU,QAAQ,QAAQ;EAC7C,IAAI,UAAU,CAAC,GAAG,KAAK,UAAU,OAAO,OAAO,CAAC;CAClD;CACA,MAAM,OAAO,EAAE,OAAO,UAAU;EAC9B,MAAM,qBAAqB,MAAM,MAAM,iBAAiB;EACxD,IAAI,oBAAoB;GACtB,MAAM,WAAW,mBAAmB;GACpC,OAAO,aAAa,WAAW,uBAAuB,CAAC;EACzD;EACA,OAAO,WAAW,OAAO;GACvB,MAAM;GACN,aAAa,SAAS,QAAQ,aAAa;GAC3C,gBAAgB;GAChB,iBAAiB;EACnB,CAAC;CACH;CACA,IAAI,UAAU;EACZ,IAAI,KAAK,uBAAuB;GAC9B,OAAO,KAAK,0BAA0B,WAAW,uBAAuB,CAAC;EAC3E;EACA,MAAM,mBAAmB,WAAW,IAAI,QAAQ;EAChD,MAAM,UAAU,WAAW,KAAK,OAAO;GACrC,MAAM;GACN,aAAa,KAAK;GAClB,GAAG;GACH,gBAAgB,iBAAiB;GACjC,iBAAiB,iBAAiB;EACpC,CAAC;EACD,OAAO;CACT;AACF"}
@@ -1,106 +1,158 @@
1
- import { Dimensions } from "react-native";
1
+ import { AccessibilityInfo, Dimensions } from "react-native";
2
2
  import { matchQuery } from "./matchQuery.native.js";
3
+
3
4
  function _class_call_check(instance, Constructor) {
4
- if (!(instance instanceof Constructor)) {
5
- throw new TypeError("Cannot call a class as a function");
6
- }
5
+ if (!(instance instanceof Constructor)) {
6
+ throw new TypeError("Cannot call a class as a function");
7
+ }
7
8
  }
8
9
  function _defineProperties(target, props) {
9
- for (var i = 0; i < props.length; i++) {
10
- var descriptor = props[i];
11
- descriptor.enumerable = descriptor.enumerable || false;
12
- descriptor.configurable = true;
13
- if ("value" in descriptor) descriptor.writable = true;
14
- Object.defineProperty(target, descriptor.key, descriptor);
15
- }
10
+ for (var i = 0; i < props.length; i++) {
11
+ var descriptor = props[i];
12
+ descriptor.enumerable = descriptor.enumerable || false;
13
+ descriptor.configurable = true;
14
+ if ("value" in descriptor) descriptor.writable = true;
15
+ Object.defineProperty(target, descriptor.key, descriptor);
16
+ }
16
17
  }
17
18
  function _create_class(Constructor, protoProps, staticProps) {
18
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
19
- if (staticProps) _defineProperties(Constructor, staticProps);
20
- return Constructor;
19
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
20
+ if (staticProps) _defineProperties(Constructor, staticProps);
21
+ return Constructor;
21
22
  }
22
23
  function _define_property(obj, key, value) {
23
- if (key in obj) {
24
- Object.defineProperty(obj, key, {
25
- value,
26
- enumerable: true,
27
- configurable: true,
28
- writable: true
29
- });
30
- } else {
31
- obj[key] = value;
32
- }
33
- return obj;
24
+ if (key in obj) {
25
+ Object.defineProperty(obj, key, {
26
+ value,
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true
30
+ });
31
+ } else {
32
+ obj[key] = value;
33
+ }
34
+ return obj;
35
+ }
36
+ var REDUCED_MOTION_RE = /\(\s*prefers-reduced-motion\s*:\s*([a-z-]+)\s*\)/i;
37
+ var reducedMotionEnabled = false;
38
+ var reducedMotionInitialized = false;
39
+ var reducedMotionListeners = /* @__PURE__ */ new Set();
40
+ function ensureReducedMotionSubscription() {
41
+ var _AccessibilityInfo_isReduceMotionEnabled, _AccessibilityInfo_addEventListener;
42
+ if (reducedMotionInitialized) return;
43
+ reducedMotionInitialized = true;
44
+ (_AccessibilityInfo_isReduceMotionEnabled = AccessibilityInfo.isReduceMotionEnabled) === null || _AccessibilityInfo_isReduceMotionEnabled === void 0 ? void 0 : _AccessibilityInfo_isReduceMotionEnabled.call(AccessibilityInfo).then(function(value) {
45
+ if (value !== reducedMotionEnabled) {
46
+ reducedMotionEnabled = value;
47
+ reducedMotionListeners.forEach(function(cb) {
48
+ return cb();
49
+ });
50
+ }
51
+ }).catch(function() {});
52
+ (_AccessibilityInfo_addEventListener = AccessibilityInfo.addEventListener) === null || _AccessibilityInfo_addEventListener === void 0 ? void 0 : _AccessibilityInfo_addEventListener.call(AccessibilityInfo, "reduceMotionChanged", function(value) {
53
+ if (value === reducedMotionEnabled) return;
54
+ reducedMotionEnabled = value;
55
+ reducedMotionListeners.forEach(function(cb) {
56
+ return cb();
57
+ });
58
+ });
34
59
  }
35
- var NativeMediaQueryList = /* @__PURE__ */function () {
36
- "use strict";
60
+ var NativeMediaQueryList = /* @__PURE__ */ (function() {
61
+ "use strict";
62
+ function NativeMediaQueryList2(query) {
63
+ var _this = this;
64
+ _class_call_check(this, NativeMediaQueryList2);
65
+ _define_property(this, "query", void 0);
66
+ _define_property(this, "listeners", void 0);
67
+ _define_property(this, "reducedMotionExpected", void 0);
68
+ this.query = query;
69
+ this.listeners = [];
70
+ this.reducedMotionExpected = null;
71
+ var reducedMotionMatch = query.match(REDUCED_MOTION_RE);
72
+ if (reducedMotionMatch) {
73
+ this.reducedMotionExpected = reducedMotionMatch[1];
74
+ ensureReducedMotionSubscription();
75
+ return;
76
+ }
77
+ this.notify();
78
+ Dimensions.addEventListener("change", function() {
79
+ _this.notify();
80
+ });
81
+ }
82
+ _create_class(NativeMediaQueryList2, [
83
+ {
84
+ key: "orientation",
85
+ get: function get() {
86
+ var windowDimensions = Dimensions.get("window");
87
+ return windowDimensions.height > windowDimensions.width ? "portrait" : "landscape";
88
+ }
89
+ },
90
+ {
91
+ key: "notify",
92
+ value: function notify() {
93
+ this.listeners.forEach(function(listener) {
94
+ listener();
95
+ });
96
+ }
97
+ },
98
+ {
99
+ key: "addListener",
100
+ value: function addListener(listener) {
101
+ if (this.reducedMotionExpected) {
102
+ reducedMotionListeners.add(listener);
103
+ this.listeners.push(listener);
104
+ return;
105
+ }
106
+ this.listeners.push(listener);
107
+ }
108
+ },
109
+ {
110
+ key: "removeListener",
111
+ value: function removeListener(listener) {
112
+ if (this.reducedMotionExpected) {
113
+ reducedMotionListeners.delete(listener);
114
+ }
115
+ var index = this.listeners.indexOf(listener);
116
+ if (index !== -1) this.listeners.splice(index, 1);
117
+ }
118
+ },
119
+ {
120
+ key: "match",
121
+ value: function match(query, param) {
122
+ var { width, height } = param;
123
+ var reducedMotionMatch = query.match(REDUCED_MOTION_RE);
124
+ if (reducedMotionMatch) {
125
+ var expected = reducedMotionMatch[1];
126
+ return expected === "reduce" ? reducedMotionEnabled : !reducedMotionEnabled;
127
+ }
128
+ return matchQuery(query, {
129
+ type: "screen",
130
+ orientation: height > width ? "portrait" : "landscape",
131
+ "device-width": width,
132
+ "device-height": height
133
+ });
134
+ }
135
+ },
136
+ {
137
+ key: "matches",
138
+ get: function get() {
139
+ if (this.reducedMotionExpected) {
140
+ return this.reducedMotionExpected === "reduce" ? reducedMotionEnabled : !reducedMotionEnabled;
141
+ }
142
+ var windowDimensions = Dimensions.get("window");
143
+ var matches = matchQuery(this.query, {
144
+ type: "screen",
145
+ orientation: this.orientation,
146
+ ...windowDimensions,
147
+ "device-width": windowDimensions.width,
148
+ "device-height": windowDimensions.height
149
+ });
150
+ return matches;
151
+ }
152
+ }
153
+ ]);
154
+ return NativeMediaQueryList2;
155
+ })();
37
156
 
38
- function NativeMediaQueryList2(query) {
39
- var _this = this;
40
- _class_call_check(this, NativeMediaQueryList2);
41
- _define_property(this, "query", void 0);
42
- _define_property(this, "listeners", void 0);
43
- this.query = query;
44
- this.listeners = [];
45
- this.notify();
46
- Dimensions.addEventListener("change", function () {
47
- _this.notify();
48
- });
49
- }
50
- _create_class(NativeMediaQueryList2, [{
51
- key: "orientation",
52
- get: function get() {
53
- var windowDimensions = Dimensions.get("window");
54
- return windowDimensions.height > windowDimensions.width ? "portrait" : "landscape";
55
- }
56
- }, {
57
- key: "notify",
58
- value: function notify() {
59
- var _this = this;
60
- this.listeners.forEach(function (listener) {
61
- listener(_this.orientation);
62
- });
63
- }
64
- }, {
65
- key: "addListener",
66
- value: function addListener(listener) {
67
- this.listeners.push(listener);
68
- }
69
- }, {
70
- key: "removeListener",
71
- value: function removeListener(listener) {
72
- var index = this.listeners.indexOf(listener);
73
- if (index !== -1) this.listeners.splice(index, 1);
74
- }
75
- }, {
76
- key: "match",
77
- value: function match(query, param) {
78
- var {
79
- width,
80
- height
81
- } = param;
82
- return matchQuery(query, {
83
- type: "screen",
84
- orientation: height > width ? "portrait" : "landscape",
85
- "device-width": width,
86
- "device-height": height
87
- });
88
- }
89
- }, {
90
- key: "matches",
91
- get: function get() {
92
- var windowDimensions = Dimensions.get("window");
93
- var matches = matchQuery(this.query, {
94
- type: "screen",
95
- orientation: this.orientation,
96
- ...windowDimensions,
97
- "device-width": windowDimensions.width,
98
- "device-height": windowDimensions.height
99
- });
100
- return matches;
101
- }
102
- }]);
103
- return NativeMediaQueryList2;
104
- }();
105
157
  export { NativeMediaQueryList };
106
158
  //# sourceMappingURL=mediaQueryList.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Dimensions","matchQuery","_class_call_check","instance","Constructor","TypeError","_defineProperties","target","props","i","length","descriptor","enumerable","configurable","writable","Object","defineProperty","key","_create_class","protoProps","staticProps","prototype","_define_property","obj","value","NativeMediaQueryList","NativeMediaQueryList2","query","_this","listeners","notify","addEventListener"],"sources":["../../src/mediaQueryList.ts"],"sourcesContent":[null],"mappings":"AACA,SAASA,UAAA,QAAkB;AAE3B,SAASC,UAAA,QAAkB;AAMpB,SAAMC,kBAA+CC,QAAA,EAAAC,WAAA;EAQ1D,MAAAD,QAAoB,YAAeC,WAAA;IAAf,UAAAC,SAAA;EAClB;AACA;AACE,SAAAC,iBAAYA,CAAAC,MAAA,EAAAC,KAAA;EAAA,KACb,IAAAC,CAAA,MAAAA,CAAA,GAAAD,KAAA,CAAAE,MAAA,EAAAD,CAAA;IACH,IAAAE,UAAA,GAAAH,KAAA,CAAAC,CAAA;IALoBE,UAAA,CAAAC,UAAA,GAAAD,UAAA,CAAAC,UAAA;IAPZD,UAAwB,CAACE,YAAA;IAEjC,IAAY,WAAAF,UAA2B,EAAAA,UAAA,CAAAG,QAAA;IACrCC,MAAM,CAAAC,cAAA,CAAAT,MAAmB,EAAAI,UAAe,CAAAM,GAAA,EAAAN,UAAQ;EAChD;AAAuE;AACzE,SASQO,aAASA,CAAAd,WAAA,EAAAe,UAAA,EAAAC,WAAA;EACf,IAAAD,UAAK,EAAAb,iBAAmB,CAAAF,WAAa,CAAAiB,SAAA,EAAAF,UAAA;EACnC,IAAAC,WAAS,EAAAd,iBAAgB,CAAAF,WAAA,EAAAgB,WAAA;EAAA,OAC1BhB,WAAA;AAAA;AACH,SAEAkB,gBAAsCA,CAAAC,GAAA,EAAAN,GAAA,EAAAO,KAAA;EACpC,IAAAP,GAAK,IAAAM,GAAA;IACPR,MAAA,CAAAC,cAAA,CAAAO,GAAA,EAAAN,GAAA;MAEAO,KAAA;MACEZ,UAAM,EAAQ;MACdC,YAAc,MAAI;MACpBC,QAAA;IAEA;EACE;IAAyBS,GACvB,CAAAN,GAAA,CAAM,GAAAO,KAAA;EAAA;EACqC,OAC3CD,GAAA;AAAgB;AACC,IACnBE,oBAAC;EACH;;EAEA,SAAIC,qBAAmBA,CAAAC,KAAA;IACrB,IAAAC,KAAM;IACN1B,iBAAgB,OAAAwB,qBAAuB;IAAAJ,gBAC/B;IAAAA,gBACO,KAAK;IAAA,IAClB,CAAGK,KAAA,GAAAA,KAAA;IAAA,IACH,CAAAE,SAAA,KAAgB;IAAiB,IACjC,CAAAC,MAAA;IACF9B,UAAC,CAAA+B,gBAAA;MACDH,KAAO,CAAAE,MAAA;IACT;EACF","ignoreList":[]}
1
+ {"version":3,"file":"mediaQueryList.native.js","names":[],"sources":["esm/mediaQueryList.native.js"],"sourcesContent":["import { AccessibilityInfo, Dimensions } from \"react-native\";\nimport { matchQuery } from \"./matchQuery\";\nfunction _class_call_check(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\nfunction _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n}\nfunction _create_class(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n return Constructor;\n}\nfunction _define_property(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n return obj;\n}\nvar REDUCED_MOTION_RE = /\\(\\s*prefers-reduced-motion\\s*:\\s*([a-z-]+)\\s*\\)/i;\nvar reducedMotionEnabled = false;\nvar reducedMotionInitialized = false;\nvar reducedMotionListeners = /* @__PURE__ */ new Set();\nfunction ensureReducedMotionSubscription() {\n var _AccessibilityInfo_isReduceMotionEnabled, _AccessibilityInfo_addEventListener;\n if (reducedMotionInitialized) return;\n reducedMotionInitialized = true;\n (_AccessibilityInfo_isReduceMotionEnabled = AccessibilityInfo.isReduceMotionEnabled) === null || _AccessibilityInfo_isReduceMotionEnabled === void 0 ? void 0 : _AccessibilityInfo_isReduceMotionEnabled.call(AccessibilityInfo).then(function(value) {\n if (value !== reducedMotionEnabled) {\n reducedMotionEnabled = value;\n reducedMotionListeners.forEach(function(cb) {\n return cb();\n });\n }\n }).catch(function() {\n });\n (_AccessibilityInfo_addEventListener = AccessibilityInfo.addEventListener) === null || _AccessibilityInfo_addEventListener === void 0 ? void 0 : _AccessibilityInfo_addEventListener.call(AccessibilityInfo, \"reduceMotionChanged\", function(value) {\n if (value === reducedMotionEnabled) return;\n reducedMotionEnabled = value;\n reducedMotionListeners.forEach(function(cb) {\n return cb();\n });\n });\n}\nvar NativeMediaQueryList = /* @__PURE__ */ (function() {\n \"use strict\";\n function NativeMediaQueryList2(query) {\n var _this = this;\n _class_call_check(this, NativeMediaQueryList2);\n _define_property(this, \"query\", void 0);\n _define_property(this, \"listeners\", void 0);\n _define_property(this, \"reducedMotionExpected\", void 0);\n this.query = query;\n this.listeners = [];\n this.reducedMotionExpected = null;\n var reducedMotionMatch = query.match(REDUCED_MOTION_RE);\n if (reducedMotionMatch) {\n this.reducedMotionExpected = reducedMotionMatch[1];\n ensureReducedMotionSubscription();\n return;\n }\n this.notify();\n Dimensions.addEventListener(\"change\", function() {\n _this.notify();\n });\n }\n _create_class(NativeMediaQueryList2, [\n {\n key: \"orientation\",\n get: function get() {\n var windowDimensions = Dimensions.get(\"window\");\n return windowDimensions.height > windowDimensions.width ? \"portrait\" : \"landscape\";\n }\n },\n {\n key: \"notify\",\n value: function notify() {\n this.listeners.forEach(function(listener) {\n listener();\n });\n }\n },\n {\n key: \"addListener\",\n value: function addListener(listener) {\n if (this.reducedMotionExpected) {\n reducedMotionListeners.add(listener);\n this.listeners.push(listener);\n return;\n }\n this.listeners.push(listener);\n }\n },\n {\n key: \"removeListener\",\n value: function removeListener(listener) {\n if (this.reducedMotionExpected) {\n reducedMotionListeners.delete(listener);\n }\n var index = this.listeners.indexOf(listener);\n if (index !== -1) this.listeners.splice(index, 1);\n }\n },\n {\n key: \"match\",\n value: function match(query, param) {\n var { width, height } = param;\n var reducedMotionMatch = query.match(REDUCED_MOTION_RE);\n if (reducedMotionMatch) {\n var 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 {\n key: \"matches\",\n get: function get() {\n if (this.reducedMotionExpected) {\n return this.reducedMotionExpected === \"reduce\" ? reducedMotionEnabled : !reducedMotionEnabled;\n }\n var windowDimensions = Dimensions.get(\"window\");\n var 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 ]);\n return NativeMediaQueryList2;\n})();\nexport {\n NativeMediaQueryList\n};\n//# sourceMappingURL=mediaQueryList.js.map\n"],"mappings":"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/react-native-media-driver",
3
- "version": "2.7.7",
3
+ "version": "3.0.0-beta.637.1",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "files": [
@@ -35,11 +35,14 @@
35
35
  "clean:build": "tamagui-build clean:build"
36
36
  },
37
37
  "dependencies": {
38
- "@tamagui/web": "2.7.7"
38
+ "@tamagui/web": "3.0.0-beta.637.1"
39
39
  },
40
40
  "devDependencies": {
41
- "@tamagui/build": "2.7.7",
42
- "react-native": "0.83.2"
41
+ "@tamagui/build": "3.0.0-beta.637.1",
42
+ "react-native": "0.86.2"
43
+ },
44
+ "peerDependencies": {
45
+ "react-native-web": "*"
43
46
  },
44
47
  "repository": {
45
48
  "type": "git",
package/src/index.ts CHANGED
@@ -1,2 +1 @@
1
- export * from './createMedia'
2
1
  export * from './matchMedia'
@@ -1,14 +1,44 @@
1
1
  import type { MediaQueryList } from '@tamagui/web'
2
- import { Dimensions } from 'react-native'
2
+ import { AccessibilityInfo, Dimensions } from 'react-native'
3
3
 
4
4
  import { matchQuery } from './matchQuery'
5
5
 
6
6
  type Orientation = 'landscape' | 'portrait'
7
7
 
8
- type Listener = (orientation: Orientation) => void
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
+ }
9
38
 
10
39
  export class NativeMediaQueryList implements MediaQueryList {
11
40
  private listeners: Listener[] = []
41
+ private reducedMotionExpected: 'reduce' | 'no-preference' | null = null
12
42
 
13
43
  private get orientation(): Orientation {
14
44
  const windowDimensions = Dimensions.get('window')
@@ -16,6 +46,13 @@ export class NativeMediaQueryList implements MediaQueryList {
16
46
  }
17
47
 
18
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
+ }
19
56
  this.notify()
20
57
  Dimensions.addEventListener('change', () => {
21
58
  this.notify()
@@ -24,20 +61,33 @@ export class NativeMediaQueryList implements MediaQueryList {
24
61
 
25
62
  private notify() {
26
63
  this.listeners.forEach((listener) => {
27
- listener(this.orientation)
64
+ listener()
28
65
  })
29
66
  }
30
67
 
31
68
  addListener(listener: Listener): void {
69
+ if (this.reducedMotionExpected) {
70
+ reducedMotionListeners.add(listener)
71
+ this.listeners.push(listener)
72
+ return
73
+ }
32
74
  this.listeners.push(listener)
33
75
  }
34
76
 
35
77
  removeListener(listener: Listener): void {
78
+ if (this.reducedMotionExpected) {
79
+ reducedMotionListeners.delete(listener)
80
+ }
36
81
  const index = this.listeners.indexOf(listener)
37
82
  if (index !== -1) this.listeners.splice(index, 1)
38
83
  }
39
84
 
40
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
+ }
41
91
  return matchQuery(query, {
42
92
  type: 'screen',
43
93
  orientation: height > width ? 'portrait' : 'landscape',
@@ -47,6 +97,11 @@ export class NativeMediaQueryList implements MediaQueryList {
47
97
  }
48
98
 
49
99
  get matches(): boolean {
100
+ if (this.reducedMotionExpected) {
101
+ return this.reducedMotionExpected === 'reduce'
102
+ ? reducedMotionEnabled
103
+ : !reducedMotionEnabled
104
+ }
50
105
  const windowDimensions = Dimensions.get('window')
51
106
  const matches = matchQuery(this.query, {
52
107
  type: 'screen',
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
  }
@@ -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;
@@ -1,11 +1,11 @@
1
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",
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
3
  "names": [],
4
4
  "sources": [
5
5
  "src/mediaQueryList.ts"
6
6
  ],
7
7
  "version": 3,
8
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"
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
10
  ]
11
11
  }