Skip to content

Standalone client mobile support#41

Open
sll-io wants to merge 21 commits intomainfrom
Standalone-client-mobile-support
Open

Standalone client mobile support#41
sll-io wants to merge 21 commits intomainfrom
Standalone-client-mobile-support

Conversation

@sll-io
Copy link
Contributor

@sll-io sll-io commented Jun 26, 2023

Resolves #53

  • Added support for zoom (pinch in and out)
  • Added support for pan (drag left and right)

What kind of changes does your PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Refactor
  • Tests
  • Other, please describe:

Does your PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe its impact and migration path for existing applications:

Does your PR fulfill the following requirements?

  • [z ] All tests are passing
  • The title references the corresponding issue # (if relevant)


let touchX: number;
let touchY: number;
let touchTimestamp: number;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be class properties rather than global as they are now.

private handleTouchEnd(event: TouchEvent) {
if (Date.now() - touchTimestamp < touchThresholdMilliseconds) {
/* a short touch, i.e., a click */
if ((event.detail as any).element) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is redundant here and also in the source it was copied from (handleClick). It can be removed from there too. It was originally a catch for when this class was an element itself, which is no longer the case.

}
let x = 0;
let y = 0;
if (!document.pointerLockElement) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a touch handler then it seems to follow that we should always be using the position of the touch rather than check if there was a pointerLockElement.

It's plausible that a device with both mouse and touchscreen could be using pointer lock controls and then have the user touch the screen to "click" something, but in that instance I'd expect the touch location to still be used.

x = (offsetX / width) * 2 - 1;
y = -((offsetY / height) * 2 - 1);
}
this.raycaster.setFromCamera(new THREE.Vector2(x, y), this.scene.getCamera());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From this point in this method this is duplicated from handleClick. It's likely best to extract this into a private method to avoid them diverging unintentionally.

private handleTouchStart(event: TouchEvent) {
/* remember the x and y position of the touch, so that it can be used in touchEnd */
touchX = event.touches[0].clientX;
touchY = event.touches[0].clientY;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the first-available touch to track position here (rather than using the position of the touch that has ended in touchEnd) has an unintentional side-effect.

If you hold a finger (A) on the screen, and then tap with a second finger (B), you will be "clicking" at point A rather than B which is where the actual tapping is happening.

if (Date.now() - this.clickTimestamp < this.clickThresholdMilliseconds) {
/* this is a click */
// Create and dispatch a new mouse event with specific x and y coordinates
const clickEvent = new MouseEvent("click", {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems extraneous now as the MMLClickTrigger handles clicks without this logic.

@MarcusLongmuir MarcusLongmuir force-pushed the Standalone-client-mobile-support branch from ce40b9f to 7329c6f Compare October 10, 2023 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standalone MML Client Mobile Support

2 participants