@tamagui/remove-scroll 3.0.16 → 3.0.18
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/useDisableScroll.cjs +3 -2
- package/dist/cjs/useDisableScroll.native.cjs +3 -2
- package/dist/cjs/useDisableScroll.native.js +3 -2
- package/dist/cjs/useDisableScroll.native.js.map +1 -1
- package/dist/esm/useDisableScroll.mjs +3 -2
- package/dist/esm/useDisableScroll.mjs.map +1 -1
- package/dist/esm/useDisableScroll.native.js +3 -2
- package/dist/esm/useDisableScroll.native.js.map +1 -1
- package/dist/jsx/useDisableScroll.mjs +3 -2
- package/dist/jsx/useDisableScroll.mjs.map +1 -1
- package/dist/jsx/useDisableScroll.native.cjs +3 -2
- package/dist/jsx/useDisableScroll.native.js +3 -2
- package/dist/jsx/useDisableScroll.native.js.map +1 -1
- package/package.json +3 -3
- package/src/useDisableScroll.ts +5 -2
- package/types/useDisableScroll.d.ts.map +1 -1
|
@@ -44,6 +44,7 @@ const useDisableBodyScroll = (enabled) => {
|
|
|
44
44
|
if (++refCount === 1) {
|
|
45
45
|
const html = document.documentElement;
|
|
46
46
|
const body = document.body;
|
|
47
|
+
const isIOS = isIOSSafari();
|
|
47
48
|
savedScrollY = window.scrollY;
|
|
48
49
|
previousStyles = {
|
|
49
50
|
htmlOverflow: html.style.overflow,
|
|
@@ -54,12 +55,12 @@ const useDisableBodyScroll = (enabled) => {
|
|
|
54
55
|
bodyOverflow: body.style.overflow,
|
|
55
56
|
bodyOverscrollBehavior: body.style.overscrollBehavior
|
|
56
57
|
};
|
|
57
|
-
if (window.innerWidth > html.clientWidth) {
|
|
58
|
+
if (!isIOS && window.innerWidth > html.clientWidth) {
|
|
58
59
|
html.style.scrollbarGutter = "stable";
|
|
59
60
|
}
|
|
60
61
|
html.style.overflow = "hidden";
|
|
61
62
|
body.style.overscrollBehavior = "none";
|
|
62
|
-
if (
|
|
63
|
+
if (isIOS) {
|
|
63
64
|
body.style.position = "fixed";
|
|
64
65
|
body.style.top = `-${savedScrollY}px`;
|
|
65
66
|
body.style.width = "100%";
|
|
@@ -48,6 +48,7 @@ var useDisableBodyScroll = function useDisableBodyScroll2(enabled) {
|
|
|
48
48
|
if (++refCount === 1) {
|
|
49
49
|
var html = document.documentElement;
|
|
50
50
|
var body = document.body;
|
|
51
|
+
var isIOS = isIOSSafari();
|
|
51
52
|
savedScrollY = window.scrollY;
|
|
52
53
|
previousStyles = {
|
|
53
54
|
htmlOverflow: html.style.overflow,
|
|
@@ -58,12 +59,12 @@ var useDisableBodyScroll = function useDisableBodyScroll2(enabled) {
|
|
|
58
59
|
bodyOverflow: body.style.overflow,
|
|
59
60
|
bodyOverscrollBehavior: body.style.overscrollBehavior
|
|
60
61
|
};
|
|
61
|
-
if (window.innerWidth > html.clientWidth) {
|
|
62
|
+
if (!isIOS && window.innerWidth > html.clientWidth) {
|
|
62
63
|
html.style.scrollbarGutter = "stable";
|
|
63
64
|
}
|
|
64
65
|
html.style.overflow = "hidden";
|
|
65
66
|
body.style.overscrollBehavior = "none";
|
|
66
|
-
if (
|
|
67
|
+
if (isIOS) {
|
|
67
68
|
body.style.position = "fixed";
|
|
68
69
|
body.style.top = `-${savedScrollY}px`;
|
|
69
70
|
body.style.width = "100%";
|
|
@@ -48,6 +48,7 @@ var useDisableBodyScroll = function useDisableBodyScroll2(enabled) {
|
|
|
48
48
|
if (++refCount === 1) {
|
|
49
49
|
var html = document.documentElement;
|
|
50
50
|
var body = document.body;
|
|
51
|
+
var isIOS = isIOSSafari();
|
|
51
52
|
savedScrollY = window.scrollY;
|
|
52
53
|
previousStyles = {
|
|
53
54
|
htmlOverflow: html.style.overflow,
|
|
@@ -58,12 +59,12 @@ var useDisableBodyScroll = function useDisableBodyScroll2(enabled) {
|
|
|
58
59
|
bodyOverflow: body.style.overflow,
|
|
59
60
|
bodyOverscrollBehavior: body.style.overscrollBehavior
|
|
60
61
|
};
|
|
61
|
-
if (window.innerWidth > html.clientWidth) {
|
|
62
|
+
if (!isIOS && window.innerWidth > html.clientWidth) {
|
|
62
63
|
html.style.scrollbarGutter = "stable";
|
|
63
64
|
}
|
|
64
65
|
html.style.overflow = "hidden";
|
|
65
66
|
body.style.overscrollBehavior = "none";
|
|
66
|
-
if (
|
|
67
|
+
if (isIOS) {
|
|
67
68
|
body.style.position = "fixed";
|
|
68
69
|
body.style.top = `-${savedScrollY}px`;
|
|
69
70
|
body.style.width = "100%";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDisableScroll.native.js","names":[],"sources":["cjs/useDisableScroll.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useDisableScroll_exports = {};\n__export(useDisableScroll_exports, {\n useDisableBodyScroll: () => useDisableBodyScroll\n});\nmodule.exports = __toCommonJS(useDisableScroll_exports);\nvar import_react = require(\"react\");\nvar canUseDOM = function canUseDOM2() {\n return typeof window !== \"undefined\" && !!window.document && !!window.document.createElement;\n};\nvar refCount = 0;\nvar savedScrollY = 0;\nvar previousStyles = null;\nfunction isIOSSafari() {\n if (typeof navigator === \"undefined\") return false;\n var ua = navigator.userAgent;\n var isIOS = /iPad|iPhone|iPod/.test(ua) || navigator.platform === \"MacIntel\" && navigator.maxTouchPoints > 1;\n var isSafari = /^((?!chrome|android).)*safari/i.test(ua);\n return isIOS && isSafari;\n}\nvar useDisableBodyScroll = function useDisableBodyScroll2(enabled) {\n var wasEnabled = (0, import_react.useRef)(false);\n (0, import_react.useEffect)(function() {\n if (!canUseDOM()) {\n return;\n }\n if (enabled && !wasEnabled.current) {\n wasEnabled.current = true;\n if (++refCount === 1) {\n var html = document.documentElement;\n var body = document.body;\n savedScrollY = window.scrollY;\n previousStyles = {\n htmlOverflow: html.style.overflow,\n htmlScrollbarGutter: html.style.scrollbarGutter,\n bodyPosition: body.style.position,\n bodyTop: body.style.top,\n bodyWidth: body.style.width,\n bodyOverflow: body.style.overflow,\n bodyOverscrollBehavior: body.style.overscrollBehavior\n };\n if (window.innerWidth > html.clientWidth) {\n html.style.scrollbarGutter = \"stable\";\n }\n html.style.overflow = \"hidden\";\n body.style.overscrollBehavior = \"none\";\n if (
|
|
1
|
+
{"version":3,"file":"useDisableScroll.native.js","names":[],"sources":["cjs/useDisableScroll.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useDisableScroll_exports = {};\n__export(useDisableScroll_exports, {\n useDisableBodyScroll: () => useDisableBodyScroll\n});\nmodule.exports = __toCommonJS(useDisableScroll_exports);\nvar import_react = require(\"react\");\nvar canUseDOM = function canUseDOM2() {\n return typeof window !== \"undefined\" && !!window.document && !!window.document.createElement;\n};\nvar refCount = 0;\nvar savedScrollY = 0;\nvar previousStyles = null;\nfunction isIOSSafari() {\n if (typeof navigator === \"undefined\") return false;\n var ua = navigator.userAgent;\n var isIOS = /iPad|iPhone|iPod/.test(ua) || navigator.platform === \"MacIntel\" && navigator.maxTouchPoints > 1;\n var isSafari = /^((?!chrome|android).)*safari/i.test(ua);\n return isIOS && isSafari;\n}\nvar useDisableBodyScroll = function useDisableBodyScroll2(enabled) {\n var wasEnabled = (0, import_react.useRef)(false);\n (0, import_react.useEffect)(function() {\n if (!canUseDOM()) {\n return;\n }\n if (enabled && !wasEnabled.current) {\n wasEnabled.current = true;\n if (++refCount === 1) {\n var html = document.documentElement;\n var body = document.body;\n var isIOS = isIOSSafari();\n savedScrollY = window.scrollY;\n previousStyles = {\n htmlOverflow: html.style.overflow,\n htmlScrollbarGutter: html.style.scrollbarGutter,\n bodyPosition: body.style.position,\n bodyTop: body.style.top,\n bodyWidth: body.style.width,\n bodyOverflow: body.style.overflow,\n bodyOverscrollBehavior: body.style.overscrollBehavior\n };\n if (!isIOS && window.innerWidth > html.clientWidth) {\n html.style.scrollbarGutter = \"stable\";\n }\n html.style.overflow = \"hidden\";\n body.style.overscrollBehavior = \"none\";\n if (isIOS) {\n body.style.position = \"fixed\";\n body.style.top = `-${savedScrollY}px`;\n body.style.width = \"100%\";\n body.style.overflow = \"hidden\";\n }\n }\n } else if (!enabled && wasEnabled.current) {\n wasEnabled.current = false;\n if (--refCount === 0 && previousStyles) {\n var html1 = document.documentElement;\n var body1 = document.body;\n html1.style.overflow = previousStyles.htmlOverflow;\n html1.style.scrollbarGutter = previousStyles.htmlScrollbarGutter;\n body1.style.position = previousStyles.bodyPosition;\n body1.style.top = previousStyles.bodyTop;\n body1.style.width = previousStyles.bodyWidth;\n body1.style.overflow = previousStyles.bodyOverflow;\n body1.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior;\n if (savedScrollY > 0) {\n window.scrollTo(0, savedScrollY);\n }\n previousStyles = null;\n savedScrollY = 0;\n }\n }\n }, [\n enabled\n ]);\n (0, import_react.useEffect)(function() {\n return function() {\n if (wasEnabled.current) {\n wasEnabled.current = false;\n if (--refCount === 0 && previousStyles) {\n var html = document.documentElement;\n var body = document.body;\n html.style.overflow = previousStyles.htmlOverflow;\n html.style.scrollbarGutter = previousStyles.htmlScrollbarGutter;\n body.style.position = previousStyles.bodyPosition;\n body.style.top = previousStyles.bodyTop;\n body.style.width = previousStyles.bodyWidth;\n body.style.overflow = previousStyles.bodyOverflow;\n body.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior;\n if (savedScrollY > 0) {\n window.scrollTo(0, savedScrollY);\n }\n previousStyles = null;\n savedScrollY = 0;\n }\n }\n };\n }, []);\n};\n//# sourceMappingURL=useDisableScroll.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,2BAA2B,CAAC;AAChC,SAAS,0BAA0B,EACjC,4BAA4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,QAAQ;KACnB,KAAK,MAAM,WAAW;IACxB;GACF;EACF,OAAO,IAAI,CAAC,WAAW,WAAW,SAAS;GACzC,WAAW,UAAU;GACrB,IAAI,EAAE,aAAa,KAAK,gBAAgB;IACtC,IAAI,QAAQ,SAAS;IACrB,IAAI,QAAQ,SAAS;IACrB,MAAM,MAAM,WAAW,eAAe;IACtC,MAAM,MAAM,kBAAkB,eAAe;IAC7C,MAAM,MAAM,WAAW,eAAe;IACtC,MAAM,MAAM,MAAM,eAAe;IACjC,MAAM,MAAM,QAAQ,eAAe;IACnC,MAAM,MAAM,WAAW,eAAe;IACtC,MAAM,MAAM,qBAAqB,eAAe;IAChD,IAAI,eAAe,GAAG;KACpB,OAAO,SAAS,GAAG,YAAY;IACjC;IACA,iBAAiB;IACjB,eAAe;GACjB;EACF;CACF,GAAG,CACD,OACF,CAAC;CACD,CAAC,GAAG,aAAa,UAAS,CAAE,WAAW;EACrC,OAAO,WAAW;GAChB,IAAI,WAAW,SAAS;IACtB,WAAW,UAAU;IACrB,IAAI,EAAE,aAAa,KAAK,gBAAgB;KACtC,IAAI,OAAO,SAAS;KACpB,IAAI,OAAO,SAAS;KACpB,KAAK,MAAM,WAAW,eAAe;KACrC,KAAK,MAAM,kBAAkB,eAAe;KAC5C,KAAK,MAAM,WAAW,eAAe;KACrC,KAAK,MAAM,MAAM,eAAe;KAChC,KAAK,MAAM,QAAQ,eAAe;KAClC,KAAK,MAAM,WAAW,eAAe;KACrC,KAAK,MAAM,qBAAqB,eAAe;KAC/C,IAAI,eAAe,GAAG;MACpB,OAAO,SAAS,GAAG,YAAY;KACjC;KACA,iBAAiB;KACjB,eAAe;IACjB;GACF;EACF;CACF,GAAG,CAAC,CAAC;AACP"}
|
|
@@ -22,6 +22,7 @@ const useDisableBodyScroll = (enabled) => {
|
|
|
22
22
|
if (++refCount === 1) {
|
|
23
23
|
const html = document.documentElement;
|
|
24
24
|
const body = document.body;
|
|
25
|
+
const isIOS = isIOSSafari();
|
|
25
26
|
savedScrollY = window.scrollY;
|
|
26
27
|
previousStyles = {
|
|
27
28
|
htmlOverflow: html.style.overflow,
|
|
@@ -32,12 +33,12 @@ const useDisableBodyScroll = (enabled) => {
|
|
|
32
33
|
bodyOverflow: body.style.overflow,
|
|
33
34
|
bodyOverscrollBehavior: body.style.overscrollBehavior
|
|
34
35
|
};
|
|
35
|
-
if (window.innerWidth > html.clientWidth) {
|
|
36
|
+
if (!isIOS && window.innerWidth > html.clientWidth) {
|
|
36
37
|
html.style.scrollbarGutter = "stable";
|
|
37
38
|
}
|
|
38
39
|
html.style.overflow = "hidden";
|
|
39
40
|
body.style.overscrollBehavior = "none";
|
|
40
|
-
if (
|
|
41
|
+
if (isIOS) {
|
|
41
42
|
body.style.position = "fixed";
|
|
42
43
|
body.style.top = `-${savedScrollY}px`;
|
|
43
44
|
body.style.width = "100%";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDisableScroll.js","names":[],"sources":["esm/useDisableScroll.js"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nconst canUseDOM = () => typeof window !== \"undefined\" && !!window.document && !!window.document.createElement;\nlet refCount = 0;\nlet savedScrollY = 0;\nlet previousStyles = null;\nfunction isIOSSafari() {\n if (typeof navigator === \"undefined\") return false;\n const ua = navigator.userAgent;\n const isIOS = /iPad|iPhone|iPod/.test(ua) || navigator.platform === \"MacIntel\" && navigator.maxTouchPoints > 1;\n const isSafari = /^((?!chrome|android).)*safari/i.test(ua);\n return isIOS && isSafari;\n}\nconst useDisableBodyScroll = (enabled) => {\n const wasEnabled = useRef(false);\n useEffect(() => {\n if (!canUseDOM()) {\n return;\n }\n if (enabled && !wasEnabled.current) {\n wasEnabled.current = true;\n if (++refCount === 1) {\n const html = document.documentElement;\n const body = document.body;\n savedScrollY = window.scrollY;\n previousStyles = {\n htmlOverflow: html.style.overflow,\n htmlScrollbarGutter: html.style.scrollbarGutter,\n bodyPosition: body.style.position,\n bodyTop: body.style.top,\n bodyWidth: body.style.width,\n bodyOverflow: body.style.overflow,\n bodyOverscrollBehavior: body.style.overscrollBehavior\n };\n if (window.innerWidth > html.clientWidth) {\n html.style.scrollbarGutter = \"stable\";\n }\n html.style.overflow = \"hidden\";\n body.style.overscrollBehavior = \"none\";\n if (
|
|
1
|
+
{"version":3,"file":"useDisableScroll.js","names":[],"sources":["esm/useDisableScroll.js"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nconst canUseDOM = () => typeof window !== \"undefined\" && !!window.document && !!window.document.createElement;\nlet refCount = 0;\nlet savedScrollY = 0;\nlet previousStyles = null;\nfunction isIOSSafari() {\n if (typeof navigator === \"undefined\") return false;\n const ua = navigator.userAgent;\n const isIOS = /iPad|iPhone|iPod/.test(ua) || navigator.platform === \"MacIntel\" && navigator.maxTouchPoints > 1;\n const isSafari = /^((?!chrome|android).)*safari/i.test(ua);\n return isIOS && isSafari;\n}\nconst useDisableBodyScroll = (enabled) => {\n const wasEnabled = useRef(false);\n useEffect(() => {\n if (!canUseDOM()) {\n return;\n }\n if (enabled && !wasEnabled.current) {\n wasEnabled.current = true;\n if (++refCount === 1) {\n const html = document.documentElement;\n const body = document.body;\n const isIOS = isIOSSafari();\n savedScrollY = window.scrollY;\n previousStyles = {\n htmlOverflow: html.style.overflow,\n htmlScrollbarGutter: html.style.scrollbarGutter,\n bodyPosition: body.style.position,\n bodyTop: body.style.top,\n bodyWidth: body.style.width,\n bodyOverflow: body.style.overflow,\n bodyOverscrollBehavior: body.style.overscrollBehavior\n };\n if (!isIOS && window.innerWidth > html.clientWidth) {\n html.style.scrollbarGutter = \"stable\";\n }\n html.style.overflow = \"hidden\";\n body.style.overscrollBehavior = \"none\";\n if (isIOS) {\n body.style.position = \"fixed\";\n body.style.top = `-${savedScrollY}px`;\n body.style.width = \"100%\";\n body.style.overflow = \"hidden\";\n }\n }\n } else if (!enabled && wasEnabled.current) {\n wasEnabled.current = false;\n if (--refCount === 0 && previousStyles) {\n const html = document.documentElement;\n const body = document.body;\n html.style.overflow = previousStyles.htmlOverflow;\n html.style.scrollbarGutter = previousStyles.htmlScrollbarGutter;\n body.style.position = previousStyles.bodyPosition;\n body.style.top = previousStyles.bodyTop;\n body.style.width = previousStyles.bodyWidth;\n body.style.overflow = previousStyles.bodyOverflow;\n body.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior;\n if (savedScrollY > 0) {\n window.scrollTo(0, savedScrollY);\n }\n previousStyles = null;\n savedScrollY = 0;\n }\n }\n }, [enabled]);\n useEffect(() => {\n return () => {\n if (wasEnabled.current) {\n wasEnabled.current = false;\n if (--refCount === 0 && previousStyles) {\n const html = document.documentElement;\n const body = document.body;\n html.style.overflow = previousStyles.htmlOverflow;\n html.style.scrollbarGutter = previousStyles.htmlScrollbarGutter;\n body.style.position = previousStyles.bodyPosition;\n body.style.top = previousStyles.bodyTop;\n body.style.width = previousStyles.bodyWidth;\n body.style.overflow = previousStyles.bodyOverflow;\n body.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior;\n if (savedScrollY > 0) {\n window.scrollTo(0, savedScrollY);\n }\n previousStyles = null;\n savedScrollY = 0;\n }\n }\n };\n }, []);\n};\nexport {\n useDisableBodyScroll\n};\n//# sourceMappingURL=useDisableScroll.js.map\n"],"mappings":";;;AACA,MAAM,kBAAkB,OAAO,WAAW,eAAe,CAAC,CAAC,OAAO,YAAY,CAAC,CAAC,OAAO,SAAS;AAChG,IAAI,WAAW;AACf,IAAI,eAAe;AACnB,IAAI,iBAAiB;AACrB,SAAS,cAAc;CACrB,IAAI,OAAO,cAAc,aAAa,OAAO;CAC7C,MAAM,KAAK,UAAU;CACrB,MAAM,QAAQ,mBAAmB,KAAK,EAAE,KAAK,UAAU,aAAa,cAAc,UAAU,iBAAiB;CAC7G,MAAM,WAAW,iCAAiC,KAAK,EAAE;CACzD,OAAO,SAAS;AAClB;AACA,MAAM,wBAAwB,YAAY;CACxC,MAAM,aAAa,OAAO,KAAK;CAC/B,gBAAgB;EACd,IAAI,CAAC,UAAU,GAAG;GACh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AgB;KACtC,MAAM,OAAO,SAAS;KACtB,MAAM,OAAO,SAAS;KACtB,KAAK,MAAM,WAAW,eAAe;KACrC,KAAK,MAAM,kBAAkB,eAAe;KAC5C,KAAK,MAAM,WAAW,eAAe;KACrC,KAAK,MAAM,MAAM,eAAe;KAChC,KAAK,MAAM,QAAQ,eAAe;KAClC,KAAK,MAAM,WAAW,eAAe;KACrC,KAAK,MAAM,qBAAqB,eAAe;KAC/C,IAAI,eAAe,GAAG;MACpB,OAAO,SAAS,GAAG,YAAY;KACjC;KACA,iBAAiB;KACjB,eAAe;IACjB;GACF;EACF;CACF,GAAG,CAAC,CAAC;AACP"}
|
|
@@ -24,6 +24,7 @@ var useDisableBodyScroll = function useDisableBodyScroll2(enabled) {
|
|
|
24
24
|
if (++refCount === 1) {
|
|
25
25
|
var html = document.documentElement;
|
|
26
26
|
var body = document.body;
|
|
27
|
+
var isIOS = isIOSSafari();
|
|
27
28
|
savedScrollY = window.scrollY;
|
|
28
29
|
previousStyles = {
|
|
29
30
|
htmlOverflow: html.style.overflow,
|
|
@@ -34,12 +35,12 @@ var useDisableBodyScroll = function useDisableBodyScroll2(enabled) {
|
|
|
34
35
|
bodyOverflow: body.style.overflow,
|
|
35
36
|
bodyOverscrollBehavior: body.style.overscrollBehavior
|
|
36
37
|
};
|
|
37
|
-
if (window.innerWidth > html.clientWidth) {
|
|
38
|
+
if (!isIOS && window.innerWidth > html.clientWidth) {
|
|
38
39
|
html.style.scrollbarGutter = "stable";
|
|
39
40
|
}
|
|
40
41
|
html.style.overflow = "hidden";
|
|
41
42
|
body.style.overscrollBehavior = "none";
|
|
42
|
-
if (
|
|
43
|
+
if (isIOS) {
|
|
43
44
|
body.style.position = "fixed";
|
|
44
45
|
body.style.top = `-${savedScrollY}px`;
|
|
45
46
|
body.style.width = "100%";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDisableScroll.native.js","names":[],"sources":["esm/useDisableScroll.native.js"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nvar canUseDOM = function canUseDOM2() {\n return typeof window !== \"undefined\" && !!window.document && !!window.document.createElement;\n};\nvar refCount = 0;\nvar savedScrollY = 0;\nvar previousStyles = null;\nfunction isIOSSafari() {\n if (typeof navigator === \"undefined\") return false;\n var ua = navigator.userAgent;\n var isIOS = /iPad|iPhone|iPod/.test(ua) || navigator.platform === \"MacIntel\" && navigator.maxTouchPoints > 1;\n var isSafari = /^((?!chrome|android).)*safari/i.test(ua);\n return isIOS && isSafari;\n}\nvar useDisableBodyScroll = function useDisableBodyScroll2(enabled) {\n var wasEnabled = useRef(false);\n useEffect(function() {\n if (!canUseDOM()) {\n return;\n }\n if (enabled && !wasEnabled.current) {\n wasEnabled.current = true;\n if (++refCount === 1) {\n var html = document.documentElement;\n var body = document.body;\n savedScrollY = window.scrollY;\n previousStyles = {\n htmlOverflow: html.style.overflow,\n htmlScrollbarGutter: html.style.scrollbarGutter,\n bodyPosition: body.style.position,\n bodyTop: body.style.top,\n bodyWidth: body.style.width,\n bodyOverflow: body.style.overflow,\n bodyOverscrollBehavior: body.style.overscrollBehavior\n };\n if (window.innerWidth > html.clientWidth) {\n html.style.scrollbarGutter = \"stable\";\n }\n html.style.overflow = \"hidden\";\n body.style.overscrollBehavior = \"none\";\n if (
|
|
1
|
+
{"version":3,"file":"useDisableScroll.native.js","names":[],"sources":["esm/useDisableScroll.native.js"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nvar canUseDOM = function canUseDOM2() {\n return typeof window !== \"undefined\" && !!window.document && !!window.document.createElement;\n};\nvar refCount = 0;\nvar savedScrollY = 0;\nvar previousStyles = null;\nfunction isIOSSafari() {\n if (typeof navigator === \"undefined\") return false;\n var ua = navigator.userAgent;\n var isIOS = /iPad|iPhone|iPod/.test(ua) || navigator.platform === \"MacIntel\" && navigator.maxTouchPoints > 1;\n var isSafari = /^((?!chrome|android).)*safari/i.test(ua);\n return isIOS && isSafari;\n}\nvar useDisableBodyScroll = function useDisableBodyScroll2(enabled) {\n var wasEnabled = useRef(false);\n useEffect(function() {\n if (!canUseDOM()) {\n return;\n }\n if (enabled && !wasEnabled.current) {\n wasEnabled.current = true;\n if (++refCount === 1) {\n var html = document.documentElement;\n var body = document.body;\n var isIOS = isIOSSafari();\n savedScrollY = window.scrollY;\n previousStyles = {\n htmlOverflow: html.style.overflow,\n htmlScrollbarGutter: html.style.scrollbarGutter,\n bodyPosition: body.style.position,\n bodyTop: body.style.top,\n bodyWidth: body.style.width,\n bodyOverflow: body.style.overflow,\n bodyOverscrollBehavior: body.style.overscrollBehavior\n };\n if (!isIOS && window.innerWidth > html.clientWidth) {\n html.style.scrollbarGutter = \"stable\";\n }\n html.style.overflow = \"hidden\";\n body.style.overscrollBehavior = \"none\";\n if (isIOS) {\n body.style.position = \"fixed\";\n body.style.top = `-${savedScrollY}px`;\n body.style.width = \"100%\";\n body.style.overflow = \"hidden\";\n }\n }\n } else if (!enabled && wasEnabled.current) {\n wasEnabled.current = false;\n if (--refCount === 0 && previousStyles) {\n var html1 = document.documentElement;\n var body1 = document.body;\n html1.style.overflow = previousStyles.htmlOverflow;\n html1.style.scrollbarGutter = previousStyles.htmlScrollbarGutter;\n body1.style.position = previousStyles.bodyPosition;\n body1.style.top = previousStyles.bodyTop;\n body1.style.width = previousStyles.bodyWidth;\n body1.style.overflow = previousStyles.bodyOverflow;\n body1.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior;\n if (savedScrollY > 0) {\n window.scrollTo(0, savedScrollY);\n }\n previousStyles = null;\n savedScrollY = 0;\n }\n }\n }, [\n enabled\n ]);\n useEffect(function() {\n return function() {\n if (wasEnabled.current) {\n wasEnabled.current = false;\n if (--refCount === 0 && previousStyles) {\n var html = document.documentElement;\n var body = document.body;\n html.style.overflow = previousStyles.htmlOverflow;\n html.style.scrollbarGutter = previousStyles.htmlScrollbarGutter;\n body.style.position = previousStyles.bodyPosition;\n body.style.top = previousStyles.bodyTop;\n body.style.width = previousStyles.bodyWidth;\n body.style.overflow = previousStyles.bodyOverflow;\n body.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior;\n if (savedScrollY > 0) {\n window.scrollTo(0, savedScrollY);\n }\n previousStyles = null;\n savedScrollY = 0;\n }\n }\n };\n }, []);\n};\nexport {\n useDisableBodyScroll\n};\n//# sourceMappingURL=useDisableScroll.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,SAAS,aAAa;CACpC,OAAO,OAAO,WAAW,eAAe,CAAC,CAAC,OAAO,YAAY,CAAC,CAAC,OAAO,SAAS;AACjF;AACA,IAAI,WAAW;AACf,IAAI,eAAe;AACnB,IAAI,iBAAiB;AACrB,SAAS,cAAc;CACrB,IAAI,OAAO,cAAc,aAAa,OAAO;CAC7C,IAAI,KAAK,UAAU;CACnB,IAAI,QAAQ,mBAAmB,KAAK,EAAE,KAAK,UAAU,aAAa,cAAc,UAAU,iBAAiB;CAC3G,IAAI,WAAW,iCAAiC,KAAK,EAAE;CACvD,OAAO,SAAS;AAClB;AACA,IAAI,uBAAuB,SAAS,sBAAsB,SAAS;CACjE,IAAI,aAAa,OAAO,KAAK;CAC7B,UAAU,WAAW;EACnB,IAAI,CAAC,UAAU,GAAG;GAChB;EACF;EACA,IAAI,WAAW,CAAC,WAAW,SAAS;GAClC,WAAW,UAAU;GACrB,IAAI,EAAE,aAAa,GAAG;IACpB,IAAI,OAAO,SAAS;IACpB,IAAI,OAAO,SAAS;IACpB,IAAI,QAAQ,YAAY;IACxB,eAAe,OAAO;IACtB,iBAAiB;KACf,cAAc,KAAK,MAAM;KACzB,qBAAqB,KAAK,MAAM;KAChC,cAAc,KAAK,MAAM;KACzB,SAAS,KAAK,MAAM;KACpB,WAAW,KAAK,MAAM;KACtB,cAAc,KAAK,MAAM;KACzB,wBAAwB,KAAK,MAAM;IACrC;IACA,IAAI,CAAC,SAAS,OAAO,aAAa,KAAK,aAAa;KAClD,KAAK,MAAM,kBAAkB;IAC/B;IACA,KAAK,MAAM,WAAW;IACtB,KAAK,MAAM,qBAAqB;IAChC,IAAI,OAAO;KACT,KAAK,MAAM,WAAW;KACtB,KAAK,MAAM,MAAM,IAAI,aAAa;KAClC,KAAK,MAAM,QAAQ;KACnB,KAAK,MAAM,WAAW;IACxB;GACF;EACF,OAAO,IAAI,CAAC,WAAW,WAAW,SAAS;GACzC,WAAW,UAAU;GACrB,IAAI,EAAE,aAAa,KAAK,gBAAgB;IACtC,IAAI,QAAQ,SAAS;IACrB,IAAI,QAAQ,SAAS;IACrB,MAAM,MAAM,WAAW,eAAe;IACtC,MAAM,MAAM,kBAAkB,eAAe;IAC7C,MAAM,MAAM,WAAW,eAAe;IACtC,MAAM,MAAM,MAAM,eAAe;IACjC,MAAM,MAAM,QAAQ,eAAe;IACnC,MAAM,MAAM,WAAW,eAAe;IACtC,MAAM,MAAM,qBAAqB,eAAe;IAChD,IAAI,eAAe,GAAG;KACpB,OAAO,SAAS,GAAG,YAAY;IACjC;IACA,iBAAiB;IACjB,eAAe;GACjB;EACF;CACF,GAAG,CACD,OACF,CAAC;CACD,UAAU,WAAW;EACnB,OAAO,WAAW;GAChB,IAAI,WAAW,SAAS;IACtB,WAAW,UAAU;IACrB,IAAI,EAAE,aAAa,KAAK,gBAAgB;KACtC,IAAI,OAAO,SAAS;KACpB,IAAI,OAAO,SAAS;KACpB,KAAK,MAAM,WAAW,eAAe;KACrC,KAAK,MAAM,kBAAkB,eAAe;KAC5C,KAAK,MAAM,WAAW,eAAe;KACrC,KAAK,MAAM,MAAM,eAAe;KAChC,KAAK,MAAM,QAAQ,eAAe;KAClC,KAAK,MAAM,WAAW,eAAe;KACrC,KAAK,MAAM,qBAAqB,eAAe;KAC/C,IAAI,eAAe,GAAG;MACpB,OAAO,SAAS,GAAG,YAAY;KACjC;KACA,iBAAiB;KACjB,eAAe;IACjB;GACF;EACF;CACF,GAAG,CAAC,CAAC;AACP"}
|
|
@@ -22,6 +22,7 @@ const useDisableBodyScroll = (enabled) => {
|
|
|
22
22
|
if (++refCount === 1) {
|
|
23
23
|
const html = document.documentElement;
|
|
24
24
|
const body = document.body;
|
|
25
|
+
const isIOS = isIOSSafari();
|
|
25
26
|
savedScrollY = window.scrollY;
|
|
26
27
|
previousStyles = {
|
|
27
28
|
htmlOverflow: html.style.overflow,
|
|
@@ -32,12 +33,12 @@ const useDisableBodyScroll = (enabled) => {
|
|
|
32
33
|
bodyOverflow: body.style.overflow,
|
|
33
34
|
bodyOverscrollBehavior: body.style.overscrollBehavior
|
|
34
35
|
};
|
|
35
|
-
if (window.innerWidth > html.clientWidth) {
|
|
36
|
+
if (!isIOS && window.innerWidth > html.clientWidth) {
|
|
36
37
|
html.style.scrollbarGutter = "stable";
|
|
37
38
|
}
|
|
38
39
|
html.style.overflow = "hidden";
|
|
39
40
|
body.style.overscrollBehavior = "none";
|
|
40
|
-
if (
|
|
41
|
+
if (isIOS) {
|
|
41
42
|
body.style.position = "fixed";
|
|
42
43
|
body.style.top = `-${savedScrollY}px`;
|
|
43
44
|
body.style.width = "100%";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDisableScroll.js","names":[],"sources":["jsx/useDisableScroll.js"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nconst canUseDOM = () => typeof window !== \"undefined\" && !!window.document && !!window.document.createElement;\nlet refCount = 0;\nlet savedScrollY = 0;\nlet previousStyles = null;\nfunction isIOSSafari() {\n if (typeof navigator === \"undefined\") return false;\n const ua = navigator.userAgent;\n const isIOS = /iPad|iPhone|iPod/.test(ua) || navigator.platform === \"MacIntel\" && navigator.maxTouchPoints > 1;\n const isSafari = /^((?!chrome|android).)*safari/i.test(ua);\n return isIOS && isSafari;\n}\nconst useDisableBodyScroll = (enabled) => {\n const wasEnabled = useRef(false);\n useEffect(() => {\n if (!canUseDOM()) {\n return;\n }\n if (enabled && !wasEnabled.current) {\n wasEnabled.current = true;\n if (++refCount === 1) {\n const html = document.documentElement;\n const body = document.body;\n savedScrollY = window.scrollY;\n previousStyles = {\n htmlOverflow: html.style.overflow,\n htmlScrollbarGutter: html.style.scrollbarGutter,\n bodyPosition: body.style.position,\n bodyTop: body.style.top,\n bodyWidth: body.style.width,\n bodyOverflow: body.style.overflow,\n bodyOverscrollBehavior: body.style.overscrollBehavior\n };\n if (window.innerWidth > html.clientWidth) {\n html.style.scrollbarGutter = \"stable\";\n }\n html.style.overflow = \"hidden\";\n body.style.overscrollBehavior = \"none\";\n if (
|
|
1
|
+
{"version":3,"file":"useDisableScroll.js","names":[],"sources":["jsx/useDisableScroll.js"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nconst canUseDOM = () => typeof window !== \"undefined\" && !!window.document && !!window.document.createElement;\nlet refCount = 0;\nlet savedScrollY = 0;\nlet previousStyles = null;\nfunction isIOSSafari() {\n if (typeof navigator === \"undefined\") return false;\n const ua = navigator.userAgent;\n const isIOS = /iPad|iPhone|iPod/.test(ua) || navigator.platform === \"MacIntel\" && navigator.maxTouchPoints > 1;\n const isSafari = /^((?!chrome|android).)*safari/i.test(ua);\n return isIOS && isSafari;\n}\nconst useDisableBodyScroll = (enabled) => {\n const wasEnabled = useRef(false);\n useEffect(() => {\n if (!canUseDOM()) {\n return;\n }\n if (enabled && !wasEnabled.current) {\n wasEnabled.current = true;\n if (++refCount === 1) {\n const html = document.documentElement;\n const body = document.body;\n const isIOS = isIOSSafari();\n savedScrollY = window.scrollY;\n previousStyles = {\n htmlOverflow: html.style.overflow,\n htmlScrollbarGutter: html.style.scrollbarGutter,\n bodyPosition: body.style.position,\n bodyTop: body.style.top,\n bodyWidth: body.style.width,\n bodyOverflow: body.style.overflow,\n bodyOverscrollBehavior: body.style.overscrollBehavior\n };\n if (!isIOS && window.innerWidth > html.clientWidth) {\n html.style.scrollbarGutter = \"stable\";\n }\n html.style.overflow = \"hidden\";\n body.style.overscrollBehavior = \"none\";\n if (isIOS) {\n body.style.position = \"fixed\";\n body.style.top = `-${savedScrollY}px`;\n body.style.width = \"100%\";\n body.style.overflow = \"hidden\";\n }\n }\n } else if (!enabled && wasEnabled.current) {\n wasEnabled.current = false;\n if (--refCount === 0 && previousStyles) {\n const html = document.documentElement;\n const body = document.body;\n html.style.overflow = previousStyles.htmlOverflow;\n html.style.scrollbarGutter = previousStyles.htmlScrollbarGutter;\n body.style.position = previousStyles.bodyPosition;\n body.style.top = previousStyles.bodyTop;\n body.style.width = previousStyles.bodyWidth;\n body.style.overflow = previousStyles.bodyOverflow;\n body.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior;\n if (savedScrollY > 0) {\n window.scrollTo(0, savedScrollY);\n }\n previousStyles = null;\n savedScrollY = 0;\n }\n }\n }, [enabled]);\n useEffect(() => {\n return () => {\n if (wasEnabled.current) {\n wasEnabled.current = false;\n if (--refCount === 0 && previousStyles) {\n const html = document.documentElement;\n const body = document.body;\n html.style.overflow = previousStyles.htmlOverflow;\n html.style.scrollbarGutter = previousStyles.htmlScrollbarGutter;\n body.style.position = previousStyles.bodyPosition;\n body.style.top = previousStyles.bodyTop;\n body.style.width = previousStyles.bodyWidth;\n body.style.overflow = previousStyles.bodyOverflow;\n body.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior;\n if (savedScrollY > 0) {\n window.scrollTo(0, savedScrollY);\n }\n previousStyles = null;\n savedScrollY = 0;\n }\n }\n };\n }, []);\n};\nexport {\n useDisableBodyScroll\n};\n//# sourceMappingURL=useDisableScroll.js.map\n"],"mappings":";;;AACA,MAAM,kBAAkB,OAAO,WAAW,eAAe,CAAC,CAAC,OAAO,YAAY,CAAC,CAAC,OAAO,SAAS;AAChG,IAAI,WAAW;AACf,IAAI,eAAe;AACnB,IAAI,iBAAiB;AACrB,SAAS,cAAc;CACrB,IAAI,OAAO,cAAc,aAAa,OAAO;CAC7C,MAAM,KAAK,UAAU;CACrB,MAAM,QAAQ,mBAAmB,KAAK,EAAE,KAAK,UAAU,aAAa,cAAc,UAAU,iBAAiB;CAC7G,MAAM,WAAW,iCAAiC,KAAK,EAAE;CACzD,OAAO,SAAS;AAClB;AACA,MAAM,wBAAwB,YAAY;CACxC,M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,IAAI,WAAW,SAAS;IACtB,WAAW,UAAU;IACrB,IAAI,EAAE,aAAa,KAAK,gBAAgB;KACtC,MAAM,OAAO,SAAS;KACtB,MAAM,OAAO,SAAS;KACtB,KAAK,MAAM,WAAW,eAAe;KACrC,KAAK,MAAM,kBAAkB,eAAe;KAC5C,KAAK,MAAM,WAAW,eAAe;KACrC,KAAK,MAAM,MAAM,eAAe;KAChC,KAAK,MAAM,QAAQ,eAAe;KAClC,KAAK,MAAM,WAAW,eAAe;KACrC,KAAK,MAAM,qBAAqB,eAAe;KAC/C,IAAI,eAAe,GAAG;MACpB,OAAO,SAAS,GAAG,YAAY;KACjC;KACA,iBAAiB;KACjB,eAAe;IACjB;GACF;EACF;CACF,GAAG,CAAC,CAAC;AACP"}
|
|
@@ -48,6 +48,7 @@ var useDisableBodyScroll = function useDisableBodyScroll2(enabled) {
|
|
|
48
48
|
if (++refCount === 1) {
|
|
49
49
|
var html = document.documentElement;
|
|
50
50
|
var body = document.body;
|
|
51
|
+
var isIOS = isIOSSafari();
|
|
51
52
|
savedScrollY = window.scrollY;
|
|
52
53
|
previousStyles = {
|
|
53
54
|
htmlOverflow: html.style.overflow,
|
|
@@ -58,12 +59,12 @@ var useDisableBodyScroll = function useDisableBodyScroll2(enabled) {
|
|
|
58
59
|
bodyOverflow: body.style.overflow,
|
|
59
60
|
bodyOverscrollBehavior: body.style.overscrollBehavior
|
|
60
61
|
};
|
|
61
|
-
if (window.innerWidth > html.clientWidth) {
|
|
62
|
+
if (!isIOS && window.innerWidth > html.clientWidth) {
|
|
62
63
|
html.style.scrollbarGutter = "stable";
|
|
63
64
|
}
|
|
64
65
|
html.style.overflow = "hidden";
|
|
65
66
|
body.style.overscrollBehavior = "none";
|
|
66
|
-
if (
|
|
67
|
+
if (isIOS) {
|
|
67
68
|
body.style.position = "fixed";
|
|
68
69
|
body.style.top = `-${savedScrollY}px`;
|
|
69
70
|
body.style.width = "100%";
|
|
@@ -48,6 +48,7 @@ var useDisableBodyScroll = function useDisableBodyScroll2(enabled) {
|
|
|
48
48
|
if (++refCount === 1) {
|
|
49
49
|
var html = document.documentElement;
|
|
50
50
|
var body = document.body;
|
|
51
|
+
var isIOS = isIOSSafari();
|
|
51
52
|
savedScrollY = window.scrollY;
|
|
52
53
|
previousStyles = {
|
|
53
54
|
htmlOverflow: html.style.overflow,
|
|
@@ -58,12 +59,12 @@ var useDisableBodyScroll = function useDisableBodyScroll2(enabled) {
|
|
|
58
59
|
bodyOverflow: body.style.overflow,
|
|
59
60
|
bodyOverscrollBehavior: body.style.overscrollBehavior
|
|
60
61
|
};
|
|
61
|
-
if (window.innerWidth > html.clientWidth) {
|
|
62
|
+
if (!isIOS && window.innerWidth > html.clientWidth) {
|
|
62
63
|
html.style.scrollbarGutter = "stable";
|
|
63
64
|
}
|
|
64
65
|
html.style.overflow = "hidden";
|
|
65
66
|
body.style.overscrollBehavior = "none";
|
|
66
|
-
if (
|
|
67
|
+
if (isIOS) {
|
|
67
68
|
body.style.position = "fixed";
|
|
68
69
|
body.style.top = `-${savedScrollY}px`;
|
|
69
70
|
body.style.width = "100%";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDisableScroll.native.js","names":[],"sources":["jsx/useDisableScroll.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useDisableScroll_exports = {};\n__export(useDisableScroll_exports, {\n useDisableBodyScroll: () => useDisableBodyScroll\n});\nmodule.exports = __toCommonJS(useDisableScroll_exports);\nvar import_react = require(\"react\");\nvar canUseDOM = function canUseDOM2() {\n return typeof window !== \"undefined\" && !!window.document && !!window.document.createElement;\n};\nvar refCount = 0;\nvar savedScrollY = 0;\nvar previousStyles = null;\nfunction isIOSSafari() {\n if (typeof navigator === \"undefined\") return false;\n var ua = navigator.userAgent;\n var isIOS = /iPad|iPhone|iPod/.test(ua) || navigator.platform === \"MacIntel\" && navigator.maxTouchPoints > 1;\n var isSafari = /^((?!chrome|android).)*safari/i.test(ua);\n return isIOS && isSafari;\n}\nvar useDisableBodyScroll = function useDisableBodyScroll2(enabled) {\n var wasEnabled = (0, import_react.useRef)(false);\n (0, import_react.useEffect)(function() {\n if (!canUseDOM()) {\n return;\n }\n if (enabled && !wasEnabled.current) {\n wasEnabled.current = true;\n if (++refCount === 1) {\n var html = document.documentElement;\n var body = document.body;\n savedScrollY = window.scrollY;\n previousStyles = {\n htmlOverflow: html.style.overflow,\n htmlScrollbarGutter: html.style.scrollbarGutter,\n bodyPosition: body.style.position,\n bodyTop: body.style.top,\n bodyWidth: body.style.width,\n bodyOverflow: body.style.overflow,\n bodyOverscrollBehavior: body.style.overscrollBehavior\n };\n if (window.innerWidth > html.clientWidth) {\n html.style.scrollbarGutter = \"stable\";\n }\n html.style.overflow = \"hidden\";\n body.style.overscrollBehavior = \"none\";\n if (
|
|
1
|
+
{"version":3,"file":"useDisableScroll.native.js","names":[],"sources":["jsx/useDisableScroll.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useDisableScroll_exports = {};\n__export(useDisableScroll_exports, {\n useDisableBodyScroll: () => useDisableBodyScroll\n});\nmodule.exports = __toCommonJS(useDisableScroll_exports);\nvar import_react = require(\"react\");\nvar canUseDOM = function canUseDOM2() {\n return typeof window !== \"undefined\" && !!window.document && !!window.document.createElement;\n};\nvar refCount = 0;\nvar savedScrollY = 0;\nvar previousStyles = null;\nfunction isIOSSafari() {\n if (typeof navigator === \"undefined\") return false;\n var ua = navigator.userAgent;\n var isIOS = /iPad|iPhone|iPod/.test(ua) || navigator.platform === \"MacIntel\" && navigator.maxTouchPoints > 1;\n var isSafari = /^((?!chrome|android).)*safari/i.test(ua);\n return isIOS && isSafari;\n}\nvar useDisableBodyScroll = function useDisableBodyScroll2(enabled) {\n var wasEnabled = (0, import_react.useRef)(false);\n (0, import_react.useEffect)(function() {\n if (!canUseDOM()) {\n return;\n }\n if (enabled && !wasEnabled.current) {\n wasEnabled.current = true;\n if (++refCount === 1) {\n var html = document.documentElement;\n var body = document.body;\n var isIOS = isIOSSafari();\n savedScrollY = window.scrollY;\n previousStyles = {\n htmlOverflow: html.style.overflow,\n htmlScrollbarGutter: html.style.scrollbarGutter,\n bodyPosition: body.style.position,\n bodyTop: body.style.top,\n bodyWidth: body.style.width,\n bodyOverflow: body.style.overflow,\n bodyOverscrollBehavior: body.style.overscrollBehavior\n };\n if (!isIOS && window.innerWidth > html.clientWidth) {\n html.style.scrollbarGutter = \"stable\";\n }\n html.style.overflow = \"hidden\";\n body.style.overscrollBehavior = \"none\";\n if (isIOS) {\n body.style.position = \"fixed\";\n body.style.top = `-${savedScrollY}px`;\n body.style.width = \"100%\";\n body.style.overflow = \"hidden\";\n }\n }\n } else if (!enabled && wasEnabled.current) {\n wasEnabled.current = false;\n if (--refCount === 0 && previousStyles) {\n var html1 = document.documentElement;\n var body1 = document.body;\n html1.style.overflow = previousStyles.htmlOverflow;\n html1.style.scrollbarGutter = previousStyles.htmlScrollbarGutter;\n body1.style.position = previousStyles.bodyPosition;\n body1.style.top = previousStyles.bodyTop;\n body1.style.width = previousStyles.bodyWidth;\n body1.style.overflow = previousStyles.bodyOverflow;\n body1.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior;\n if (savedScrollY > 0) {\n window.scrollTo(0, savedScrollY);\n }\n previousStyles = null;\n savedScrollY = 0;\n }\n }\n }, [\n enabled\n ]);\n (0, import_react.useEffect)(function() {\n return function() {\n if (wasEnabled.current) {\n wasEnabled.current = false;\n if (--refCount === 0 && previousStyles) {\n var html = document.documentElement;\n var body = document.body;\n html.style.overflow = previousStyles.htmlOverflow;\n html.style.scrollbarGutter = previousStyles.htmlScrollbarGutter;\n body.style.position = previousStyles.bodyPosition;\n body.style.top = previousStyles.bodyTop;\n body.style.width = previousStyles.bodyWidth;\n body.style.overflow = previousStyles.bodyOverflow;\n body.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior;\n if (savedScrollY > 0) {\n window.scrollTo(0, savedScrollY);\n }\n previousStyles = null;\n savedScrollY = 0;\n }\n }\n };\n }, []);\n};\n//# sourceMappingURL=useDisableScroll.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,O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eAAe;KAChC,KAAK,MAAM,QAAQ,eAAe;KAClC,KAAK,MAAM,WAAW,eAAe;KACrC,KAAK,MAAM,qBAAqB,eAAe;KAC/C,IAAI,eAAe,GAAG;MACpB,OAAO,SAAS,GAAG,YAAY;KACjC;KACA,iBAAiB;KACjB,eAAe;IACjB;GACF;EACF;CACF,GAAG,CAAC,CAAC;AACP"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/remove-scroll",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.18",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"clean:build": "tamagui-build clean:build"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@tamagui/build": "3.0.
|
|
37
|
+
"@tamagui/build": "3.0.18",
|
|
38
38
|
"react": "19.2.3"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"url": "git+https://github.com/tamagui/tamagui.git",
|
|
47
47
|
"directory": "code/ui/remove-scroll"
|
|
48
48
|
},
|
|
49
|
-
"releaseSourceCommit": "
|
|
49
|
+
"releaseSourceCommit": "e7ebeed9d446eee3e0eda4b0dd5e55dd8ec46bf7"
|
|
50
50
|
}
|
package/src/useDisableScroll.ts
CHANGED
|
@@ -40,6 +40,7 @@ export const useDisableBodyScroll = (enabled: boolean): void => {
|
|
|
40
40
|
if (++refCount === 1) {
|
|
41
41
|
const html = document.documentElement
|
|
42
42
|
const body = document.body
|
|
43
|
+
const isIOS = isIOSSafari()
|
|
43
44
|
|
|
44
45
|
// save current scroll position before locking
|
|
45
46
|
savedScrollY = window.scrollY
|
|
@@ -57,7 +58,9 @@ export const useDisableBodyScroll = (enabled: boolean): void => {
|
|
|
57
58
|
|
|
58
59
|
// keep the gutter only where a scrollbar was: reserving one on a page
|
|
59
60
|
// that had none shifts the content by the scrollbar width on every open
|
|
60
|
-
|
|
61
|
+
// iOS uses overlay scrollbars, so locking never removes a gutter.
|
|
62
|
+
// measuring clientWidth here would flush the opening modal's layout.
|
|
63
|
+
if (!isIOS && window.innerWidth > html.clientWidth) {
|
|
61
64
|
html.style.scrollbarGutter = 'stable'
|
|
62
65
|
}
|
|
63
66
|
html.style.overflow = 'hidden'
|
|
@@ -67,7 +70,7 @@ export const useDisableBodyScroll = (enabled: boolean): void => {
|
|
|
67
70
|
|
|
68
71
|
// for iOS Safari, use position:fixed workaround
|
|
69
72
|
// this also helps with any edge cases on other mobile browsers
|
|
70
|
-
if (
|
|
73
|
+
if (isIOS) {
|
|
71
74
|
body.style.position = 'fixed'
|
|
72
75
|
body.style.top = `-${savedScrollY}px`
|
|
73
76
|
body.style.width = '100%'
|
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
],
|
|
7
7
|
"version": 3,
|
|
8
8
|
"sourcesContent": [
|
|
9
|
-
"import { useEffect, useRef } from 'react'\n\nconst canUseDOM = () =>\n typeof window !== 'undefined' && !!window.document && !!window.document.createElement\n\nlet refCount = 0\nlet savedScrollY = 0\nlet previousStyles: {\n htmlOverflow: string\n htmlScrollbarGutter: string\n bodyPosition: string\n bodyTop: string\n bodyWidth: string\n bodyOverflow: string\n bodyOverscrollBehavior: string\n} | null = null\n\n// detect iOS Safari which needs position:fixed workaround\nfunction isIOSSafari() {\n if (typeof navigator === 'undefined') return false\n const ua = navigator.userAgent\n const isIOS =\n /iPad|iPhone|iPod/.test(ua) ||\n (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)\n const isSafari = /^((?!chrome|android).)*safari/i.test(ua)\n return isIOS && isSafari\n}\n\nexport const useDisableBodyScroll = (enabled: boolean): void => {\n const wasEnabled = useRef(false)\n\n useEffect(() => {\n if (!canUseDOM()) {\n return\n }\n\n if (enabled && !wasEnabled.current) {\n wasEnabled.current = true\n\n if (++refCount === 1) {\n const html = document.documentElement\n const body = document.body\n\n // save current scroll position before locking\n savedScrollY = window.scrollY\n\n // save previous styles\n previousStyles = {\n htmlOverflow: html.style.overflow,\n htmlScrollbarGutter: html.style.scrollbarGutter,\n bodyPosition: body.style.position,\n bodyTop: body.style.top,\n bodyWidth: body.style.width,\n bodyOverflow: body.style.overflow,\n bodyOverscrollBehavior: body.style.overscrollBehavior,\n }\n\n // keep the gutter only where a scrollbar was: reserving one on a page\n // that had none shifts the content by the scrollbar width on every open\n if (window.innerWidth > html.clientWidth) {\n html.style.scrollbarGutter = 'stable'\n }\n html.style.overflow = 'hidden'\n\n // prevent scroll chaining on all browsers\n body.style.overscrollBehavior = 'none'\n\n // for iOS Safari, use position:fixed workaround\n // this also helps with any edge cases on other mobile browsers\n if (
|
|
9
|
+
"import { useEffect, useRef } from 'react'\n\nconst canUseDOM = () =>\n typeof window !== 'undefined' && !!window.document && !!window.document.createElement\n\nlet refCount = 0\nlet savedScrollY = 0\nlet previousStyles: {\n htmlOverflow: string\n htmlScrollbarGutter: string\n bodyPosition: string\n bodyTop: string\n bodyWidth: string\n bodyOverflow: string\n bodyOverscrollBehavior: string\n} | null = null\n\n// detect iOS Safari which needs position:fixed workaround\nfunction isIOSSafari() {\n if (typeof navigator === 'undefined') return false\n const ua = navigator.userAgent\n const isIOS =\n /iPad|iPhone|iPod/.test(ua) ||\n (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)\n const isSafari = /^((?!chrome|android).)*safari/i.test(ua)\n return isIOS && isSafari\n}\n\nexport const useDisableBodyScroll = (enabled: boolean): void => {\n const wasEnabled = useRef(false)\n\n useEffect(() => {\n if (!canUseDOM()) {\n return\n }\n\n if (enabled && !wasEnabled.current) {\n wasEnabled.current = true\n\n if (++refCount === 1) {\n const html = document.documentElement\n const body = document.body\n const isIOS = isIOSSafari()\n\n // save current scroll position before locking\n savedScrollY = window.scrollY\n\n // save previous styles\n previousStyles = {\n htmlOverflow: html.style.overflow,\n htmlScrollbarGutter: html.style.scrollbarGutter,\n bodyPosition: body.style.position,\n bodyTop: body.style.top,\n bodyWidth: body.style.width,\n bodyOverflow: body.style.overflow,\n bodyOverscrollBehavior: body.style.overscrollBehavior,\n }\n\n // keep the gutter only where a scrollbar was: reserving one on a page\n // that had none shifts the content by the scrollbar width on every open\n // iOS uses overlay scrollbars, so locking never removes a gutter.\n // measuring clientWidth here would flush the opening modal's layout.\n if (!isIOS && window.innerWidth > html.clientWidth) {\n html.style.scrollbarGutter = 'stable'\n }\n html.style.overflow = 'hidden'\n\n // prevent scroll chaining on all browsers\n body.style.overscrollBehavior = 'none'\n\n // for iOS Safari, use position:fixed workaround\n // this also helps with any edge cases on other mobile browsers\n if (isIOS) {\n body.style.position = 'fixed'\n body.style.top = `-${savedScrollY}px`\n body.style.width = '100%'\n body.style.overflow = 'hidden'\n }\n }\n } else if (!enabled && wasEnabled.current) {\n wasEnabled.current = false\n\n if (--refCount === 0 && previousStyles) {\n const html = document.documentElement\n const body = document.body\n\n // restore previous styles\n html.style.overflow = previousStyles.htmlOverflow\n html.style.scrollbarGutter = previousStyles.htmlScrollbarGutter\n body.style.position = previousStyles.bodyPosition\n body.style.top = previousStyles.bodyTop\n body.style.width = previousStyles.bodyWidth\n body.style.overflow = previousStyles.bodyOverflow\n body.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior\n\n // restore scroll position (browsers reset to 0 when overflow:hidden is removed)\n if (savedScrollY > 0) {\n window.scrollTo(0, savedScrollY)\n }\n\n previousStyles = null\n savedScrollY = 0\n }\n }\n }, [enabled])\n\n // cleanup on unmount\n useEffect(() => {\n return () => {\n if (wasEnabled.current) {\n wasEnabled.current = false\n if (--refCount === 0 && previousStyles) {\n const html = document.documentElement\n const body = document.body\n\n html.style.overflow = previousStyles.htmlOverflow\n html.style.scrollbarGutter = previousStyles.htmlScrollbarGutter\n body.style.position = previousStyles.bodyPosition\n body.style.top = previousStyles.bodyTop\n body.style.width = previousStyles.bodyWidth\n body.style.overflow = previousStyles.bodyOverflow\n body.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior\n\n if (savedScrollY > 0) {\n window.scrollTo(0, savedScrollY)\n }\n\n previousStyles = null\n savedScrollY = 0\n }\n }\n }\n }, [])\n}\n"
|
|
10
10
|
]
|
|
11
11
|
}
|