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

[Web] Stylus support #3107

Merged
merged 19 commits into from
Sep 19, 2024
Merged

[Web] Stylus support #3107

merged 19 commits into from
Sep 19, 2024

Conversation

m-bert
Copy link
Contributor

@m-bert m-bert commented Sep 17, 2024

Description

This PR adds more information about stylus to event. Pan and Hover events now have stylusData field, which contains the following information:

  • tiltX
  • tiltY
  • altitudeAngle
  • azimuthAngle
  • pressure

Important

Because we receive only one set of data (either tiltX/tiltY or altitudeAngle/azimuthAngle, we use this conversion algorithm to calculate second set.

Note

This PR adds stylusData only on web, native platforms will be handled in another PRs

Test plan

Tested on newly added example.

@m-bert m-bert marked this pull request as ready for review September 17, 2024 14:22
@m-bert m-bert requested review from latekvo and j-piasecki and removed request for latekvo September 17, 2024 14:24
Copy link
Contributor

@latekvo latekvo left a comment

Choose a reason for hiding this comment

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

All good 👍

@m-bert m-bert mentioned this pull request Sep 18, 2024
Comment on lines 85 to 87
// Stylus triggers `pointermove` event when it detects changes in pressure. Since it is very sensitive to those changes,
// it constantly sends events, even though there was no change in position. To fix that we check whether
// pointer has actually moved and if not, we do not send event.
Copy link
Member

Choose a reason for hiding this comment

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

Not true anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Removed in f98b911

src/web/utils.ts Outdated
// or that none of the position sets is supported. In that case, we can treat stylus as perpendicular
//
// @ts-ignore This property exists (https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent#instance_properties)
if (event.azimuthAngle === undefined || event.altitudeAngle === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

You can extract those to variables instead of @ts-ignoring multiple times

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Done in 9fa4003

src/web/utils.ts Outdated Show resolved Hide resolved
@m-bert m-bert merged commit b79223d into main Sep 19, 2024
3 checks passed
@m-bert m-bert deleted the @mbert/stylus-support-web branch September 19, 2024 09:50
@m-bert m-bert mentioned this pull request Sep 19, 2024
m-bert added a commit that referenced this pull request Sep 24, 2024
## Description

This PR adds stylus support on Android.

>[!NOTE]
> You can read more about this feature in #3107

## Test plan

Tested on **_StylusData_** example
m-bert added a commit that referenced this pull request Sep 24, 2024
## Description

This PR adds stylus support on `iOS`.

>[!WARNING]
> This PR lacks support for `Hover` since currently we are unable to test that.

>[!NOTE]
> You can read more about this feature in #3107

## Test plan

Tested on **_StylusData_** example
@m-bert m-bert mentioned this pull request Oct 8, 2024
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.

3 participants