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.
@@ -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
- width: _utils.isServer ? undefined : window.innerWidth,
13
- height: _utils.isServer ? undefined : window.innerHeight
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","_utils","useDimensions","timerRef","useRef","screenSize","setScreenSize","useState","width","isServer","undefined","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;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAEO,MAAME,aAAa,GAAGA,CAAA,KAAkB;EAC3C,MAAMC,QAAQ,GAAG,IAAAC,aAAM,EAAgC,CAAC;EACxD,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAC,eAAQ,EAAa;IACrDC,KAAK,EAAEC,eAAQ,GACTC,SAAS,GACTC,MAAM,CAACC,UAAU;IACvBC,MAAM,EAAEJ,eAAQ,GACVC,SAAS,GACTC,MAAM,CAACG;EACjB,CAAe,CAAC;EAEhB,IAAAC,gBAAS,EAAC,MAAM;IACZ,MAAMC,YAAY,GAAGA,CAAA,KAAM;MACvBC,YAAY,CAACd,QAAQ,CAACe,OAAO,CAAC;MAE9Bf,QAAQ,CAACe,OAAO,GAAGC,UAAU,CAAC,MAAMb,aAAa,CAAC;QAC9CE,KAAK,EAAEG,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,CAACd,QAAQ,CAACe,OAAO,CAAC;IAClC,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOb,UAAU;AACrB,CAAC;AAAAiB,OAAA,CAAApB,aAAA,GAAAA,aAAA"}
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
- width: isServer ? undefined : window.innerWidth,
7
- height: isServer ? undefined : window.innerHeight
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","useRef","useState","isServer","useDimensions","timerRef","screenSize","setScreenSize","width","undefined","window","innerWidth","height","innerHeight","handleResize","clearTimeout","current","setTimeout","addEventListener","removeEventListener"],"sourceRoot":"../../../src","sources":["hooks/useDimensions.web.ts"],"mappings":"AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEnD,SAASC,QAAQ,QAAQ,UAAU;AAEnC,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAkB;EAC3C,MAAMC,QAAQ,GAAGJ,MAAM,CAAgC,CAAC;EACxD,MAAM,CAACK,UAAU,EAAEC,aAAa,CAAC,GAAGL,QAAQ,CAAa;IACrDM,KAAK,EAAEL,QAAQ,GACTM,SAAS,GACTC,MAAM,CAACC,UAAU;IACvBC,MAAM,EAAET,QAAQ,GACVM,SAAS,GACTC,MAAM,CAACG;EACjB,CAAe,CAAC;EAEhBb,SAAS,CAAC,MAAM;IACZ,MAAMc,YAAY,GAAGA,CAAA,KAAM;MACvBC,YAAY,CAACV,QAAQ,CAACW,OAAO,CAAC;MAE9BX,QAAQ,CAACW,OAAO,GAAGC,UAAU,CAAC,MAAMV,aAAa,CAAC;QAC9CC,KAAK,EAAEE,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,CAACV,QAAQ,CAACW,OAAO,CAAC;IAClC,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOV,UAAU;AACrB,CAAC"}
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;AAG1C,eAAO,MAAM,aAAa,QAAO,UA8BhC,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,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -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
- width: isServer
9
- ? undefined
10
- : window.innerWidth,
11
- height: isServer
12
- ? undefined
13
- : window.innerHeight
14
- } as ScreenSize)
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 = () => {