Skip to content

Commit 8593b5a

Browse files
authored
fix(plugin-basic-ui,react-ui-core): prevent touch events while transitioning (#584)
1 parent 91413b6 commit 8593b5a

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
lines changed

.changeset/metal-pandas-dance.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@stackflow/plugin-basic-ui": patch
3+
"@stackflow/react-ui-core": patch
4+
---
5+
6+
fix(plugin-basic-ui,react-ui-core): prevent touch events while transitioning

extensions/plugin-basic-ui/src/basicUIPlugin.css.ts

-9
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,5 @@ export const stackWrapper = recipe({
115115
android,
116116
cupertino,
117117
},
118-
globalTransitionState: {
119-
idle: {},
120-
loading: {
121-
pointerEvents: "none",
122-
},
123-
paused: {
124-
pointerEvents: "none",
125-
},
126-
},
127118
},
128119
});

extensions/plugin-basic-ui/src/basicUIPlugin.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export const basicUIPlugin: (
6161
className={compact([
6262
css.stackWrapper({
6363
theme: initialContext?.theme ?? _options.theme,
64-
globalTransitionState: stack.globalTransitionState,
6564
}),
6665
_options.rootClassName,
6766
]).join(" ")}

extensions/plugin-basic-ui/src/components/AppScreen.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { useActions } from "@stackflow/react";
1+
import { useActions, useStack } from "@stackflow/react";
22
import {
33
useActivityDataAttributes,
44
useLazy,
55
useMounted,
66
useNullableActivity,
7+
usePreventTouchDuringTransition,
78
useStyleEffectHide,
89
useStyleEffectOffset,
910
useStyleEffectSwipeBack,
@@ -194,6 +195,10 @@ const AppScreen: React.FC<AppScreenProps> = ({
194195
}
195196
};
196197

198+
usePreventTouchDuringTransition({
199+
appScreenRef,
200+
});
201+
197202
return (
198203
<Context.Provider
199204
value={useMemo(

extensions/react-ui-core/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from "./useStyleEffectOffset";
88
export * from "./useStyleEffectSwipeBack";
99
export * from "./useZIndexBase";
1010
export * from "./useActivityDataAttributes";
11+
export * from "./usePreventTouchDuringTransition";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useStack } from "@stackflow/react";
2+
import { useEffect } from "react";
3+
4+
export function usePreventTouchDuringTransition({
5+
appScreenRef,
6+
}: {
7+
appScreenRef: React.RefObject<HTMLDivElement>;
8+
}) {
9+
const { globalTransitionState } = useStack();
10+
11+
useEffect(() => {
12+
const $appScreen = appScreenRef.current;
13+
if (!$appScreen || globalTransitionState === "idle") {
14+
return;
15+
}
16+
17+
const onTouchStart = (e: TouchEvent) => {
18+
e.preventDefault();
19+
};
20+
21+
$appScreen.addEventListener("touchstart", onTouchStart);
22+
23+
return () => {
24+
$appScreen.removeEventListener("touchstart", onTouchStart);
25+
};
26+
}, [globalTransitionState]);
27+
}

0 commit comments

Comments
 (0)