Skip to content
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
7 changes: 7 additions & 0 deletions .changeset/dry-insects-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@tapsioss/react-client-socket-manager": patch
"@tapsioss/client-socket-manager": patch
---

Improve devtool expecience in mobile devices.

10 changes: 8 additions & 2 deletions packages/core/src/devtool/devtool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const renderChipGroup = (items: string[]) => {
overflow: "hidden",
"white-space": "nowrap",
"text-overflow": "ellipsis",
"overscroll-behavior-y": "contain",
});

const chipGroupStyle = generateInlineStyle({
Expand Down Expand Up @@ -165,6 +166,7 @@ export const renderLogs = () => {
style: generateInlineStyle({
"max-height": "20rem",
overflow: "scroll",
"overscroll-behavior-y": "contain",
}),
});

Expand Down Expand Up @@ -287,9 +289,13 @@ const init = () => {
devtoolWrapper.innerHTML = renderDevtool();

document.body.appendChild(devtoolWrapper);
makeElementDraggable(devtoolWrapper);

getDevtoolIconElement()?.addEventListener("click", toggle);
const iconButton = getDevtoolIconElement();

if (iconButton) {
iconButton.addEventListener("click", toggle);
makeElementDraggable(iconButton, devtoolWrapper);
}

[DEVTOOL_CLOSE_ICON_ID, DEVTOOL_SOCKET_ICON_ID].forEach(icon => {
const buttonIcon = document.getElementById(icon);
Expand Down
16 changes: 10 additions & 6 deletions packages/core/src/devtool/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ export const generateAttributes = (
* - The element must be absolutely or fixed-positioned, and should not be constrained by layout flow
* - Internally sets `element.style.touchAction = 'none'` to disable browser-native touch gestures
*
* @param element - The HTMLElement to make draggable
* @param dragHandle - The drag handle.
* @param dragTarget - The HTMLElement that will move when dragging with the handler.
*/
export const makeElementDraggable = (element: HTMLElement) => {
export const makeElementDraggable = (
dragHandle: HTMLElement,
dragTarget: HTMLElement,
) => {
// Extract clientX from MouseEvent or TouchEvent
const getClientX = (event: MouseEvent | TouchEvent) => {
if (event instanceof MouseEvent) return event.clientX;
Expand Down Expand Up @@ -112,7 +116,7 @@ export const makeElementDraggable = (element: HTMLElement) => {
x = initialX + deltaX;
y = initialY + deltaY;

element.style.transform = `translate(${x}px, ${y}px)`;
dragTarget.style.transform = `translate(${x}px, ${y}px)`;
}
};

Expand All @@ -125,10 +129,10 @@ export const makeElementDraggable = (element: HTMLElement) => {
};

// Disable browser-native touch gestures (scroll, nav swipe)
element.style.touchAction = "none";
dragHandle.style.touchAction = "none";

element.addEventListener("touchstart", handleDragStart, false);
element.addEventListener("mousedown", handleDragStart, false);
dragHandle.addEventListener("touchstart", handleDragStart, false);
dragHandle.addEventListener("mousedown", handleDragStart, false);

document.addEventListener("mousemove", handleDragging, false);
document.addEventListener("touchmove", handleDragging, false);
Expand Down