@tamagui/use-window-dimensions 1.52.4 → 1.52.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +16 -14
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/index.js +19 -17
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +27 -19
- package/types/index.d.ts +12 -5
- package/types/index.d.ts.map +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -26,26 +26,28 @@ var import_constants = require("@tamagui/constants");
|
|
|
26
26
|
var import_react = require("react");
|
|
27
27
|
var import_react_native = require("react-native");
|
|
28
28
|
const initialValue = {
|
|
29
|
-
fontScale: 1,
|
|
30
29
|
height: 800,
|
|
31
|
-
width: 600
|
|
32
|
-
scale: 1
|
|
30
|
+
width: 600
|
|
33
31
|
};
|
|
34
32
|
function configureInitialWindowDimensions(next) {
|
|
35
33
|
Object.assign(initialValue, next);
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
import_react_native.Dimensions.addEventListener("change", () => {
|
|
36
|
+
cbs.forEach((cb) => cb(window));
|
|
37
|
+
});
|
|
38
|
+
const cbs = /* @__PURE__ */ new Set();
|
|
39
|
+
function subscribe(cb) {
|
|
40
|
+
cbs.add(cb);
|
|
41
|
+
return () => cbs.delete(cb);
|
|
42
|
+
}
|
|
43
|
+
function useWindowDimensions({
|
|
44
|
+
serverValue = initialValue
|
|
45
|
+
} = {}) {
|
|
46
|
+
return (0, import_react.useSyncExternalStore)(
|
|
47
|
+
subscribe,
|
|
48
|
+
() => import_react_native.Dimensions.get("window"),
|
|
49
|
+
() => import_constants.isWeb ? serverValue : import_react_native.Dimensions.get("window")
|
|
44
50
|
);
|
|
45
|
-
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
46
|
-
setState(current);
|
|
47
|
-
}, Object.values(current));
|
|
48
|
-
return state;
|
|
49
51
|
}
|
|
50
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
51
53
|
0 && (module.exports = {
|
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,
|
|
5
|
-
"names": [
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAsB;AACtB,mBAAqC;AACrC,0BAAuC;AAWvC,MAAM,eAAqB;AAAA,EACzB,QAAQ;AAAA,EACR,OAAO;AACT;AAEO,SAAS,iCAAiC,MAAY;AAC3D,SAAO,OAAO,cAAc,IAAI;AAClC;AAEA,+BAAW,iBAAiB,UAAU,MAAM;AAC1C,MAAI,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC;AAChC,CAAC;AAED,MAAM,MAAM,oBAAI,IAAc;AAI9B,SAAS,UAAU,IAAwB;AACzC,MAAI,IAAI,EAAE;AACV,SAAO,MAAM,IAAI,OAAO,EAAE;AAC5B;AAEO,SAAS,oBAAoB;AAAA,EAClC,cAAc;AAChB,IAA4B,CAAC,GAAG;AAC9B,aAAO;AAAA,IACL;AAAA,IACA,MAAM,+BAAW,IAAI,QAAQ;AAAA,IAC7B,MAAO,yBAAQ,cAAc,+BAAW,IAAI,QAAQ;AAAA,EACtD;AACF;",
|
|
5
|
+
"names": []
|
|
6
6
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { isWeb } from "@tamagui/constants";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
import { Dimensions } from "react-native";
|
|
4
4
|
const initialValue = {
|
|
5
|
-
fontScale: 1,
|
|
6
5
|
height: 800,
|
|
7
|
-
width: 600
|
|
8
|
-
scale: 1
|
|
6
|
+
width: 600
|
|
9
7
|
};
|
|
10
8
|
function configureInitialWindowDimensions(next) {
|
|
11
9
|
Object.assign(initialValue, next);
|
|
12
10
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
Dimensions.addEventListener("change", () => {
|
|
12
|
+
cbs.forEach((cb) => cb(window));
|
|
13
|
+
});
|
|
14
|
+
const cbs = /* @__PURE__ */ new Set();
|
|
15
|
+
function subscribe(cb) {
|
|
16
|
+
cbs.add(cb);
|
|
17
|
+
return () => cbs.delete(cb);
|
|
18
|
+
}
|
|
19
|
+
function useWindowDimensions({
|
|
20
|
+
serverValue = initialValue
|
|
21
|
+
} = {}) {
|
|
22
|
+
return useSyncExternalStore(
|
|
23
|
+
subscribe,
|
|
24
|
+
() => Dimensions.get("window"),
|
|
25
|
+
() => isWeb ? serverValue : Dimensions.get("window")
|
|
20
26
|
);
|
|
21
|
-
useIsomorphicLayoutEffect(() => {
|
|
22
|
-
setState(current);
|
|
23
|
-
}, Object.values(current));
|
|
24
|
-
return state;
|
|
25
27
|
}
|
|
26
28
|
export {
|
|
27
29
|
configureInitialWindowDimensions,
|
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,SAAS,
|
|
4
|
+
"mappings": "AAAA,SAAS,aAAa;AACtB,SAAS,4BAA4B;AACrC,SAAS,kBAA8B;AAWvC,MAAM,eAAqB;AAAA,EACzB,QAAQ;AAAA,EACR,OAAO;AACT;AAEO,SAAS,iCAAiC,MAAY;AAC3D,SAAO,OAAO,cAAc,IAAI;AAClC;AAEA,WAAW,iBAAiB,UAAU,MAAM;AAC1C,MAAI,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC;AAChC,CAAC;AAED,MAAM,MAAM,oBAAI,IAAc;AAI9B,SAAS,UAAU,IAAwB;AACzC,MAAI,IAAI,EAAE;AACV,SAAO,MAAM,IAAI,OAAO,EAAE;AAC5B;AAEO,SAAS,oBAAoB;AAAA,EAClC,cAAc;AAChB,IAA4B,CAAC,GAAG;AAC9B,SAAO;AAAA,IACL;AAAA,IACA,MAAM,WAAW,IAAI,QAAQ;AAAA,IAC7B,MAAO,QAAQ,cAAc,WAAW,IAAI,QAAQ;AAAA,EACtD;AACF;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/use-window-dimensions",
|
|
3
|
-
"version": "1.52.
|
|
3
|
+
"version": "1.52.6",
|
|
4
4
|
"types": "./types/index.d.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@tamagui/constants": "1.52.
|
|
29
|
+
"@tamagui/constants": "1.52.6"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tamagui/build": "1.52.
|
|
32
|
+
"@tamagui/build": "1.52.6",
|
|
33
33
|
"react": "^18.2.0",
|
|
34
34
|
"react-native": "^0.72.1"
|
|
35
35
|
},
|
package/src/index.ts
CHANGED
|
@@ -1,36 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { isWeb } from '@tamagui/constants'
|
|
2
|
+
import { useSyncExternalStore } from 'react'
|
|
3
|
+
import { Dimensions, ScaledSize } from 'react-native'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* SSR safe useWindowDimensions
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
type Size = {
|
|
10
|
+
width: number
|
|
11
|
+
height: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const initialValue: Size = {
|
|
11
15
|
height: 800,
|
|
12
16
|
width: 600,
|
|
13
|
-
scale: 1,
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
export function configureInitialWindowDimensions(next:
|
|
19
|
+
export function configureInitialWindowDimensions(next: Size) {
|
|
17
20
|
Object.assign(initialValue, next)
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
Dimensions.addEventListener('change', () => {
|
|
24
|
+
cbs.forEach((cb) => cb(window))
|
|
25
|
+
})
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
return current
|
|
25
|
-
}
|
|
27
|
+
const cbs = new Set<Function>()
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
initial ? { ...initialValue, ...initial } : initialValue
|
|
29
|
-
)
|
|
29
|
+
type WindowSizeListener = ({ window }: { window: ScaledSize }) => void
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
function subscribe(cb: WindowSizeListener) {
|
|
32
|
+
cbs.add(cb)
|
|
33
|
+
return () => cbs.delete(cb)
|
|
34
|
+
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
export function useWindowDimensions({
|
|
37
|
+
serverValue = initialValue,
|
|
38
|
+
}: { serverValue?: Size } = {}) {
|
|
39
|
+
return useSyncExternalStore(
|
|
40
|
+
subscribe,
|
|
41
|
+
() => Dimensions.get('window'),
|
|
42
|
+
() => (isWeb ? serverValue : Dimensions.get('window'))
|
|
43
|
+
)
|
|
36
44
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* SSR safe useWindowDimensions
|
|
3
|
+
*/
|
|
4
|
+
type Size = {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
};
|
|
8
|
+
export declare function configureInitialWindowDimensions(next: Size): void;
|
|
9
|
+
export declare function useWindowDimensions({ serverValue, }?: {
|
|
10
|
+
serverValue?: Size;
|
|
11
|
+
}): Size;
|
|
12
|
+
export {};
|
|
6
13
|
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,KAAK,IAAI,GAAG;IACV,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAOD,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,IAAI,QAE1D;AAeD,wBAAgB,mBAAmB,CAAC,EAClC,WAA0B,GAC3B,GAAE;IAAE,WAAW,CAAC,EAAE,IAAI,CAAA;CAAO,QAM7B"}
|