Skip to content

Commit

Permalink
fix: joystick in 'dynamic' mode gets stuck on iOS
Browse files Browse the repository at this point in the history
fix #94
  • Loading branch information
iodev authored and yoannmoinet committed May 8, 2019
1 parent 8484d00 commit 94bb784
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ Three modes are possible :
- new joystick is created at each new touch farther than `options.catchDistance` of any previously created joystick.
- the joystick is faded-out when released but not destroyed.
- when touch is made **inside** the `options.catchDistance` a new direction is triggered immediately.
- when touch is made **oustide** the `options.catchDistance` the previous joystick is destroyed and a new one is created.
- when touch is made **outside** the `options.catchDistance` the previous joystick is destroyed and a new one is created.
- **cannot** be multitouch.

#### `'static'`
- a joystick is positionned immediately at `options.position`.
- a joystick is positioned immediately at `options.position`.
- one joystick per zone.
- each new touch triggers a new direction.
- **cannot** be multitouch.
Expand Down Expand Up @@ -289,7 +289,7 @@ Your manager has the following signature :

#### `manager.on(type, handler)`

If you whish to listen to internal events like :
If you wish to listen to internal events like :

```javascript
manager.on('event#1 event#2', function (evt, data) {
Expand Down
17 changes: 17 additions & 0 deletions src/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ Collection.prototype.pressureFn = function (touch, nipple, identifier) {
Collection.prototype.onstart = function (evt) {
var self = this;
var opts = self.options;
var origEvt = evt;
evt = u.prepareEvent(evt);

// Update the box position
Expand All @@ -239,6 +240,22 @@ Collection.prototype.onstart = function (evt) {
if (self.actives.length < opts.maxNumberOfNipples) {
self.processOnStart(touch);
}
else if(origEvt.type.match(/^touch/)){
// zombies occur when end event is not received on Safari
// first touch removed before second touch, we need to catch up...
// so remove where touches in manager that no longer exist
Object.keys(self.manager.ids).forEach(function(k){
if(Object.values(origEvt.touches).findIndex(function(t){return t.identifier===k;}) < 0){
// manager has id that doesn't exist in touches
var e = [evt[0]];
e.identifier = k;
self.processOnEnd(e);
}
});
if(self.actives.length < opts.maxNumberOfNipples){
self.processOnStart(touch);
}
}
};

u.map(evt, process);
Expand Down

0 comments on commit 94bb784

Please sign in to comment.