Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix touch issue when dragging a widget with SVG icon #688

Merged
merged 5 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/appui-layout-react",
"comment": "Fix touch issue when dragging a widget with SVG icon.",
"type": "none"
}
],
"packageName": "@itwin/appui-layout-react"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ import {
Widget,
WidgetState,
} from "@itwin/appui-react";
import {
SvgTextAlignCenter,
SvgTextAlignJustify,
SvgTextAlignLeft,
SvgTextAlignRight,
SvgUser,
SvgUsers,
} from "@itwin/itwinui-icons-react";
import {
getToggleCustomOverlayCommandItemDef,
WidgetApiStage,
Expand Down Expand Up @@ -135,7 +143,7 @@ export class WidgetApiStageUiItemsProvider implements UiItemsProvider {
widgets.push({
id: "WR-A",
label: "WR-A",
icon: "icon-text-align-text-align-left",
icon: <SvgTextAlignLeft />,
canPopout: true,
defaultState: WidgetState.Open,
content: <h2>Right WR-A</h2>,
Expand All @@ -144,7 +152,7 @@ export class WidgetApiStageUiItemsProvider implements UiItemsProvider {
widgets.push({
id: "WR-B",
label: "WR-B",
icon: "icon-text-align-text-align-right",
icon: <SvgTextAlignRight />,
canPopout: true,
defaultState: WidgetState.Hidden,
content: <h2>Right WR-B</h2>,
Expand All @@ -153,14 +161,14 @@ export class WidgetApiStageUiItemsProvider implements UiItemsProvider {
widgets.push({
id: "WR-1",
label: "WR-1",
icon: "icon-text-align-text-align-center",
icon: <SvgTextAlignCenter />,
canPopout: false,
content: <h2>Right WR-1</h2>,
});
widgets.push({
id: "WR-2",
label: "WR-2",
icon: "icon-text-align-text-align-justify",
icon: <SvgTextAlignJustify />,
defaultState: WidgetState.Open,
canPopout: true,
content: <h2>Right WR-2</h2>,
Expand All @@ -169,14 +177,14 @@ export class WidgetApiStageUiItemsProvider implements UiItemsProvider {
widgets.push({
id: "WR-3",
label: "WR-3",
icon: "icon-user",
icon: <SvgUser />,
canPopout: true,
content: <h2>Right WR-3</h2>,
});
widgets.push({
id: "WR-4",
label: "WR-4",
icon: "icon-users",
icon: <SvgUsers />,
canPopout: true,
defaultState: WidgetState.Open,
content: <h2>Right WR-4</h2>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,18 @@ export const usePointerCaptor = <T extends HTMLElement>(
isDown.current && dragManager.handleDragEnd();
isDown.current = false;
touchTarget = null;
if (e.target instanceof HTMLElement) {
e.target.removeEventListener("touchmove", targetTouchMove);
e.target.removeEventListener("touchend", touchEnd);
if (e.target instanceof Element) {
e.target.removeEventListener(
"touchmove",
targetTouchMove as EventListener
);
e.target.removeEventListener("touchend", touchEnd as EventListener);
}
document.removeEventListener("touchmove", documentTouchMove);
document.removeEventListener("touchend", documentTouchEnd);
};
const documentTouchEnd = (e: TouchEvent) => {
// Do not handle document touch move if it was handled by target handler.
// Do not handle document touch end if it was handled by target handler.
if (touchTarget === e.target) return;
touchEnd(e);
};
Expand All @@ -92,11 +95,15 @@ export const usePointerCaptor = <T extends HTMLElement>(
if (e.touches.length !== 1) return;
touchTarget = e.target;
// In case of implicit pointer capture attach to event target.
if (e.target instanceof HTMLElement) {
e.target.addEventListener("touchmove", targetTouchMove);
e.target.addEventListener("touchend", touchEnd);
if (e.target instanceof Element) {
e.target.addEventListener(
"touchmove",
targetTouchMove as EventListener
);
e.target.addEventListener("touchend", touchEnd as EventListener);
}
// Add to document in case the target looses capture (i.e. is removed)

// Add to document in case the target loses capture (i.e. is removed)
document.addEventListener("touchmove", documentTouchMove);
document.addEventListener("touchend", documentTouchEnd);
onPointerDown && onPointerDown(e.touches[0], e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ export function NineZoneStateReducer(
});
}
case "WIDGET_TAB_DRAG_START": {
assert(!state.draggedTab);
const tabId = action.id;
let home: PanelWidgetRestoreState;
if (action.floatingWidgetId) {
Expand Down
Loading