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

fix: isPressed will return value expectedly on iOS13 #123

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ var options = {
restOpacity: Number, // opacity when not 'dynamic' and rested
lockX: Boolean, // only move on the X axis
lockY: Boolean, // only move on the Y axis
catchDistance: Number // distance to recycle previous joystick in
catchDistance: Number, // distance to recycle previous joystick in
// 'semi' mode
dynamicPage: Boolean, // Enable if the page has dynamically visible elements
};
```

Expand All @@ -155,7 +156,7 @@ The dom element in which all your joysticks will be injected.
<script type="text/javascript" src="./nipplejs.js"></script>
<script type="text/javascript">
var options = {
zone: document.getElementById('zone_joystick');
zone: document.getElementById('zone_joystick'),
};
var manager = nipplejs.create(options);
</script>
Expand Down Expand Up @@ -252,6 +253,8 @@ Locks joystick's movement to the x (horizontal) axis
### `options.lockY` defaults to false
Locks joystick's movement to the y (vertical) axis

### `options.dynamicPage` defaults to true
Enable if the page has dynamically visible elements such as for Vue, React, Angular or simply some CSS hiding or showing some DOM.

----

Expand Down Expand Up @@ -526,6 +529,10 @@ Comes with data :
radian: 1.5707963268, // angle in radian
degree: 90
},
vector: { // force unit vector
x: 0.508,
y: 3.110602869834277e-17
},
raw: { // note: angle is the same, beyond the 50 pixel limit
distance: 25.4, // distance which continues beyond the 50 pixel limit
position: { // position of the finger/mouse in pixels, beyond joystick limits
Expand Down
16 changes: 15 additions & 1 deletion src/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ function Collection (manager, options) {
restJoystick: true,
restOpacity: 0.5,
lockX: false,
lockY: false
lockY: false,
dynamicPage: false
};

self.config(options);
Expand Down Expand Up @@ -377,6 +378,15 @@ Collection.prototype.processOnMove = function (evt) {
return;
}

if (opts.dynamicPage) {
var scroll = u.getScroll();
pos = nipple.el.getBoundingClientRect();
nipple.position = {
x: scroll.x + pos.left,
y: scroll.y + pos.top
};
}

nipple.identifier = identifier;

var size = nipple.options.size / 2;
Expand Down Expand Up @@ -432,6 +442,10 @@ Collection.prototype.processOnMove = function (evt) {
radian: rAngle,
degree: angle
},
vector: {
x: xPosition / size,
y: - yPosition / size
},
raw: raw,
instance: nipple,
lockX: opts.lockX,
Expand Down
3 changes: 3 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const degrees = (a) => {
};

export const isPressed = (evt) => {
if (evt.type === 'pointerdown' || evt.type === 'pointermove') {
Copy link
Owner

@yoannmoinet yoannmoinet Oct 3, 2019

Choose a reason for hiding this comment

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

Is it possible to have a evt.type === 'pointerdown' here? I don't see it.

Also, following that logic, maybe it will be the same for touchstart and touchmove?

Copy link
Author

Choose a reason for hiding this comment

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

Sorry for late reply. When I tested with iPhone 11, I have confirmed 'pointerdown' event through here.
However, I think this is not fundamental solution, is just workaround.
So could I close this PR?

Copy link
Owner

Choose a reason for hiding this comment

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

don't close it, I think this is a good solution.
I'll take over if you don't have time for this, no worries.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I got it.
I don't have enough time for debugging this now.

I'm working on some game project with nipplejs, and I got another bug with iOS 13 on iPhone SE: Sometimes joypad will not be destroyed, remains show up without disappearing even if I lift up my finger.

So I fork this, and I'm using this branch code.
umeruma@3be8638

return true;
}
if (isNaN(evt.buttons)) {
return evt.pressure !== 0;
}
Expand Down
4 changes: 4 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ export interface JoystickOutputData {
x: string;
y: string;
};
vector: {
x: number;
y: number;
};
raw: {
distance: number;
position: Position;
Expand Down