Skip to content

Commit 8865b18

Browse files
authored
Merge pull request #70 from mohit23x/fix/lag-touch-device
2 parents 3ab56ba + 4823f00 commit 8865b18

7 files changed

Lines changed: 52 additions & 41 deletions

File tree

build/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface ActionSheetProps {
1212
zIndex?: number;
1313
closeOnBgTap?: boolean;
1414
bgTransition?: string;
15+
className?: string;
1516
sheetTransition?: string;
1617
reverse?: boolean;
1718
}

build/index.es.js

Lines changed: 16 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/index.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/index.js

Lines changed: 16 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "actionsheet-react",
3-
"version": "1.0.13",
3+
"version": "1.0.14",
44
"description": "🌟A lightweight and flexible action sheet component for the web",
55
"main": "build/index.js",
66
"module": "build/index.es.js",

src/index.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ const ActionSheet = React.forwardRef<
4747
zIndex = 998,
4848
closeOnBgTap = true,
4949
bgTransition = "opacity 0.5s ease-in-out, z-index 0.5s ease-in-out",
50-
className="action-sheet",
51-
sheetTransition = "transform 0.3s ease-in-out",
50+
className = "action-sheet",
51+
sheetTransition = "transform 0.5s linear",
5252
reverse = false,
5353
},
5454
ref
5555
): JSX.Element => {
5656
const [show, setShow] = useState(false);
57-
const [pressed, setPressed] = useState(false);
57+
const pressed = useRef(false);
5858
const sheetRef = useRef<HTMLDivElement>(null);
5959
const animationRef = useRef(0);
6060
const masterOffset = useRef(0);
@@ -76,13 +76,14 @@ const ActionSheet = React.forwardRef<
7676

7777
const requestSheetDown = React.useCallback((): boolean => {
7878
if (null !== sheetRef.current) {
79+
sheetRef.current.style.transition = sheetTransition;
7980
sheetRef.current.style.transform = reverse
8081
? "translate3d(0, -101%, 0)"
8182
: "translate3d(0, 101%, 0)";
8283
return true;
8384
}
8485
return false;
85-
}, [reverse]);
86+
}, [reverse, sheetTransition]);
8687

8788
const requestSheetUp = React.useCallback((): boolean => {
8889
if (null !== sheetRef.current) {
@@ -101,8 +102,7 @@ const ActionSheet = React.forwardRef<
101102
}, [requestSheetDown, requestSheetUp, show]);
102103

103104
const onSwipeMove = (event: React.TouchEvent<HTMLDivElement>): void => {
104-
event.stopPropagation();
105-
if (pressed) {
105+
if (pressed.current) {
106106
const offset = event.touches[0].clientY - startY.current;
107107
move(offset);
108108
}
@@ -112,7 +112,7 @@ const ActionSheet = React.forwardRef<
112112
event: React.MouseEvent<HTMLDivElement, MouseEvent>
113113
): void => {
114114
event.stopPropagation();
115-
if (pressed) {
115+
if (pressed.current) {
116116
if (reverse) {
117117
const offset = event.clientY - startY.current;
118118
move(offset);
@@ -148,24 +148,26 @@ const ActionSheet = React.forwardRef<
148148
};
149149

150150
const onSwipeStart = (event: React.TouchEvent<HTMLDivElement>): void => {
151+
if (sheetRef?.current) sheetRef.current.style.transition = "none";
151152
startY.current = event.touches[0].clientY;
152153
changePressed(true);
153154
};
154155

155156
const onMouseStart = (
156157
event: React.MouseEvent<HTMLDivElement, MouseEvent>
157158
): void => {
159+
if (sheetRef?.current) sheetRef.current.style.transition = "none";
158160
startY.current = event.clientY;
159161
changePressed(true);
160162
};
161163

162164
const changePressed = (x: boolean): void => {
163-
setPressed(x);
165+
pressed.current = x;
164166
};
165167

166168
const onSwipeEnd = (): void => {
167169
cancelAnimationFrame(animationRef.current);
168-
setPressed(false);
170+
changePressed(false);
169171
if (Math.abs(masterOffset.current) > threshold) {
170172
setShow(false);
171173
if (onClose) onClose();
@@ -186,12 +188,12 @@ const ActionSheet = React.forwardRef<
186188
left: 0,
187189
right: 0,
188190
bottom: 0,
189-
background: "rgba(0, 0, 0, 0.8)",
191+
backgroundColor: "rgba(0, 0, 0, 0.8)",
190192
backfaceVisibility: "hidden",
191-
...bgStyle,
192193
transition: bgTransition,
193194
opacity: show ? opacity : 0,
194195
zIndex: show ? zIndex : -1,
196+
...bgStyle,
195197
}}
196198
></div>
197199
<div
@@ -217,9 +219,9 @@ const ActionSheet = React.forwardRef<
217219
backgroundColor: "#fbfbfb",
218220
borderTopLeftRadius: 16,
219221
borderTopRightRadius: 16,
220-
...sheetStyle,
222+
touchAction: "none",
221223
zIndex: zIndex + 1,
222-
transition: pressed ? "transform 0.05s linear" : sheetTransition,
224+
...sheetStyle,
223225
}}
224226
onMouseDown={mouseEnable ? onMouseStart : () => undefined}
225227
onMouseMove={mouseEnable ? onMouseMove : () => undefined}
@@ -228,7 +230,7 @@ const ActionSheet = React.forwardRef<
228230
onTouchMove={touchEnable ? onSwipeMove : () => undefined}
229231
onTouchEnd={touchEnable ? onSwipeEnd : () => undefined}
230232
>
231-
{children ? children : <div style={{ height: 150 }} />}
233+
{children}
232234
</div>
233235
</Fragment>
234236
);

0 commit comments

Comments
 (0)