Skip to content

Commit 71a3db3

Browse files
authored
Merge pull request #2 from stripearmy/issue_1
added vh logic and downgraded dependency versions >=React 16.8.0
2 parents 5a7e1c1 + 3378764 commit 71a3db3

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-ios-scroll-lock",
33
"author": "Arsen Mkrtchyan (stripearmy)",
44
"private": false,
5-
"version": "1.0.4",
5+
"version": "1.0.7",
66
"description": "A lightweight CSS-only scroll lock solution for iOS Safari and Android",
77
"type": "module",
88
"main": "dist/react-ios-scroll-lock.umd.js",
@@ -83,6 +83,10 @@
8383
"lint": "eslint .",
8484
"preview": "vite preview"
8585
},
86+
"peerDependencies": {
87+
"react": ">= 16.8.0",
88+
"react-dom": ">= 16.8.0"
89+
},
8690
"devDependencies": {
8791
"@eslint/js": "^9.21.0",
8892
"@types/node": "^22.13.10",
@@ -98,8 +102,8 @@
98102
"typescript-eslint": "^8.24.1",
99103
"vite": "^6.2.0",
100104
"vite-plugin-static-copy": "^2.3.0",
101-
"react": "^19.0.0",
102-
"react-dom": "^19.0.0",
105+
"react": ">= 16.8.0",
106+
"react-dom": ">= 16.8.0",
103107
"vite-plugin-dts": "^4.5.3"
104108
}
105109
}

src/IosScrollLock.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// import "./styles/react-ios-scroll-lock.css";
2-
import React from "react";
1+
import React, {useEffect} from 'react';
2+
import("./styles/styles.css");
33

44
interface IosScrollLockProps {
55
bgColor?: string;
@@ -16,7 +16,28 @@ function IosScrollLock({
1616
className = "",
1717
bgColor = "",
1818
}: IosScrollLockProps) {
19-
import("./styles/styles.css");
19+
20+
useEffect(() => {
21+
const isIOS =
22+
typeof window !== "undefined" &&
23+
navigator.userAgent.match(/iPhone|iPad|iPod/i);
24+
25+
function setIOSHeight() {
26+
document.documentElement.style.setProperty(
27+
"--isl-vh",
28+
window.innerHeight * 0.01 + "px"
29+
);
30+
}
31+
32+
if (isIOS) {
33+
setIOSHeight();
34+
window.addEventListener("resize", setIOSHeight);
35+
36+
return () => {
37+
window.removeEventListener("resize", setIOSHeight);
38+
};
39+
}
40+
}, []);
2041

2142
const rootStyle = bgColor
2243
? ({ "--isl-bg": bgColor } as React.CSSProperties)

0 commit comments

Comments
 (0)