-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Adding movementX and movementY to synthenticMouseEvent fixes #6723 #9018
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ | |
import SyntheticUIEvent from './SyntheticUIEvent'; | ||
import getEventModifierState from './getEventModifierState'; | ||
|
||
let previousScreenX = null; | ||
let previousScreenY = null; | ||
|
||
/** | ||
* @interface MouseEvent | ||
* @see http://www.w3.org/TR/DOM-Level-3-Events/ | ||
|
@@ -34,6 +37,24 @@ const SyntheticMouseEvent = SyntheticUIEvent.extend({ | |
: event.fromElement) | ||
); | ||
}, | ||
movementX: function(event) { | ||
if ('movementX' in event) { | ||
return event.movementX; | ||
} | ||
|
||
const screenX = previousScreenX; | ||
previousScreenX = event.ScreenX; | ||
return screenX ? event.screenX - screenX : 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the check here intends to check against There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's equal to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that if saved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe Dan is right, and we need to correct this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/tc39/proposal-nullish-coalescing would have helped a lot with this, yes we should check if equal to null There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another thing is that using the same variable for both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, are we happy to assume screenX on event? If undefined we could end up with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok so if screenX will always be an Number, could we not just initiate previousScreenX as 0 Instead of null, and then instead of a ternary or null checking, always perform the minus operation. Because we can guarantee both operands will be Numbers by this point . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't make the first |
||
}, | ||
movementY: function(event) { | ||
if ('movementY' in event) { | ||
return event.movementY; | ||
} | ||
|
||
const screenY = previousScreenY; | ||
previousScreenY = event.screenY; | ||
return screenY ? event.screenY - screenY : 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. |
||
}, | ||
}); | ||
|
||
export default SyntheticMouseEvent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
event.screenX
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, yes it should