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

Touch events not supported? #1001

Closed
hguillermo opened this issue Apr 5, 2017 · 28 comments
Closed

Touch events not supported? #1001

hguillermo opened this issue Apr 5, 2017 · 28 comments

Comments

@hguillermo
Copy link
Contributor

hguillermo commented Apr 5, 2017

I am migrating a code like this from a React codebase:

<div
className="discover-slider"
onTouchStart={this.onTouchStart}
onTouchMove={this.onTouchMove}
onTouchEnd={this.onTouchEnd}
>
...
</div>

Those events are working on React but they are not being fired in Inferno. Am I doing something wrong? I think it is just not supported right now. Ideas?

Thanks a lot for all your support guys!

@Havunen
Copy link
Member

Havunen commented Apr 5, 2017

We use them and they are working just fine... Is this again old version of JSX plugin issue? Make sure you have v3+. Edit: I misread, thought it was about onMouseMove need to test this.

@deamme
Copy link
Member

deamme commented Apr 5, 2017

@hguillermo
Copy link
Contributor Author

@deamme you are right. @Havunen Can we add these touch events? Thanks

@hguillermo hguillermo reopened this Apr 5, 2017
@trueadm
Copy link
Member

trueadm commented Apr 5, 2017

These have worked in the past, just not via the synthetic event system. Can you try with the event name being all lowercase?

@deamme
Copy link
Member

deamme commented Apr 5, 2017

@trueadm Are non synthetic events created by setting the name to lowercase?

@trueadm
Copy link
Member

trueadm commented Apr 5, 2017

@deamme all lowercase events use the native event system and bypass Inferno's system entirely.

@hguillermo
Copy link
Contributor Author

@trueadm Oh. Let me test. I will keep you posted.

@hguillermo
Copy link
Contributor Author

@trueadm I updated the event names to lowercase but they are not being rendered. Somehow Inferno is removing it? This is what I did:

<div
className="discover-slider"
ontouchstart={this.onTouchStart}
ontouchmove={this.onTouchMove}
ontouchend={this.onTouchEnd}
>
...
</div>

Based on what you are saying this should work. Not sure what is going on here.

@trueadm
Copy link
Member

trueadm commented Apr 5, 2017

@hguillermo Can you show what the compiled JSX code looks like? I have a feeling you might be using an old version of the JSX plugin for Inferno.

@hguillermo
Copy link
Contributor Author

hguillermo commented Apr 5, 2017

@trueadm I am using "babel-plugin-inferno": "^3.1.0" and I just updated inferno to 1.6.1 but I am getting this error now: Inferno Error: cannot update state via setState() in componentWillUpdate() or constructor.. But I am not setting the state in the constructor or componentWillUpdate. After I fix that problem I will check again. Thanks for your help!

@hguillermo
Copy link
Contributor Author

@trueadm Inferno is removing those events. I tested using "babel-plugin-inferno": "^3.1.0" and "inferno": "1.5.6".

Input

<div
className="discover-slider"
ontouchstart={this.onTouchStart}
ontouchmove={this.onTouchMove}
ontouchend={this.onTouchEnd}
aaaa={'aaaaaaaa'}
bbbb={'bbbbbbbb'}
>

Output

<div class="discover-slider" aaaa="aaaaaaaa" bbbb="bbbbbbbb">
...
</div>

cc @deamme

@trueadm
Copy link
Member

trueadm commented Apr 5, 2017

Are you looking at the rendered HTML lookup? Events won't appear there, as they're added as properties to th DOM Node, rather than as attributes. You'll need to access the nodes property to find these.

@hguillermo
Copy link
Contributor Author

oh I see. I can see those events now. They are not being fired but maybe that is an error in my code. I will debug and keep you posted. Thanks!

@hguillermo
Copy link
Contributor Author

@trueadm I fixed it doing this:

<div
className="discover-slider"
ontouchstart={(e) => this.onTouchStart(e)}
ontouchmove={(e) => this.onTouchMove(e)}
ontouchend={(e) => this.onTouchEnd(e)}
>

From the React original code:

<div
className="discover-slider"
onTouchStart={this.onTouchStart}
onTouchMove={this.onTouchMove}
onTouchEnd={this.onTouchEnd}
>

Thanks for all your help.

@hguillermo
Copy link
Contributor Author

I am going to close this issue. Not an inferno error. Thanks again for all your help.

@trueadm
Copy link
Member

trueadm commented Apr 5, 2017

@hguillermo you can use camelCase too, like React – well you should be. It sounds like the issue was the fact your events weren't bound the the class. Were you using createClass before in React by any chance?

@hguillermo
Copy link
Contributor Author

@trueadm From the react code: export default class Slider extends React.Component {

and of course in React I have this in the constructor:

this.onTouchStart = this.onTouchStart.bind(this);
this.onTouchMove = this.onTouchMove.bind(this);
this.onTouchEnd = this.onTouchEnd.bind(this);

I try that in inferno but it didn't work. I am going to try again. Maybe after many tries and errors I got confused or so.

@Havunen
Copy link
Member

Havunen commented Apr 10, 2017

New version 3.0.2 released. Closing

@Havunen Havunen closed this as completed Apr 10, 2017
@koellcode
Copy link

Hi there! Have the same problem here. We are using "nuka-carousel": "^2.0.4" and migrated from preact to infernojs recently. The problem is even there with "inferno": "^3.3.1" respectivly "inferno-compat": "^3.3.1". The mouse events seems to work, but on mobile devices the touchevents are not even registered. Is that maybe a regression or smth? or more like an inferno-compat issue?

@koellcode
Copy link

To verify, I swapped inferno-compat with preact-compat. And the touch events are properly registred in the EventListener section -.- (and working fine). Did I miss something that InfernoJS is not supported on Touch Devices? 🤔

@Havunen
Copy link
Member

Havunen commented Jun 6, 2017

@koellcode Can you track down the issue you are having? PR would be nice :)
Also touch events should work, but I have not used them with inferno-compat

@koellcode
Copy link

koellcode commented Jun 7, 2017

@Havunen I've tried to write a failing test for it. Sadly came not that far ... will try to make a gist with inferno starter after work today

@tomlagier
Copy link

Having the same issue - touch events are not showing up as bound. Using inferno/inferno-component: ^3.9.0 and babel-plugin-inferno: ^3.2.0. Have tried with both camel and lowercased variants and I cannot get the bindings to show up.

@Havunen
Copy link
Member

Havunen commented Sep 13, 2017

@tomlagier can you create jsFiddle to reproduce the issue please. https://jsfiddle.net/wt5vL603/

@tomlagier
Copy link

Sure: https://jsfiddle.net/97w3ounh/1/

Note that the div with all the touch handlers doesn't get any listeners bound.

@Havunen
Copy link
Member

Havunen commented Nov 23, 2017

Seems like touch events were missing in synthetic event list... I added them there now... This is fixed in development and will be available in v4 (next weekend). From then on you don't need to use ontouchstart syntax, and its also preferred to use onTouchStart because then there will be only 1 listener bound to DOM.

@Havunen Havunen closed this as completed Nov 23, 2017
@sprlwrksAprilmintacpineda

@Havunen onTouchStart is still not on the docs?

@sprlwrksAprilmintacpineda

it's also good if we can add onSwipe event that will allow us to detect swipe directions (left, right, top, bottom).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

7 participants