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

Always fire mouseup on element that had mousedown #850

Merged
merged 1 commit into from
Aug 12, 2019
Merged
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
32 changes: 24 additions & 8 deletions modern/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ function handleMouseEventDispatch(node, event, eventName) {
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
node.js_trigger(eventName, x, y);

if (event.nativeEvent.type === "mousedown") {
// We need to persist the react event so we can access the target
event.persist();
document.addEventListener("mouseup", function globalMouseUp(ev) {
document.removeEventListener("mouseup", globalMouseUp);
// Create an object that looks and acts like an event, but has mixed
// properties from original mousedown event and new mouseup event
const fakeEvent = {
target: event.target,
clientX: ev.clientX,
clientY: ev.clientY,
nativeEvent: {
type: "mouseup",
},
stopPropagation: ev.stopPropagation.bind(ev),
};
handleMouseEventDispatch(
node,
fakeEvent,
eventName === "onLeftButtonDown" ? "onLeftButtonUp" : "onRightButtonUp"
);
});
}
}

function handleMouseButtonEventDispatch(
Expand All @@ -53,14 +77,6 @@ function GuiObjectEvents({ node, children }) {
"onRightButtonDown"
)
}
onMouseUp={e =>
handleMouseButtonEventDispatch(
node,
e,
"onLeftButtonUp",
"onRightButtonUp"
)
}
onDoubleClick={e =>
handleMouseButtonEventDispatch(
node,
Expand Down