@tamagui/remove-scroll 2.7.7 → 3.0.0-beta.1091.1
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/RemoveScroll.cjs +17 -21
- package/dist/cjs/RemoveScroll.native.cjs +32 -0
- package/dist/cjs/RemoveScroll.native.js +18 -19
- package/dist/cjs/RemoveScroll.native.js.map +1 -1
- package/dist/cjs/index.cjs +9 -11
- package/dist/cjs/index.native.cjs +20 -0
- package/dist/cjs/index.native.js +9 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/useDisableScroll.cjs +95 -97
- package/dist/cjs/useDisableScroll.native.cjs +116 -0
- package/dist/cjs/useDisableScroll.native.js +97 -98
- package/dist/cjs/useDisableScroll.native.js.map +1 -1
- package/dist/esm/RemoveScroll.mjs +5 -3
- package/dist/esm/RemoveScroll.mjs.map +1 -1
- package/dist/esm/RemoveScroll.native.js +4 -3
- package/dist/esm/RemoveScroll.native.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.native.js +1 -2
- package/dist/esm/useDisableScroll.mjs +83 -79
- package/dist/esm/useDisableScroll.mjs.map +1 -1
- package/dist/esm/useDisableScroll.native.js +85 -81
- package/dist/esm/useDisableScroll.native.js.map +1 -1
- package/dist/jsx/RemoveScroll.mjs +5 -3
- package/dist/jsx/RemoveScroll.mjs.map +1 -1
- package/dist/jsx/RemoveScroll.native.cjs +32 -0
- package/dist/jsx/RemoveScroll.native.js +18 -19
- package/dist/jsx/RemoveScroll.native.js.map +1 -1
- package/dist/jsx/index.js +1 -2
- package/dist/jsx/index.mjs +1 -2
- package/dist/jsx/index.native.cjs +20 -0
- package/dist/jsx/index.native.js +9 -10
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/useDisableScroll.mjs +83 -79
- package/dist/jsx/useDisableScroll.mjs.map +1 -1
- package/dist/jsx/useDisableScroll.native.cjs +116 -0
- package/dist/jsx/useDisableScroll.native.js +97 -98
- package/dist/jsx/useDisableScroll.native.js.map +1 -1
- package/package.json +4 -3
- package/src/useDisableScroll.ts +5 -2
- package/types/useDisableScroll.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 (isIOSSafari()) {\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,O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gB;EACd,aAAa;GACX,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"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var useDisableScroll_exports = {};
|
|
24
|
+
__export(useDisableScroll_exports, { useDisableBodyScroll: () => useDisableBodyScroll });
|
|
25
|
+
module.exports = __toCommonJS(useDisableScroll_exports);
|
|
26
|
+
var import_react = require("react");
|
|
27
|
+
var canUseDOM = function() {
|
|
28
|
+
return typeof window !== "undefined" && !!window.document && !!window.document.createElement;
|
|
29
|
+
};
|
|
30
|
+
var refCount = 0;
|
|
31
|
+
var savedScrollY = 0;
|
|
32
|
+
var previousStyles = null;
|
|
33
|
+
function isIOSSafari() {
|
|
34
|
+
if (typeof navigator === "undefined") return false;
|
|
35
|
+
var ua = navigator.userAgent;
|
|
36
|
+
var isIOS = /iPad|iPhone|iPod/.test(ua) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1;
|
|
37
|
+
var isSafari = /^((?!chrome|android).)*safari/i.test(ua);
|
|
38
|
+
return isIOS && isSafari;
|
|
39
|
+
}
|
|
40
|
+
var useDisableBodyScroll = function(enabled) {
|
|
41
|
+
var wasEnabled = (0, import_react.useRef)(false);
|
|
42
|
+
(0, import_react.useEffect)(function() {
|
|
43
|
+
if (!canUseDOM()) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (enabled && !wasEnabled.current) {
|
|
47
|
+
wasEnabled.current = true;
|
|
48
|
+
if (++refCount === 1) {
|
|
49
|
+
var html = document.documentElement;
|
|
50
|
+
var body = document.body;
|
|
51
|
+
savedScrollY = window.scrollY;
|
|
52
|
+
previousStyles = {
|
|
53
|
+
htmlOverflow: html.style.overflow,
|
|
54
|
+
htmlScrollbarGutter: html.style.scrollbarGutter,
|
|
55
|
+
bodyPosition: body.style.position,
|
|
56
|
+
bodyTop: body.style.top,
|
|
57
|
+
bodyWidth: body.style.width,
|
|
58
|
+
bodyOverflow: body.style.overflow,
|
|
59
|
+
bodyOverscrollBehavior: body.style.overscrollBehavior
|
|
60
|
+
};
|
|
61
|
+
if (window.innerWidth > html.clientWidth) {
|
|
62
|
+
html.style.scrollbarGutter = "stable";
|
|
63
|
+
}
|
|
64
|
+
html.style.overflow = "hidden";
|
|
65
|
+
body.style.overscrollBehavior = "none";
|
|
66
|
+
if (isIOSSafari()) {
|
|
67
|
+
body.style.position = "fixed";
|
|
68
|
+
body.style.top = `-${savedScrollY}px`;
|
|
69
|
+
body.style.width = "100%";
|
|
70
|
+
body.style.overflow = "hidden";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} else if (!enabled && wasEnabled.current) {
|
|
74
|
+
wasEnabled.current = false;
|
|
75
|
+
if (--refCount === 0 && previousStyles) {
|
|
76
|
+
var html1 = document.documentElement;
|
|
77
|
+
var body1 = document.body;
|
|
78
|
+
html1.style.overflow = previousStyles.htmlOverflow;
|
|
79
|
+
html1.style.scrollbarGutter = previousStyles.htmlScrollbarGutter;
|
|
80
|
+
body1.style.position = previousStyles.bodyPosition;
|
|
81
|
+
body1.style.top = previousStyles.bodyTop;
|
|
82
|
+
body1.style.width = previousStyles.bodyWidth;
|
|
83
|
+
body1.style.overflow = previousStyles.bodyOverflow;
|
|
84
|
+
body1.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior;
|
|
85
|
+
if (savedScrollY > 0) {
|
|
86
|
+
window.scrollTo(0, savedScrollY);
|
|
87
|
+
}
|
|
88
|
+
previousStyles = null;
|
|
89
|
+
savedScrollY = 0;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}, [enabled]);
|
|
93
|
+
(0, import_react.useEffect)(function() {
|
|
94
|
+
return function() {
|
|
95
|
+
if (wasEnabled.current) {
|
|
96
|
+
wasEnabled.current = false;
|
|
97
|
+
if (--refCount === 0 && previousStyles) {
|
|
98
|
+
var html = document.documentElement;
|
|
99
|
+
var body = document.body;
|
|
100
|
+
html.style.overflow = previousStyles.htmlOverflow;
|
|
101
|
+
html.style.scrollbarGutter = previousStyles.htmlScrollbarGutter;
|
|
102
|
+
body.style.position = previousStyles.bodyPosition;
|
|
103
|
+
body.style.top = previousStyles.bodyTop;
|
|
104
|
+
body.style.width = previousStyles.bodyWidth;
|
|
105
|
+
body.style.overflow = previousStyles.bodyOverflow;
|
|
106
|
+
body.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior;
|
|
107
|
+
if (savedScrollY > 0) {
|
|
108
|
+
window.scrollTo(0, savedScrollY);
|
|
109
|
+
}
|
|
110
|
+
previousStyles = null;
|
|
111
|
+
savedScrollY = 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}, []);
|
|
116
|
+
};
|
|
@@ -5,115 +5,114 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
12
|
};
|
|
13
13
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
21
|
};
|
|
22
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
-
value: true
|
|
24
|
-
}), mod);
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
23
|
var useDisableScroll_exports = {};
|
|
26
|
-
__export(useDisableScroll_exports, {
|
|
27
|
-
useDisableBodyScroll: () => useDisableBodyScroll
|
|
28
|
-
});
|
|
24
|
+
__export(useDisableScroll_exports, { useDisableBodyScroll: () => useDisableBodyScroll });
|
|
29
25
|
module.exports = __toCommonJS(useDisableScroll_exports);
|
|
30
26
|
var import_react = require("react");
|
|
31
|
-
var canUseDOM = function
|
|
32
|
-
|
|
27
|
+
var canUseDOM = function() {
|
|
28
|
+
return typeof window !== "undefined" && !!window.document && !!window.document.createElement;
|
|
33
29
|
};
|
|
34
30
|
var refCount = 0;
|
|
35
31
|
var savedScrollY = 0;
|
|
36
32
|
var previousStyles = null;
|
|
37
33
|
function isIOSSafari() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
if (typeof navigator === "undefined") return false;
|
|
35
|
+
var ua = navigator.userAgent;
|
|
36
|
+
var isIOS = /iPad|iPhone|iPod/.test(ua) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1;
|
|
37
|
+
var isSafari = /^((?!chrome|android).)*safari/i.test(ua);
|
|
38
|
+
return isIOS && isSafari;
|
|
43
39
|
}
|
|
44
|
-
var useDisableBodyScroll = function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
40
|
+
var useDisableBodyScroll = function(enabled) {
|
|
41
|
+
var wasEnabled = (0, import_react.useRef)(false);
|
|
42
|
+
(0, import_react.useEffect)(function() {
|
|
43
|
+
if (!canUseDOM()) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (enabled && !wasEnabled.current) {
|
|
47
|
+
wasEnabled.current = true;
|
|
48
|
+
if (++refCount === 1) {
|
|
49
|
+
var html = document.documentElement;
|
|
50
|
+
var body = document.body;
|
|
51
|
+
savedScrollY = window.scrollY;
|
|
52
|
+
previousStyles = {
|
|
53
|
+
htmlOverflow: html.style.overflow,
|
|
54
|
+
htmlScrollbarGutter: html.style.scrollbarGutter,
|
|
55
|
+
bodyPosition: body.style.position,
|
|
56
|
+
bodyTop: body.style.top,
|
|
57
|
+
bodyWidth: body.style.width,
|
|
58
|
+
bodyOverflow: body.style.overflow,
|
|
59
|
+
bodyOverscrollBehavior: body.style.overscrollBehavior
|
|
60
|
+
};
|
|
61
|
+
if (window.innerWidth > html.clientWidth) {
|
|
62
|
+
html.style.scrollbarGutter = "stable";
|
|
63
|
+
}
|
|
64
|
+
html.style.overflow = "hidden";
|
|
65
|
+
body.style.overscrollBehavior = "none";
|
|
66
|
+
if (isIOSSafari()) {
|
|
67
|
+
body.style.position = "fixed";
|
|
68
|
+
body.style.top = `-${savedScrollY}px`;
|
|
69
|
+
body.style.width = "100%";
|
|
70
|
+
body.style.overflow = "hidden";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} else if (!enabled && wasEnabled.current) {
|
|
74
|
+
wasEnabled.current = false;
|
|
75
|
+
if (--refCount === 0 && previousStyles) {
|
|
76
|
+
var html1 = document.documentElement;
|
|
77
|
+
var body1 = document.body;
|
|
78
|
+
html1.style.overflow = previousStyles.htmlOverflow;
|
|
79
|
+
html1.style.scrollbarGutter = previousStyles.htmlScrollbarGutter;
|
|
80
|
+
body1.style.position = previousStyles.bodyPosition;
|
|
81
|
+
body1.style.top = previousStyles.bodyTop;
|
|
82
|
+
body1.style.width = previousStyles.bodyWidth;
|
|
83
|
+
body1.style.overflow = previousStyles.bodyOverflow;
|
|
84
|
+
body1.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior;
|
|
85
|
+
if (savedScrollY > 0) {
|
|
86
|
+
window.scrollTo(0, savedScrollY);
|
|
87
|
+
}
|
|
88
|
+
previousStyles = null;
|
|
89
|
+
savedScrollY = 0;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}, [enabled]);
|
|
93
|
+
(0, import_react.useEffect)(function() {
|
|
94
|
+
return function() {
|
|
95
|
+
if (wasEnabled.current) {
|
|
96
|
+
wasEnabled.current = false;
|
|
97
|
+
if (--refCount === 0 && previousStyles) {
|
|
98
|
+
var html = document.documentElement;
|
|
99
|
+
var body = document.body;
|
|
100
|
+
html.style.overflow = previousStyles.htmlOverflow;
|
|
101
|
+
html.style.scrollbarGutter = previousStyles.htmlScrollbarGutter;
|
|
102
|
+
body.style.position = previousStyles.bodyPosition;
|
|
103
|
+
body.style.top = previousStyles.bodyTop;
|
|
104
|
+
body.style.width = previousStyles.bodyWidth;
|
|
105
|
+
body.style.overflow = previousStyles.bodyOverflow;
|
|
106
|
+
body.style.overscrollBehavior = previousStyles.bodyOverscrollBehavior;
|
|
107
|
+
if (savedScrollY > 0) {
|
|
108
|
+
window.scrollTo(0, savedScrollY);
|
|
109
|
+
}
|
|
110
|
+
previousStyles = null;
|
|
111
|
+
savedScrollY = 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}, []);
|
|
118
116
|
};
|
|
117
|
+
|
|
119
118
|
//# sourceMappingURL=useDisableScroll.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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() {\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(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 (isIOSSafari()) {\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,4BAA4B,qBAC9B,CAAC;AACD,OAAO,UAAU,aAAa,wBAAwB;AACtD,IAAI,eAAe,QAAQ,OAAO;AAClC,IAAI,YAAY,WAAW;CACzB,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,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AAe;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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/remove-scroll",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-beta.1091.1",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"files": [
|
|
5
6
|
"src",
|
|
6
7
|
"types",
|
|
@@ -33,8 +34,8 @@
|
|
|
33
34
|
"clean:build": "tamagui-build clean:build"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"@tamagui/build": "
|
|
37
|
-
"react": "
|
|
37
|
+
"@tamagui/build": "3.0.0-beta.1091.1",
|
|
38
|
+
"react": "19.2.3"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
41
|
"react": ">=19"
|
package/src/useDisableScroll.ts
CHANGED
|
@@ -55,8 +55,11 @@ export const useDisableBodyScroll = (enabled: boolean): void => {
|
|
|
55
55
|
bodyOverscrollBehavior: body.style.overscrollBehavior,
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
//
|
|
59
|
-
|
|
58
|
+
// keep the gutter only where a scrollbar was: reserving one on a page
|
|
59
|
+
// that had none shifts the content by the scrollbar width on every open
|
|
60
|
+
if (window.innerWidth > html.clientWidth) {
|
|
61
|
+
html.style.scrollbarGutter = 'stable'
|
|
62
|
+
}
|
|
60
63
|
html.style.overflow = 'hidden'
|
|
61
64
|
|
|
62
65
|
// prevent scroll chaining on all browsers
|
|
@@ -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 //
|
|
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 (isIOSSafari()) {\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
|
}
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
package/dist/esm/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
package/dist/jsx/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
package/dist/jsx/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|