react-native-unistyles 1.1.2 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/commonjs/hooks/useDimensions.web.js +7 -5
- package/lib/commonjs/hooks/useDimensions.web.js.map +1 -1
- package/lib/module/hooks/useDimensions.web.js +8 -6
- package/lib/module/hooks/useDimensions.web.js.map +1 -1
- package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useDimensions.web.ts +9 -10
@@ -5,13 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.useDimensions = void 0;
|
7
7
|
var _react = require("react");
|
8
|
-
var _utils = require("../utils");
|
9
8
|
const useDimensions = () => {
|
10
9
|
const timerRef = (0, _react.useRef)();
|
11
|
-
const [screenSize, setScreenSize] = (0, _react.useState)({
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
const [screenSize, setScreenSize] = (0, _react.useState)({});
|
11
|
+
(0, _react.useLayoutEffect)(() => {
|
12
|
+
setScreenSize({
|
13
|
+
width: window.innerWidth,
|
14
|
+
height: window.innerHeight
|
15
|
+
});
|
16
|
+
}, []);
|
15
17
|
(0, _react.useEffect)(() => {
|
16
18
|
const handleResize = () => {
|
17
19
|
clearTimeout(timerRef.current);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","require","
|
1
|
+
{"version":3,"names":["_react","require","useDimensions","timerRef","useRef","screenSize","setScreenSize","useState","useLayoutEffect","width","window","innerWidth","height","innerHeight","useEffect","handleResize","clearTimeout","current","setTimeout","addEventListener","removeEventListener","exports"],"sourceRoot":"../../../src","sources":["hooks/useDimensions.web.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGO,MAAMC,aAAa,GAAGA,CAAA,KAAkB;EAC3C,MAAMC,QAAQ,GAAG,IAAAC,aAAM,EAAgC,CAAC;EACxD,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAC,eAAQ,EAAa,CAAC,CAAe,CAAC;EAE1E,IAAAC,sBAAe,EAAC,MAAM;IAClBF,aAAa,CAAC;MACVG,KAAK,EAAEC,MAAM,CAACC,UAAU;MACxBC,MAAM,EAAEF,MAAM,CAACG;IACnB,CAAC,CAAC;EACN,CAAC,EAAE,EAAE,CAAC;EAEN,IAAAC,gBAAS,EAAC,MAAM;IACZ,MAAMC,YAAY,GAAGA,CAAA,KAAM;MACvBC,YAAY,CAACb,QAAQ,CAACc,OAAO,CAAC;MAE9Bd,QAAQ,CAACc,OAAO,GAAGC,UAAU,CAAC,MAAMZ,aAAa,CAAC;QAC9CG,KAAK,EAAEC,MAAM,CAACC,UAAU;QACxBC,MAAM,EAAEF,MAAM,CAACG;MACnB,CAAC,CAAC,EAAE,GAAG,CAAC;IACZ,CAAC;IAEDH,MAAM,CAACS,gBAAgB,CAAC,QAAQ,EAAEJ,YAAY,CAAC;IAE/C,OAAO,MAAM;MACTL,MAAM,CAACU,mBAAmB,CAAC,QAAQ,EAAEL,YAAY,CAAC;MAClDC,YAAY,CAACb,QAAQ,CAACc,OAAO,CAAC;IAClC,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOZ,UAAU;AACrB,CAAC;AAAAgB,OAAA,CAAAnB,aAAA,GAAAA,aAAA"}
|
@@ -1,11 +1,13 @@
|
|
1
|
-
import { useEffect, useRef, useState } from 'react';
|
2
|
-
import { isServer } from '../utils';
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
3
2
|
export const useDimensions = () => {
|
4
3
|
const timerRef = useRef();
|
5
|
-
const [screenSize, setScreenSize] = useState({
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
const [screenSize, setScreenSize] = useState({});
|
5
|
+
useLayoutEffect(() => {
|
6
|
+
setScreenSize({
|
7
|
+
width: window.innerWidth,
|
8
|
+
height: window.innerHeight
|
9
|
+
});
|
10
|
+
}, []);
|
9
11
|
useEffect(() => {
|
10
12
|
const handleResize = () => {
|
11
13
|
clearTimeout(timerRef.current);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useEffect","
|
1
|
+
{"version":3,"names":["useEffect","useLayoutEffect","useRef","useState","useDimensions","timerRef","screenSize","setScreenSize","width","window","innerWidth","height","innerHeight","handleResize","clearTimeout","current","setTimeout","addEventListener","removeEventListener"],"sourceRoot":"../../../src","sources":["hooks/useDimensions.web.ts"],"mappings":"AAAA,SAASA,SAAS,EAAEC,eAAe,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAGpE,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAkB;EAC3C,MAAMC,QAAQ,GAAGH,MAAM,CAAgC,CAAC;EACxD,MAAM,CAACI,UAAU,EAAEC,aAAa,CAAC,GAAGJ,QAAQ,CAAa,CAAC,CAAe,CAAC;EAE1EF,eAAe,CAAC,MAAM;IAClBM,aAAa,CAAC;MACVC,KAAK,EAAEC,MAAM,CAACC,UAAU;MACxBC,MAAM,EAAEF,MAAM,CAACG;IACnB,CAAC,CAAC;EACN,CAAC,EAAE,EAAE,CAAC;EAENZ,SAAS,CAAC,MAAM;IACZ,MAAMa,YAAY,GAAGA,CAAA,KAAM;MACvBC,YAAY,CAACT,QAAQ,CAACU,OAAO,CAAC;MAE9BV,QAAQ,CAACU,OAAO,GAAGC,UAAU,CAAC,MAAMT,aAAa,CAAC;QAC9CC,KAAK,EAAEC,MAAM,CAACC,UAAU;QACxBC,MAAM,EAAEF,MAAM,CAACG;MACnB,CAAC,CAAC,EAAE,GAAG,CAAC;IACZ,CAAC;IAEDH,MAAM,CAACQ,gBAAgB,CAAC,QAAQ,EAAEJ,YAAY,CAAC;IAE/C,OAAO,MAAM;MACTJ,MAAM,CAACS,mBAAmB,CAAC,QAAQ,EAAEL,YAAY,CAAC;MAClDC,YAAY,CAACT,QAAQ,CAACU,OAAO,CAAC;IAClC,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOT,UAAU;AACrB,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useDimensions.web.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useDimensions.web.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;
|
1
|
+
{"version":3,"file":"useDimensions.web.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useDimensions.web.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1C,eAAO,MAAM,aAAa,QAAO,UA8BhC,CAAA"}
|
package/package.json
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
-
import { useEffect, useRef, useState } from 'react'
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
2
2
|
import type { ScreenSize } from '../types'
|
3
|
-
import { isServer } from '../utils'
|
4
3
|
|
5
4
|
export const useDimensions = (): ScreenSize => {
|
6
5
|
const timerRef = useRef<ReturnType<typeof setTimeout>>()
|
7
|
-
const [screenSize, setScreenSize] = useState<ScreenSize>({
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}
|
6
|
+
const [screenSize, setScreenSize] = useState<ScreenSize>({} as ScreenSize)
|
7
|
+
|
8
|
+
useLayoutEffect(() => {
|
9
|
+
setScreenSize({
|
10
|
+
width: window.innerWidth,
|
11
|
+
height: window.innerHeight
|
12
|
+
})
|
13
|
+
}, [])
|
15
14
|
|
16
15
|
useEffect(() => {
|
17
16
|
const handleResize = () => {
|