@tamagui/use-window-dimensions 1.130.7 → 1.131.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/helpers.cjs +57 -0
- package/dist/cjs/helpers.js +52 -0
- package/dist/cjs/helpers.js.map +6 -0
- package/dist/cjs/helpers.native.js +43 -0
- package/dist/cjs/helpers.native.js.map +6 -0
- package/dist/cjs/index.cjs +6 -11
- package/dist/cjs/index.js +8 -13
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js +7 -18
- package/dist/cjs/index.native.js.map +2 -2
- package/dist/cjs/types.cjs +16 -0
- package/dist/cjs/types.js +14 -0
- package/dist/cjs/types.js.map +6 -0
- package/dist/cjs/types.native.js +15 -0
- package/dist/cjs/types.native.js.map +6 -0
- package/dist/esm/helpers.js +36 -0
- package/dist/esm/helpers.js.map +6 -0
- package/dist/esm/helpers.mjs +33 -0
- package/dist/esm/helpers.mjs.map +1 -0
- package/dist/esm/helpers.native.js +20 -0
- package/dist/esm/helpers.native.js.map +1 -0
- package/dist/esm/index.js +7 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +6 -11
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +7 -18
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +6 -0
- package/dist/esm/types.mjs +2 -0
- package/dist/esm/types.mjs.map +1 -0
- package/dist/esm/types.native.js +2 -0
- package/dist/esm/types.native.js.map +1 -0
- package/package.json +3 -3
- package/src/helpers.native.ts +17 -0
- package/src/helpers.ts +44 -0
- package/src/index.ts +11 -29
- package/src/types.ts +10 -0
- package/types/helpers.d.ts +5 -0
- package/types/helpers.d.ts.map +13 -0
- package/types/helpers.native.d.ts +5 -0
- package/types/helpers.native.d.ts.map +13 -0
- package/types/index.d.ts +4 -11
- package/types/index.d.ts.map +3 -3
- package/types/types.d.ts +9 -0
- package/types/types.d.ts.map +13 -0
|
@@ -0,0 +1,57 @@
|
|
|
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: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var helpers_exports = {};
|
|
22
|
+
__export(helpers_exports, {
|
|
23
|
+
getWindowSize: () => getWindowSize,
|
|
24
|
+
subscribe: () => subscribe
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
27
|
+
var import_constants = require("@tamagui/constants");
|
|
28
|
+
function getWindowSize() {
|
|
29
|
+
if (!import_constants.isClient) return {
|
|
30
|
+
width: 800,
|
|
31
|
+
height: 600,
|
|
32
|
+
scale: 1,
|
|
33
|
+
fontScale: 1
|
|
34
|
+
};
|
|
35
|
+
const win = window,
|
|
36
|
+
docEl = win.document.documentElement;
|
|
37
|
+
return {
|
|
38
|
+
fontScale: 1,
|
|
39
|
+
height: docEl.clientHeight,
|
|
40
|
+
scale: win.devicePixelRatio || 1,
|
|
41
|
+
width: docEl.clientWidth
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const cbs = /* @__PURE__ */new Set();
|
|
45
|
+
let _raf = 0;
|
|
46
|
+
if (import_constants.isClient) {
|
|
47
|
+
let frame = 0;
|
|
48
|
+
const onResize = () => {
|
|
49
|
+
cancelAnimationFrame(_raf), _raf = requestAnimationFrame(() => {
|
|
50
|
+
++frame % 4 === 0 && cbs.forEach(cb => cb(getWindowSize()));
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
window.addEventListener("resize", onResize);
|
|
54
|
+
}
|
|
55
|
+
function subscribe(cb) {
|
|
56
|
+
return cbs.add(cb), () => cbs.delete(cb);
|
|
57
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var helpers_exports = {};
|
|
16
|
+
__export(helpers_exports, {
|
|
17
|
+
getWindowSize: () => getWindowSize,
|
|
18
|
+
subscribe: () => subscribe
|
|
19
|
+
});
|
|
20
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
21
|
+
var import_constants = require("@tamagui/constants");
|
|
22
|
+
function getWindowSize() {
|
|
23
|
+
if (!import_constants.isClient)
|
|
24
|
+
return {
|
|
25
|
+
width: 800,
|
|
26
|
+
height: 600,
|
|
27
|
+
scale: 1,
|
|
28
|
+
fontScale: 1
|
|
29
|
+
};
|
|
30
|
+
const win = window, docEl = win.document.documentElement;
|
|
31
|
+
return {
|
|
32
|
+
fontScale: 1,
|
|
33
|
+
height: docEl.clientHeight,
|
|
34
|
+
scale: win.devicePixelRatio || 1,
|
|
35
|
+
width: docEl.clientWidth
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const cbs = /* @__PURE__ */ new Set();
|
|
39
|
+
let _raf = 0;
|
|
40
|
+
if (import_constants.isClient) {
|
|
41
|
+
let frame = 0;
|
|
42
|
+
const onResize = () => {
|
|
43
|
+
cancelAnimationFrame(_raf), _raf = requestAnimationFrame(() => {
|
|
44
|
+
++frame % 4 === 0 && cbs.forEach((cb) => cb(getWindowSize()));
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
window.addEventListener("resize", onResize);
|
|
48
|
+
}
|
|
49
|
+
function subscribe(cb) {
|
|
50
|
+
return cbs.add(cb), () => cbs.delete(cb);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/helpers.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAyB;AAGlB,SAAS,gBAA4B;AAC1C,MAAI,CAAC;AACH,WAAO;AAAA,MACL,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,WAAW;AAAA,IACb;AAEF,QAAM,MAAM,QACN,QAAQ,IAAI,SAAS;AAC3B,SAAO;AAAA,IACL,WAAW;AAAA,IACX,QAAQ,MAAM;AAAA,IACd,OAAO,IAAI,oBAAoB;AAAA,IAC/B,OAAO,MAAM;AAAA,EACf;AACF;AAEA,MAAM,MAAM,oBAAI,IAAwB;AACxC,IAAI,OAAO;AAEX,IAAI,2BAAU;AACZ,MAAI,QAAQ;AACZ,QAAM,WAAW,MAAM;AACrB,yBAAqB,IAAI,GACzB,OAAO,sBAAsB,MAAM;AAEjC,MAAI,EAAE,QAAQ,MAAM,KAClB,IAAI,QAAQ,CAAC,OAAO,GAAG,cAAc,CAAC,CAAC;AAAA,IAE3C,CAAC;AAAA,EACH;AAEA,SAAO,iBAAiB,UAAU,QAAQ;AAC5C;AAEO,SAAS,UAAU,IAAoC;AAC5D,aAAI,IAAI,EAAE,GACH,MAAM,IAAI,OAAO,EAAE;AAC5B;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
16
|
+
var helpers_native_exports = {};
|
|
17
|
+
__export(helpers_native_exports, {
|
|
18
|
+
getWindowSize: () => getWindowSize,
|
|
19
|
+
subscribe: () => subscribe
|
|
20
|
+
});
|
|
21
|
+
module.exports = __toCommonJS(helpers_native_exports);
|
|
22
|
+
var import_react_native = require("react-native");
|
|
23
|
+
function getWindowSize() {
|
|
24
|
+
return import_react_native.Dimensions.get("window");
|
|
25
|
+
}
|
|
26
|
+
var cbs = /* @__PURE__ */ new Set();
|
|
27
|
+
import_react_native.Dimensions.addEventListener("change", function(param) {
|
|
28
|
+
var { window } = param;
|
|
29
|
+
cbs.forEach(function(cb) {
|
|
30
|
+
return cb(window);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
function subscribe(cb) {
|
|
34
|
+
return cbs.add(cb), function() {
|
|
35
|
+
return cbs.delete(cb);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
getWindowSize,
|
|
41
|
+
subscribe
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=helpers.native.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/helpers.native.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;;;;;;0BAA2B;AAGpB,SAASA,gBAAAA;AACd,SAAOC,+BAAWC,IAAI,QAAA;AACxB;AAEA,IAAMC,MAAM,oBAAIC,IAAAA;AAEhBH,+BAAWI,iBAAiB,UAAU,SAAA,OAAA;MAAC,EAAEC,OAAM,IAAE;AAC/CH,MAAII,QAAQ,SAACC,IAAAA;WAAOA,GAAGF,MAAAA;;AACzB,CAAA;AAEO,SAASG,UAAUD,IAAsB;AAC9CL,aAAIO,IAAIF,EAAAA,GACD,WAAA;WAAML,IAAIQ,OAAOH,EAAAA;;AAC1B;",
|
|
5
|
+
"names": ["getWindowSize", "Dimensions", "get", "cbs", "Set", "addEventListener", "window", "forEach", "cb", "subscribe", "add", "delete"]
|
|
6
|
+
}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -37,23 +37,18 @@ __export(index_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(index_exports);
|
|
38
38
|
var import_react = __toESM(require("react")),
|
|
39
39
|
import_constants = require("@tamagui/constants"),
|
|
40
|
-
|
|
40
|
+
import_helpers = require("./helpers.cjs");
|
|
41
41
|
const initialValue = {
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
width: 800,
|
|
43
|
+
height: 600,
|
|
44
|
+
scale: 1,
|
|
45
|
+
fontScale: 1
|
|
44
46
|
};
|
|
45
47
|
function configureInitialWindowDimensions(next) {
|
|
46
48
|
Object.assign(initialValue, next);
|
|
47
49
|
}
|
|
48
|
-
import_react_native.Dimensions.addEventListener("change", () => {
|
|
49
|
-
cbs.forEach(cb => cb(window));
|
|
50
|
-
});
|
|
51
|
-
const cbs = /* @__PURE__ */new Set();
|
|
52
|
-
function subscribe(cb) {
|
|
53
|
-
return cbs.add(cb), () => cbs.delete(cb);
|
|
54
|
-
}
|
|
55
50
|
function useWindowDimensions({
|
|
56
51
|
serverValue = initialValue
|
|
57
52
|
} = {}) {
|
|
58
|
-
return import_react.default.useSyncExternalStore(subscribe,
|
|
53
|
+
return import_react.default.useSyncExternalStore(import_helpers.subscribe, import_helpers.getWindowSize, () => import_constants.isWeb ? serverValue : (0, import_helpers.getWindowSize)());
|
|
59
54
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -26,28 +26,23 @@ __export(index_exports, {
|
|
|
26
26
|
useWindowDimensions: () => useWindowDimensions
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(index_exports);
|
|
29
|
-
var import_react = __toESM(require("react")), import_constants = require("@tamagui/constants"),
|
|
29
|
+
var import_react = __toESM(require("react")), import_constants = require("@tamagui/constants"), import_helpers = require("./helpers");
|
|
30
30
|
const initialValue = {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
width: 800,
|
|
32
|
+
height: 600,
|
|
33
|
+
scale: 1,
|
|
34
|
+
fontScale: 1
|
|
33
35
|
};
|
|
34
36
|
function configureInitialWindowDimensions(next) {
|
|
35
37
|
Object.assign(initialValue, next);
|
|
36
38
|
}
|
|
37
|
-
import_react_native.Dimensions.addEventListener("change", () => {
|
|
38
|
-
cbs.forEach((cb) => cb(window));
|
|
39
|
-
});
|
|
40
|
-
const cbs = /* @__PURE__ */ new Set();
|
|
41
|
-
function subscribe(cb) {
|
|
42
|
-
return cbs.add(cb), () => cbs.delete(cb);
|
|
43
|
-
}
|
|
44
39
|
function useWindowDimensions({
|
|
45
40
|
serverValue = initialValue
|
|
46
41
|
} = {}) {
|
|
47
42
|
return import_react.default.useSyncExternalStore(
|
|
48
|
-
subscribe,
|
|
49
|
-
|
|
50
|
-
() => import_constants.isWeb ? serverValue :
|
|
43
|
+
import_helpers.subscribe,
|
|
44
|
+
import_helpers.getWindowSize,
|
|
45
|
+
() => import_constants.isWeb ? serverValue : (0, import_helpers.getWindowSize)()
|
|
51
46
|
);
|
|
52
47
|
}
|
|
53
48
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB,2BAClB,mBAAsB,+
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB,2BAClB,mBAAsB,+BAEtB,iBAAyC;AAOzC,MAAM,eAA2B;AAAA,EAC/B,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,WAAW;AACb;AAEO,SAAS,iCAAiC,MAAwB;AACvE,SAAO,OAAO,cAAc,IAAI;AAClC;AAEO,SAAS,oBAAoB;AAAA,EAClC,cAAc;AAChB,IAAkC,CAAC,GAAe;AAChD,SAAO,aAAAA,QAAM;AAAA,IAAqB;AAAA,IAAW;AAAA,IAAe,MAC1D,yBAAQ,kBAAc,8BAAc;AAAA,EACtC;AACF;",
|
|
5
5
|
"names": ["React"]
|
|
6
6
|
}
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -27,30 +27,19 @@ __export(index_exports, {
|
|
|
27
27
|
useWindowDimensions: () => useWindowDimensions
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(index_exports);
|
|
30
|
-
var import_react = __toESM(require("react")), import_constants = require("@tamagui/constants"),
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
var import_react = __toESM(require("react")), import_constants = require("@tamagui/constants"), import_helpers = require("./helpers"), initialValue = {
|
|
31
|
+
width: 800,
|
|
32
|
+
height: 600,
|
|
33
|
+
scale: 1,
|
|
34
|
+
fontScale: 1
|
|
33
35
|
};
|
|
34
36
|
function configureInitialWindowDimensions(next) {
|
|
35
37
|
Object.assign(initialValue, next);
|
|
36
38
|
}
|
|
37
|
-
import_react_native.Dimensions.addEventListener("change", function() {
|
|
38
|
-
cbs.forEach(function(cb) {
|
|
39
|
-
return cb(window);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
var cbs = /* @__PURE__ */ new Set();
|
|
43
|
-
function subscribe(cb) {
|
|
44
|
-
return cbs.add(cb), function() {
|
|
45
|
-
return cbs.delete(cb);
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
39
|
function useWindowDimensions() {
|
|
49
40
|
var { serverValue = initialValue } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
50
|
-
return import_react.default.useSyncExternalStore(subscribe, function() {
|
|
51
|
-
return
|
|
52
|
-
}, function() {
|
|
53
|
-
return import_constants.isWeb ? serverValue : import_react_native.Dimensions.get("window");
|
|
41
|
+
return import_react.default.useSyncExternalStore(import_helpers.subscribe, import_helpers.getWindowSize, function() {
|
|
42
|
+
return import_constants.isWeb ? serverValue : (0, import_helpers.getWindowSize)();
|
|
54
43
|
});
|
|
55
44
|
}
|
|
56
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;mBAAkB,2BAClB,mBAAsB,+
|
|
5
|
-
"names": ["initialValue", "
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;mBAAkB,2BAClB,mBAAsB,+BAEtB,iBAAyC,sBAOnCA,eAA2B;EAC/BC,OAAO;EACPC,QAAQ;EACRC,OAAO;EACPC,WAAW;AACb;AAEO,SAASC,iCAAiCC,MAAgB;AAC/DC,SAAOC,OAAOR,cAAcM,IAAAA;AAC9B;AAEO,SAASG,sBAAAA;MAAoB,EAClCC,cAAcV,aAAY,IADQ,UAAA,SAAA,KAAA,UAAA,CAAA,MAAA,SAAA,UAAA,CAAA,IAEF,CAAC;AACjC,SAAOW,aAAAA,QAAMC,qBAAqBC,0BAAWC,8BAAe,WAAA;WAC1DC,yBAAQL,kBAAcI,8BAAAA;;AAE1B;",
|
|
5
|
+
"names": ["initialValue", "width", "height", "scale", "fontScale", "configureInitialWindowDimensions", "next", "Object", "assign", "useWindowDimensions", "serverValue", "React", "useSyncExternalStore", "subscribe", "getWindowSize", "isWeb"]
|
|
6
6
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
};
|
|
12
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
13
|
+
value: !0
|
|
14
|
+
}), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
|
+
return to;
|
|
10
|
+
};
|
|
11
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
12
|
+
var types_exports = {};
|
|
13
|
+
module.exports = __toCommonJS(types_exports);
|
|
14
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
return to;
|
|
11
|
+
};
|
|
12
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
13
|
+
var types_exports = {};
|
|
14
|
+
module.exports = __toCommonJS(types_exports);
|
|
15
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { isClient } from "@tamagui/constants";
|
|
2
|
+
function getWindowSize() {
|
|
3
|
+
if (!isClient)
|
|
4
|
+
return {
|
|
5
|
+
width: 800,
|
|
6
|
+
height: 600,
|
|
7
|
+
scale: 1,
|
|
8
|
+
fontScale: 1
|
|
9
|
+
};
|
|
10
|
+
const win = window, docEl = win.document.documentElement;
|
|
11
|
+
return {
|
|
12
|
+
fontScale: 1,
|
|
13
|
+
height: docEl.clientHeight,
|
|
14
|
+
scale: win.devicePixelRatio || 1,
|
|
15
|
+
width: docEl.clientWidth
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const cbs = /* @__PURE__ */ new Set();
|
|
19
|
+
let _raf = 0;
|
|
20
|
+
if (isClient) {
|
|
21
|
+
let frame = 0;
|
|
22
|
+
const onResize = () => {
|
|
23
|
+
cancelAnimationFrame(_raf), _raf = requestAnimationFrame(() => {
|
|
24
|
+
++frame % 4 === 0 && cbs.forEach((cb) => cb(getWindowSize()));
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
window.addEventListener("resize", onResize);
|
|
28
|
+
}
|
|
29
|
+
function subscribe(cb) {
|
|
30
|
+
return cbs.add(cb), () => cbs.delete(cb);
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
getWindowSize,
|
|
34
|
+
subscribe
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/helpers.ts"],
|
|
4
|
+
"mappings": "AAAA,SAAS,gBAAgB;AAGlB,SAAS,gBAA4B;AAC1C,MAAI,CAAC;AACH,WAAO;AAAA,MACL,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,WAAW;AAAA,IACb;AAEF,QAAM,MAAM,QACN,QAAQ,IAAI,SAAS;AAC3B,SAAO;AAAA,IACL,WAAW;AAAA,IACX,QAAQ,MAAM;AAAA,IACd,OAAO,IAAI,oBAAoB;AAAA,IAC/B,OAAO,MAAM;AAAA,EACf;AACF;AAEA,MAAM,MAAM,oBAAI,IAAwB;AACxC,IAAI,OAAO;AAEX,IAAI,UAAU;AACZ,MAAI,QAAQ;AACZ,QAAM,WAAW,MAAM;AACrB,yBAAqB,IAAI,GACzB,OAAO,sBAAsB,MAAM;AAEjC,MAAI,EAAE,QAAQ,MAAM,KAClB,IAAI,QAAQ,CAAC,OAAO,GAAG,cAAc,CAAC,CAAC;AAAA,IAE3C,CAAC;AAAA,EACH;AAEA,SAAO,iBAAiB,UAAU,QAAQ;AAC5C;AAEO,SAAS,UAAU,IAAoC;AAC5D,aAAI,IAAI,EAAE,GACH,MAAM,IAAI,OAAO,EAAE;AAC5B;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isClient } from "@tamagui/constants";
|
|
2
|
+
function getWindowSize() {
|
|
3
|
+
if (!isClient) return {
|
|
4
|
+
width: 800,
|
|
5
|
+
height: 600,
|
|
6
|
+
scale: 1,
|
|
7
|
+
fontScale: 1
|
|
8
|
+
};
|
|
9
|
+
const win = window,
|
|
10
|
+
docEl = win.document.documentElement;
|
|
11
|
+
return {
|
|
12
|
+
fontScale: 1,
|
|
13
|
+
height: docEl.clientHeight,
|
|
14
|
+
scale: win.devicePixelRatio || 1,
|
|
15
|
+
width: docEl.clientWidth
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const cbs = /* @__PURE__ */new Set();
|
|
19
|
+
let _raf = 0;
|
|
20
|
+
if (isClient) {
|
|
21
|
+
let frame = 0;
|
|
22
|
+
const onResize = () => {
|
|
23
|
+
cancelAnimationFrame(_raf), _raf = requestAnimationFrame(() => {
|
|
24
|
+
++frame % 4 === 0 && cbs.forEach(cb => cb(getWindowSize()));
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
window.addEventListener("resize", onResize);
|
|
28
|
+
}
|
|
29
|
+
function subscribe(cb) {
|
|
30
|
+
return cbs.add(cb), () => cbs.delete(cb);
|
|
31
|
+
}
|
|
32
|
+
export { getWindowSize, subscribe };
|
|
33
|
+
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isClient","getWindowSize","width","height","scale","fontScale","win","window","docEl","document","documentElement","clientHeight","devicePixelRatio","clientWidth","cbs","Set","_raf","frame","onResize","cancelAnimationFrame","requestAnimationFrame","forEach","cb","addEventListener","subscribe","add","delete"],"sources":["../../src/helpers.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,QAAA,QAAgB;AAGlB,SAASC,cAAA,EAA4B;EAC1C,IAAI,CAACD,QAAA,EACH,OAAO;IACLE,KAAA,EAAO;IACPC,MAAA,EAAQ;IACRC,KAAA,EAAO;IACPC,SAAA,EAAW;EACb;EAEF,MAAMC,GAAA,GAAMC,MAAA;IACNC,KAAA,GAAQF,GAAA,CAAIG,QAAA,CAASC,eAAA;EAC3B,OAAO;IACLL,SAAA,EAAW;IACXF,MAAA,EAAQK,KAAA,CAAMG,YAAA;IACdP,KAAA,EAAOE,GAAA,CAAIM,gBAAA,IAAoB;IAC/BV,KAAA,EAAOM,KAAA,CAAMK;EACf;AACF;AAEA,MAAMC,GAAA,GAAM,mBAAIC,GAAA,CAAwB;AACxC,IAAIC,IAAA,GAAO;AAEX,IAAIhB,QAAA,EAAU;EACZ,IAAIiB,KAAA,GAAQ;EACZ,MAAMC,QAAA,GAAWA,CAAA,KAAM;IACrBC,oBAAA,CAAqBH,IAAI,GACzBA,IAAA,GAAOI,qBAAA,CAAsB,MAAM;MAE7B,EAAEH,KAAA,GAAQ,MAAM,KAClBH,GAAA,CAAIO,OAAA,CAASC,EAAA,IAAOA,EAAA,CAAGrB,aAAA,CAAc,CAAC,CAAC;IAE3C,CAAC;EACH;EAEAM,MAAA,CAAOgB,gBAAA,CAAiB,UAAUL,QAAQ;AAC5C;AAEO,SAASM,UAAUF,EAAA,EAAoC;EAC5D,OAAAR,GAAA,CAAIW,GAAA,CAAIH,EAAE,GACH,MAAMR,GAAA,CAAIY,MAAA,CAAOJ,EAAE;AAC5B","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Dimensions } from "react-native";
|
|
2
|
+
function getWindowSize() {
|
|
3
|
+
return Dimensions.get("window");
|
|
4
|
+
}
|
|
5
|
+
var cbs = /* @__PURE__ */new Set();
|
|
6
|
+
Dimensions.addEventListener("change", function (param) {
|
|
7
|
+
var {
|
|
8
|
+
window
|
|
9
|
+
} = param;
|
|
10
|
+
cbs.forEach(function (cb) {
|
|
11
|
+
return cb(window);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
function subscribe(cb) {
|
|
15
|
+
return cbs.add(cb), function () {
|
|
16
|
+
return cbs.delete(cb);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export { getWindowSize, subscribe };
|
|
20
|
+
//# sourceMappingURL=helpers.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Dimensions","getWindowSize","get","cbs","Set","addEventListener","param","window","forEach","cb","subscribe","add","delete"],"sources":["../../src/helpers.native.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AAGpB,SAASC,cAAA;EACd,OAAOD,UAAA,CAAWE,GAAA,CAAI;AACxB;AAEA,IAAMC,GAAA,GAAM,mBAAIC,GAAA;AAEhBJ,UAAA,CAAWK,gBAAA,CAAiB,UAAU,UAAAC,KAAA;MAAC;IAAEC;EAAM,IAAED,KAAA;EAC/CH,GAAA,CAAIK,OAAA,CAAQ,UAACC,EAAA;WAAOA,EAAA,CAAGF,MAAA;;AACzB;AAEO,SAASG,UAAUD,EAAA,EAAsB;EAC9C,OAAAN,GAAA,CAAIQ,GAAA,CAAIF,EAAA,GACD;WAAMN,GAAA,CAAIS,MAAA,CAAOH,EAAA;;AAC1B","ignoreList":[]}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { isWeb } from "@tamagui/constants";
|
|
3
|
-
import {
|
|
3
|
+
import { getWindowSize, subscribe } from "./helpers";
|
|
4
4
|
const initialValue = {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
width: 800,
|
|
6
|
+
height: 600,
|
|
7
|
+
scale: 1,
|
|
8
|
+
fontScale: 1
|
|
7
9
|
};
|
|
8
10
|
function configureInitialWindowDimensions(next) {
|
|
9
11
|
Object.assign(initialValue, next);
|
|
10
12
|
}
|
|
11
|
-
Dimensions.addEventListener("change", () => {
|
|
12
|
-
cbs.forEach((cb) => cb(window));
|
|
13
|
-
});
|
|
14
|
-
const cbs = /* @__PURE__ */ new Set();
|
|
15
|
-
function subscribe(cb) {
|
|
16
|
-
return cbs.add(cb), () => cbs.delete(cb);
|
|
17
|
-
}
|
|
18
13
|
function useWindowDimensions({
|
|
19
14
|
serverValue = initialValue
|
|
20
15
|
} = {}) {
|
|
21
16
|
return React.useSyncExternalStore(
|
|
22
17
|
subscribe,
|
|
23
|
-
|
|
24
|
-
() => isWeb ? serverValue :
|
|
18
|
+
getWindowSize,
|
|
19
|
+
() => isWeb ? serverValue : getWindowSize()
|
|
25
20
|
);
|
|
26
21
|
}
|
|
27
22
|
export {
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,aAAa;
|
|
4
|
+
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,aAAa;AAEtB,SAAS,eAAe,iBAAiB;AAOzC,MAAM,eAA2B;AAAA,EAC/B,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,WAAW;AACb;AAEO,SAAS,iCAAiC,MAAwB;AACvE,SAAO,OAAO,cAAc,IAAI;AAClC;AAEO,SAAS,oBAAoB;AAAA,EAClC,cAAc;AAChB,IAAkC,CAAC,GAAe;AAChD,SAAO,MAAM;AAAA,IAAqB;AAAA,IAAW;AAAA,IAAe,MAC1D,QAAQ,cAAc,cAAc;AAAA,EACtC;AACF;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { isWeb } from "@tamagui/constants";
|
|
3
|
-
import {
|
|
3
|
+
import { getWindowSize, subscribe } from "./helpers.mjs";
|
|
4
4
|
const initialValue = {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
width: 800,
|
|
6
|
+
height: 600,
|
|
7
|
+
scale: 1,
|
|
8
|
+
fontScale: 1
|
|
7
9
|
};
|
|
8
10
|
function configureInitialWindowDimensions(next) {
|
|
9
11
|
Object.assign(initialValue, next);
|
|
10
12
|
}
|
|
11
|
-
Dimensions.addEventListener("change", () => {
|
|
12
|
-
cbs.forEach(cb => cb(window));
|
|
13
|
-
});
|
|
14
|
-
const cbs = /* @__PURE__ */new Set();
|
|
15
|
-
function subscribe(cb) {
|
|
16
|
-
return cbs.add(cb), () => cbs.delete(cb);
|
|
17
|
-
}
|
|
18
13
|
function useWindowDimensions({
|
|
19
14
|
serverValue = initialValue
|
|
20
15
|
} = {}) {
|
|
21
|
-
return React.useSyncExternalStore(subscribe,
|
|
16
|
+
return React.useSyncExternalStore(subscribe, getWindowSize, () => isWeb ? serverValue : getWindowSize());
|
|
22
17
|
}
|
|
23
18
|
export { configureInitialWindowDimensions, useWindowDimensions };
|
|
24
19
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","isWeb","
|
|
1
|
+
{"version":3,"names":["React","isWeb","getWindowSize","subscribe","initialValue","width","height","scale","fontScale","configureInitialWindowDimensions","next","Object","assign","useWindowDimensions","serverValue","useSyncExternalStore"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAOA,KAAA,MAAW;AAClB,SAASC,KAAA,QAAa;AAEtB,SAASC,aAAA,EAAeC,SAAA,QAAiB;AAOzC,MAAMC,YAAA,GAA2B;EAC/BC,KAAA,EAAO;EACPC,MAAA,EAAQ;EACRC,KAAA,EAAO;EACPC,SAAA,EAAW;AACb;AAEO,SAASC,iCAAiCC,IAAA,EAAwB;EACvEC,MAAA,CAAOC,MAAA,CAAOR,YAAA,EAAcM,IAAI;AAClC;AAEO,SAASG,oBAAoB;EAClCC,WAAA,GAAcV;AAChB,IAAkC,CAAC,GAAe;EAChD,OAAOJ,KAAA,CAAMe,oBAAA,CAAqBZ,SAAA,EAAWD,aAAA,EAAe,MAC1DD,KAAA,GAAQa,WAAA,GAAcZ,aAAA,CAAc,CACtC;AACF","ignoreList":[]}
|
package/dist/esm/index.native.js
CHANGED
|
@@ -1,32 +1,21 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { isWeb } from "@tamagui/constants";
|
|
3
|
-
import {
|
|
3
|
+
import { getWindowSize, subscribe } from "./helpers.native.js";
|
|
4
4
|
var initialValue = {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
width: 800,
|
|
6
|
+
height: 600,
|
|
7
|
+
scale: 1,
|
|
8
|
+
fontScale: 1
|
|
7
9
|
};
|
|
8
10
|
function configureInitialWindowDimensions(next) {
|
|
9
11
|
Object.assign(initialValue, next);
|
|
10
12
|
}
|
|
11
|
-
Dimensions.addEventListener("change", function () {
|
|
12
|
-
cbs.forEach(function (cb) {
|
|
13
|
-
return cb(window);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
var cbs = /* @__PURE__ */new Set();
|
|
17
|
-
function subscribe(cb) {
|
|
18
|
-
return cbs.add(cb), function () {
|
|
19
|
-
return cbs.delete(cb);
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
13
|
function useWindowDimensions() {
|
|
23
14
|
var {
|
|
24
15
|
serverValue = initialValue
|
|
25
16
|
} = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
26
|
-
return React.useSyncExternalStore(subscribe, function () {
|
|
27
|
-
return
|
|
28
|
-
}, function () {
|
|
29
|
-
return isWeb ? serverValue : Dimensions.get("window");
|
|
17
|
+
return React.useSyncExternalStore(subscribe, getWindowSize, function () {
|
|
18
|
+
return isWeb ? serverValue : getWindowSize();
|
|
30
19
|
});
|
|
31
20
|
}
|
|
32
21
|
export { configureInitialWindowDimensions, useWindowDimensions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","isWeb","
|
|
1
|
+
{"version":3,"names":["React","isWeb","getWindowSize","subscribe","initialValue","width","height","scale","fontScale","configureInitialWindowDimensions","next","Object","assign","useWindowDimensions","serverValue","arguments","length","useSyncExternalStore"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAOA,KAAA,MAAW;AAClB,SAASC,KAAA,QAAa;AAEtB,SAASC,aAAA,EAAeC,SAAA,QAAiB;AAOzC,IAAAC,YAAM;EACJC,KAAA,EAAO;EACPC,MAAA,EAAQ;EACRC,KAAA,EAAO;EACPC,SAAA,EAAW;AACb;AAEO,SAASC,iCAAiCC,IAAA,EAAwB;EACvEC,MAAA,CAAOC,MAAA,CAAOR,YAAA,EAAcM,IAAI;AAClC;AAEO,SAASG,oBAAA,EAAoB;EAClC;IAAAC,WAAc,GAAAV;EAAA,IAAAW,SAAA,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA;EAChB,OAAkDf,KAAA,CAAAiB,oBAAA,CAAAd,SAAA,EAAAD,aAAA;IAChD,OAAOD,KAAM,GAAAa,WAAA,GAAAZ,aAAA;EAAA,EAAqB;AAAA;AAAW,SAE7CO,gCAAA,EACFI,mBAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/use-window-dimensions",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.131.0",
|
|
4
4
|
"types": "./types/index.d.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@tamagui/constants": "1.
|
|
34
|
+
"@tamagui/constants": "1.131.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@tamagui/build": "1.
|
|
37
|
+
"@tamagui/build": "1.131.0",
|
|
38
38
|
"react": "*",
|
|
39
39
|
"react-native": "^0.79.2"
|
|
40
40
|
},
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Dimensions } from 'react-native'
|
|
2
|
+
import type { WindowSize, WindowSizeListener } from './types'
|
|
3
|
+
|
|
4
|
+
export function getWindowSize(): WindowSize {
|
|
5
|
+
return Dimensions.get('window')
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const cbs = new Set<WindowSizeListener>()
|
|
9
|
+
|
|
10
|
+
Dimensions.addEventListener('change', ({ window }) => {
|
|
11
|
+
cbs.forEach((cb) => cb(window))
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export function subscribe(cb: WindowSizeListener): () => void {
|
|
15
|
+
cbs.add(cb)
|
|
16
|
+
return () => cbs.delete(cb)
|
|
17
|
+
}
|
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { isClient } from '@tamagui/constants'
|
|
2
|
+
import type { WindowSize, WindowSizeListener } from './types'
|
|
3
|
+
|
|
4
|
+
export function getWindowSize(): WindowSize {
|
|
5
|
+
if (!isClient) {
|
|
6
|
+
return {
|
|
7
|
+
width: 800,
|
|
8
|
+
height: 600,
|
|
9
|
+
scale: 1,
|
|
10
|
+
fontScale: 1,
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const win = window
|
|
14
|
+
const docEl = win.document.documentElement
|
|
15
|
+
return {
|
|
16
|
+
fontScale: 1,
|
|
17
|
+
height: docEl.clientHeight,
|
|
18
|
+
scale: win.devicePixelRatio || 1,
|
|
19
|
+
width: docEl.clientWidth,
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const cbs = new Set<WindowSizeListener>()
|
|
24
|
+
let _raf = 0
|
|
25
|
+
|
|
26
|
+
if (isClient) {
|
|
27
|
+
let frame = 0
|
|
28
|
+
const onResize = () => {
|
|
29
|
+
cancelAnimationFrame(_raf)
|
|
30
|
+
_raf = requestAnimationFrame(() => {
|
|
31
|
+
// throttle to every 4 frames
|
|
32
|
+
if (++frame % 4 === 0) {
|
|
33
|
+
cbs.forEach((cb) => cb(getWindowSize()))
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
window.addEventListener('resize', onResize)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function subscribe(cb: WindowSizeListener): () => void {
|
|
42
|
+
cbs.add(cb)
|
|
43
|
+
return () => cbs.delete(cb)
|
|
44
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,46 +1,28 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { isWeb } from '@tamagui/constants'
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
4
|
+
import { getWindowSize, subscribe } from './helpers'
|
|
5
|
+
import type { WindowSize } from './types'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* SSR safe useWindowDimensions
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
width:
|
|
13
|
-
height:
|
|
11
|
+
const initialValue: WindowSize = {
|
|
12
|
+
width: 800,
|
|
13
|
+
height: 600,
|
|
14
|
+
scale: 1,
|
|
15
|
+
fontScale: 1,
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
height: 800,
|
|
18
|
-
width: 600,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function configureInitialWindowDimensions(next: Size): void {
|
|
18
|
+
export function configureInitialWindowDimensions(next: WindowSize): void {
|
|
22
19
|
Object.assign(initialValue, next)
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
Dimensions.addEventListener('change', () => {
|
|
26
|
-
cbs.forEach((cb) => cb(window))
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
const cbs = new Set<Function>()
|
|
30
|
-
|
|
31
|
-
type WindowSizeListener = ({ window }: { window: ScaledSize }) => void
|
|
32
|
-
|
|
33
|
-
function subscribe(cb: WindowSizeListener) {
|
|
34
|
-
cbs.add(cb)
|
|
35
|
-
return () => cbs.delete(cb)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
22
|
export function useWindowDimensions({
|
|
39
23
|
serverValue = initialValue,
|
|
40
|
-
}: { serverValue?:
|
|
41
|
-
return React.useSyncExternalStore(
|
|
42
|
-
|
|
43
|
-
() => Dimensions.get('window'),
|
|
44
|
-
() => (isWeb ? serverValue : Dimensions.get('window'))
|
|
24
|
+
}: { serverValue?: WindowSize } = {}): WindowSize {
|
|
25
|
+
return React.useSyncExternalStore(subscribe, getWindowSize, () =>
|
|
26
|
+
isWeb ? serverValue : getWindowSize()
|
|
45
27
|
)
|
|
46
28
|
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AACA,cAAc,YAAY,0BAA0B,SAAS;AAE7D,OAAO,iBAAS,iBAAiB;AAqCjC,OAAO,iBAAS,UAAUA,IAAI",
|
|
3
|
+
"names": [
|
|
4
|
+
"cb: WindowSizeListener"
|
|
5
|
+
],
|
|
6
|
+
"sources": [
|
|
7
|
+
"src/helpers.ts"
|
|
8
|
+
],
|
|
9
|
+
"sourcesContent": [
|
|
10
|
+
"import { isClient } from '@tamagui/constants'\nimport type { WindowSize, WindowSizeListener } from './types'\n\nexport function getWindowSize(): WindowSize {\n if (!isClient) {\n return {\n width: 800,\n height: 600,\n scale: 1,\n fontScale: 1,\n }\n }\n const win = window\n const docEl = win.document.documentElement\n return {\n fontScale: 1,\n height: docEl.clientHeight,\n scale: win.devicePixelRatio || 1,\n width: docEl.clientWidth,\n }\n}\n\nconst cbs = new Set<WindowSizeListener>()\nlet _raf = 0\n\nif (isClient) {\n let frame = 0\n const onResize = () => {\n cancelAnimationFrame(_raf)\n _raf = requestAnimationFrame(() => {\n // throttle to every 4 frames\n if (++frame % 4 === 0) {\n cbs.forEach((cb) => cb(getWindowSize()))\n }\n })\n }\n\n window.addEventListener('resize', onResize)\n}\n\nexport function subscribe(cb: WindowSizeListener): () => void {\n cbs.add(cb)\n return () => cbs.delete(cb)\n}\n"
|
|
11
|
+
],
|
|
12
|
+
"version": 3
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AACA,cAAc,YAAY,0BAA0B,SAAS;AAE7D,OAAO,iBAAS,iBAAiB;AAUjC,OAAO,iBAAS,UAAUA,IAAI",
|
|
3
|
+
"names": [
|
|
4
|
+
"cb: WindowSizeListener"
|
|
5
|
+
],
|
|
6
|
+
"sources": [
|
|
7
|
+
"src/helpers.native.ts"
|
|
8
|
+
],
|
|
9
|
+
"sourcesContent": [
|
|
10
|
+
"import { Dimensions } from 'react-native'\nimport type { WindowSize, WindowSizeListener } from './types'\n\nexport function getWindowSize(): WindowSize {\n return Dimensions.get('window')\n}\n\nconst cbs = new Set<WindowSizeListener>()\n\nDimensions.addEventListener('change', ({ window }) => {\n cbs.forEach((cb) => cb(window))\n})\n\nexport function subscribe(cb: WindowSizeListener): () => void {\n cbs.add(cb)\n return () => cbs.delete(cb)\n}\n"
|
|
11
|
+
],
|
|
12
|
+
"version": 3
|
|
13
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
type Size = {
|
|
5
|
-
width: number;
|
|
6
|
-
height: number;
|
|
7
|
-
};
|
|
8
|
-
export declare function configureInitialWindowDimensions(next: Size): void;
|
|
1
|
+
import type { WindowSize } from "./types";
|
|
2
|
+
export declare function configureInitialWindowDimensions(next: WindowSize): void;
|
|
9
3
|
export declare function useWindowDimensions({ serverValue }?: {
|
|
10
|
-
serverValue?:
|
|
11
|
-
}):
|
|
12
|
-
export {};
|
|
4
|
+
serverValue?: WindowSize;
|
|
5
|
+
}): WindowSize;
|
|
13
6
|
|
|
14
7
|
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts.map
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"mappings": "
|
|
2
|
+
"mappings": "AAIA,cAAc,kBAAkB,SAAS;AAazC,OAAO,iBAAS,iCAAiCA,MAAM;AAIvD,OAAO,iBAAS,oBAAoB,EAClC,aAC6B,GAA5B;CAAE,cAAc;AAAY,IAAQ",
|
|
3
3
|
"names": [
|
|
4
|
-
"next:
|
|
4
|
+
"next: WindowSize"
|
|
5
5
|
],
|
|
6
6
|
"sources": [
|
|
7
7
|
"src/index.ts"
|
|
8
8
|
],
|
|
9
9
|
"sourcesContent": [
|
|
10
|
-
"import React from 'react'\nimport { isWeb } from '@tamagui/constants'\n\nimport
|
|
10
|
+
"import React from 'react'\nimport { isWeb } from '@tamagui/constants'\n\nimport { getWindowSize, subscribe } from './helpers'\nimport type { WindowSize } from './types'\n\n/**\n * SSR safe useWindowDimensions\n */\n\nconst initialValue: WindowSize = {\n width: 800,\n height: 600,\n scale: 1,\n fontScale: 1,\n}\n\nexport function configureInitialWindowDimensions(next: WindowSize): void {\n Object.assign(initialValue, next)\n}\n\nexport function useWindowDimensions({\n serverValue = initialValue,\n}: { serverValue?: WindowSize } = {}): WindowSize {\n return React.useSyncExternalStore(subscribe, getWindowSize, () =>\n isWeb ? serverValue : getWindowSize()\n )\n}\n"
|
|
11
11
|
],
|
|
12
12
|
"version": 3
|
|
13
13
|
}
|
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAAA,cAAc,kBAAkB,cAAc;AAE9C,YAAY,OAAO;CACjB;CACA;AACD;AAED,YAAY,aAAa;AAEzB,YAAY,sBAAsBA,MAAM",
|
|
3
|
+
"names": [
|
|
4
|
+
"size: WindowSize"
|
|
5
|
+
],
|
|
6
|
+
"sources": [
|
|
7
|
+
"src/types.ts"
|
|
8
|
+
],
|
|
9
|
+
"sourcesContent": [
|
|
10
|
+
"import type { ScaledSize } from 'react-native'\n\nexport type Size = {\n width: number\n height: number\n}\n\nexport type WindowSize = ScaledSize\n\nexport type WindowSizeListener = (size: WindowSize) => void\n"
|
|
11
|
+
],
|
|
12
|
+
"version": 3
|
|
13
|
+
}
|