Longpress event triggers tap event
up vote
0
down vote
favorite
In a list view I have two events happening, a tap event, and a longpress event, but longpress fires both.
Inside the .html file:
<ListView class="listViewContainer" [items]="contactList">
<ng-template let-item="item" let-i="index">
<StackLayout
(loaded)="loaded($event)"
orientation="horizontal"
class="preview-info-container"
>
</StackLayout>
</ng-template>
</ListView>
And then the .ts file
loaded(args)
const element = args.object;
element.on("loaded, tap, longPress", (args) =>
// console.log("Event: " + args.eventName + ", sender: " + args.object);
if(args.eventName === "tap")
this.router.navigate(["card/contact/" + this.contact.id]);
else
this.togglePreviewOptions = !this.togglePreviewOptions;
);
My question is, how can I prevent the tap event from being fired when long pressing on the specific field?
This might be duplicate issue of NativeScript tap & longPress together not working, however since there has not been a clear answer I would like to raise it again.
Edit
Some more info:
The project tns version is
$ tns --version 4.3.0-2018-08-31-12160
Global nativescript version
nativescript@4.3.0-2018-08-31-12160
Emulator version:
Iphone 6, iOS 11.3
angular events nativescript
add a comment |
up vote
0
down vote
favorite
In a list view I have two events happening, a tap event, and a longpress event, but longpress fires both.
Inside the .html file:
<ListView class="listViewContainer" [items]="contactList">
<ng-template let-item="item" let-i="index">
<StackLayout
(loaded)="loaded($event)"
orientation="horizontal"
class="preview-info-container"
>
</StackLayout>
</ng-template>
</ListView>
And then the .ts file
loaded(args)
const element = args.object;
element.on("loaded, tap, longPress", (args) =>
// console.log("Event: " + args.eventName + ", sender: " + args.object);
if(args.eventName === "tap")
this.router.navigate(["card/contact/" + this.contact.id]);
else
this.togglePreviewOptions = !this.togglePreviewOptions;
);
My question is, how can I prevent the tap event from being fired when long pressing on the specific field?
This might be duplicate issue of NativeScript tap & longPress together not working, however since there has not been a clear answer I would like to raise it again.
Edit
Some more info:
The project tns version is
$ tns --version 4.3.0-2018-08-31-12160
Global nativescript version
nativescript@4.3.0-2018-08-31-12160
Emulator version:
Iphone 6, iOS 11.3
angular events nativescript
Elaborate your question.
– Sunil Singh
Nov 11 at 12:02
I have edited with a more specific question.
– GeorgeK
Nov 11 at 12:10
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
In a list view I have two events happening, a tap event, and a longpress event, but longpress fires both.
Inside the .html file:
<ListView class="listViewContainer" [items]="contactList">
<ng-template let-item="item" let-i="index">
<StackLayout
(loaded)="loaded($event)"
orientation="horizontal"
class="preview-info-container"
>
</StackLayout>
</ng-template>
</ListView>
And then the .ts file
loaded(args)
const element = args.object;
element.on("loaded, tap, longPress", (args) =>
// console.log("Event: " + args.eventName + ", sender: " + args.object);
if(args.eventName === "tap")
this.router.navigate(["card/contact/" + this.contact.id]);
else
this.togglePreviewOptions = !this.togglePreviewOptions;
);
My question is, how can I prevent the tap event from being fired when long pressing on the specific field?
This might be duplicate issue of NativeScript tap & longPress together not working, however since there has not been a clear answer I would like to raise it again.
Edit
Some more info:
The project tns version is
$ tns --version 4.3.0-2018-08-31-12160
Global nativescript version
nativescript@4.3.0-2018-08-31-12160
Emulator version:
Iphone 6, iOS 11.3
angular events nativescript
In a list view I have two events happening, a tap event, and a longpress event, but longpress fires both.
Inside the .html file:
<ListView class="listViewContainer" [items]="contactList">
<ng-template let-item="item" let-i="index">
<StackLayout
(loaded)="loaded($event)"
orientation="horizontal"
class="preview-info-container"
>
</StackLayout>
</ng-template>
</ListView>
And then the .ts file
loaded(args)
const element = args.object;
element.on("loaded, tap, longPress", (args) =>
// console.log("Event: " + args.eventName + ", sender: " + args.object);
if(args.eventName === "tap")
this.router.navigate(["card/contact/" + this.contact.id]);
else
this.togglePreviewOptions = !this.togglePreviewOptions;
);
My question is, how can I prevent the tap event from being fired when long pressing on the specific field?
This might be duplicate issue of NativeScript tap & longPress together not working, however since there has not been a clear answer I would like to raise it again.
Edit
Some more info:
The project tns version is
$ tns --version 4.3.0-2018-08-31-12160
Global nativescript version
nativescript@4.3.0-2018-08-31-12160
Emulator version:
Iphone 6, iOS 11.3
angular events nativescript
angular events nativescript
edited Nov 11 at 13:44
asked Nov 11 at 11:53
GeorgeK
548
548
Elaborate your question.
– Sunil Singh
Nov 11 at 12:02
I have edited with a more specific question.
– GeorgeK
Nov 11 at 12:10
add a comment |
Elaborate your question.
– Sunil Singh
Nov 11 at 12:02
I have edited with a more specific question.
– GeorgeK
Nov 11 at 12:10
Elaborate your question.
– Sunil Singh
Nov 11 at 12:02
Elaborate your question.
– Sunil Singh
Nov 11 at 12:02
I have edited with a more specific question.
– GeorgeK
Nov 11 at 12:10
I have edited with a more specific question.
– GeorgeK
Nov 11 at 12:10
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
It would be much easier for you to define 2 events in your template code:
<ListView class="listViewContainer" [items]="contactList">
<ng-template let-item="item" let-i="index">
<StackLayout
(loaded)="loaded($event)"
(tap)="functionWhenTap(item)"
(longPress)="functionWhenLongPress(item)"
orientation="horizontal"
class="preview-info-container"
>
</StackLayout>
</ng-template>
</ListView>
and then, handle it in your .ts
file with these:
functionWhenTap(item: any)
// your things to do when tapped
functionWhenLongPress(item: any)
// your things to do when long pressed
This is an actual piece of code. Should work for you as well.
Here's working example, tested on my physical personal device:
https://play.nativescript.org/?template=play-ng&id=XgBfFE
Thanks for your comment! I have tried this way, but i cannot prevent the tap event from being triggered at the end of the long press, thus when i console log i get two"longpressed" events, and then "tapped"
– GeorgeK
Nov 11 at 12:59
Well, that's interesting. Have you tried clearing your env. A little bit? Like, quit your emulator, removenode_modules
,hooks
andplatforms
, thennpm i
andtns platform add ios/android
? Maybe something is cached. Maybe sometns build android/ios --clear
? Start with these and we'll see.
– ogrodowiczp
Nov 11 at 13:03
And why the heck there are 2x long presses and 1x tap? Hmm.
– ogrodowiczp
Nov 11 at 13:05
Removed node_modules, hooks, and platform, and still getting exactly the same issue. Longpress is fired twice in the beginning and then tap is fired once.
– GeorgeK
Nov 11 at 13:21
1
Have you tried defining tap event one level higher - on ListView instead of it's child? I believe there's something like(itemTapped)
if I recall well
– ogrodowiczp
Nov 11 at 13:52
|
show 8 more comments
up vote
0
down vote
I have not been able to solve this issue by adding two different events (tap/longPress).
As a solution i use the following
Inside .html
<StackLayout (touch)="onTouch($event)">
<Contact-Preview [contact]=contactList[i]></Contact-Preview>
</StackLayout>
Inside .ts
onTouch(args: TouchGestureEventData)
if(args.action === "down")
this.start = new Date().getMilliseconds();
if(args.action === "up")
this.end = new Date().getMilliseconds();
const duration = Math.abs(this.start - this.end)
console.log(duration > 150? "long press": "tap")
This prevents tap and longPress events being fired on the same time, thus working around my issue.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
It would be much easier for you to define 2 events in your template code:
<ListView class="listViewContainer" [items]="contactList">
<ng-template let-item="item" let-i="index">
<StackLayout
(loaded)="loaded($event)"
(tap)="functionWhenTap(item)"
(longPress)="functionWhenLongPress(item)"
orientation="horizontal"
class="preview-info-container"
>
</StackLayout>
</ng-template>
</ListView>
and then, handle it in your .ts
file with these:
functionWhenTap(item: any)
// your things to do when tapped
functionWhenLongPress(item: any)
// your things to do when long pressed
This is an actual piece of code. Should work for you as well.
Here's working example, tested on my physical personal device:
https://play.nativescript.org/?template=play-ng&id=XgBfFE
Thanks for your comment! I have tried this way, but i cannot prevent the tap event from being triggered at the end of the long press, thus when i console log i get two"longpressed" events, and then "tapped"
– GeorgeK
Nov 11 at 12:59
Well, that's interesting. Have you tried clearing your env. A little bit? Like, quit your emulator, removenode_modules
,hooks
andplatforms
, thennpm i
andtns platform add ios/android
? Maybe something is cached. Maybe sometns build android/ios --clear
? Start with these and we'll see.
– ogrodowiczp
Nov 11 at 13:03
And why the heck there are 2x long presses and 1x tap? Hmm.
– ogrodowiczp
Nov 11 at 13:05
Removed node_modules, hooks, and platform, and still getting exactly the same issue. Longpress is fired twice in the beginning and then tap is fired once.
– GeorgeK
Nov 11 at 13:21
1
Have you tried defining tap event one level higher - on ListView instead of it's child? I believe there's something like(itemTapped)
if I recall well
– ogrodowiczp
Nov 11 at 13:52
|
show 8 more comments
up vote
1
down vote
It would be much easier for you to define 2 events in your template code:
<ListView class="listViewContainer" [items]="contactList">
<ng-template let-item="item" let-i="index">
<StackLayout
(loaded)="loaded($event)"
(tap)="functionWhenTap(item)"
(longPress)="functionWhenLongPress(item)"
orientation="horizontal"
class="preview-info-container"
>
</StackLayout>
</ng-template>
</ListView>
and then, handle it in your .ts
file with these:
functionWhenTap(item: any)
// your things to do when tapped
functionWhenLongPress(item: any)
// your things to do when long pressed
This is an actual piece of code. Should work for you as well.
Here's working example, tested on my physical personal device:
https://play.nativescript.org/?template=play-ng&id=XgBfFE
Thanks for your comment! I have tried this way, but i cannot prevent the tap event from being triggered at the end of the long press, thus when i console log i get two"longpressed" events, and then "tapped"
– GeorgeK
Nov 11 at 12:59
Well, that's interesting. Have you tried clearing your env. A little bit? Like, quit your emulator, removenode_modules
,hooks
andplatforms
, thennpm i
andtns platform add ios/android
? Maybe something is cached. Maybe sometns build android/ios --clear
? Start with these and we'll see.
– ogrodowiczp
Nov 11 at 13:03
And why the heck there are 2x long presses and 1x tap? Hmm.
– ogrodowiczp
Nov 11 at 13:05
Removed node_modules, hooks, and platform, and still getting exactly the same issue. Longpress is fired twice in the beginning and then tap is fired once.
– GeorgeK
Nov 11 at 13:21
1
Have you tried defining tap event one level higher - on ListView instead of it's child? I believe there's something like(itemTapped)
if I recall well
– ogrodowiczp
Nov 11 at 13:52
|
show 8 more comments
up vote
1
down vote
up vote
1
down vote
It would be much easier for you to define 2 events in your template code:
<ListView class="listViewContainer" [items]="contactList">
<ng-template let-item="item" let-i="index">
<StackLayout
(loaded)="loaded($event)"
(tap)="functionWhenTap(item)"
(longPress)="functionWhenLongPress(item)"
orientation="horizontal"
class="preview-info-container"
>
</StackLayout>
</ng-template>
</ListView>
and then, handle it in your .ts
file with these:
functionWhenTap(item: any)
// your things to do when tapped
functionWhenLongPress(item: any)
// your things to do when long pressed
This is an actual piece of code. Should work for you as well.
Here's working example, tested on my physical personal device:
https://play.nativescript.org/?template=play-ng&id=XgBfFE
It would be much easier for you to define 2 events in your template code:
<ListView class="listViewContainer" [items]="contactList">
<ng-template let-item="item" let-i="index">
<StackLayout
(loaded)="loaded($event)"
(tap)="functionWhenTap(item)"
(longPress)="functionWhenLongPress(item)"
orientation="horizontal"
class="preview-info-container"
>
</StackLayout>
</ng-template>
</ListView>
and then, handle it in your .ts
file with these:
functionWhenTap(item: any)
// your things to do when tapped
functionWhenLongPress(item: any)
// your things to do when long pressed
This is an actual piece of code. Should work for you as well.
Here's working example, tested on my physical personal device:
https://play.nativescript.org/?template=play-ng&id=XgBfFE
edited Nov 11 at 12:27
answered Nov 11 at 12:21
ogrodowiczp
216
216
Thanks for your comment! I have tried this way, but i cannot prevent the tap event from being triggered at the end of the long press, thus when i console log i get two"longpressed" events, and then "tapped"
– GeorgeK
Nov 11 at 12:59
Well, that's interesting. Have you tried clearing your env. A little bit? Like, quit your emulator, removenode_modules
,hooks
andplatforms
, thennpm i
andtns platform add ios/android
? Maybe something is cached. Maybe sometns build android/ios --clear
? Start with these and we'll see.
– ogrodowiczp
Nov 11 at 13:03
And why the heck there are 2x long presses and 1x tap? Hmm.
– ogrodowiczp
Nov 11 at 13:05
Removed node_modules, hooks, and platform, and still getting exactly the same issue. Longpress is fired twice in the beginning and then tap is fired once.
– GeorgeK
Nov 11 at 13:21
1
Have you tried defining tap event one level higher - on ListView instead of it's child? I believe there's something like(itemTapped)
if I recall well
– ogrodowiczp
Nov 11 at 13:52
|
show 8 more comments
Thanks for your comment! I have tried this way, but i cannot prevent the tap event from being triggered at the end of the long press, thus when i console log i get two"longpressed" events, and then "tapped"
– GeorgeK
Nov 11 at 12:59
Well, that's interesting. Have you tried clearing your env. A little bit? Like, quit your emulator, removenode_modules
,hooks
andplatforms
, thennpm i
andtns platform add ios/android
? Maybe something is cached. Maybe sometns build android/ios --clear
? Start with these and we'll see.
– ogrodowiczp
Nov 11 at 13:03
And why the heck there are 2x long presses and 1x tap? Hmm.
– ogrodowiczp
Nov 11 at 13:05
Removed node_modules, hooks, and platform, and still getting exactly the same issue. Longpress is fired twice in the beginning and then tap is fired once.
– GeorgeK
Nov 11 at 13:21
1
Have you tried defining tap event one level higher - on ListView instead of it's child? I believe there's something like(itemTapped)
if I recall well
– ogrodowiczp
Nov 11 at 13:52
Thanks for your comment! I have tried this way, but i cannot prevent the tap event from being triggered at the end of the long press, thus when i console log i get two"longpressed" events, and then "tapped"
– GeorgeK
Nov 11 at 12:59
Thanks for your comment! I have tried this way, but i cannot prevent the tap event from being triggered at the end of the long press, thus when i console log i get two"longpressed" events, and then "tapped"
– GeorgeK
Nov 11 at 12:59
Well, that's interesting. Have you tried clearing your env. A little bit? Like, quit your emulator, remove
node_modules
, hooks
and platforms
, then npm i
and tns platform add ios/android
? Maybe something is cached. Maybe some tns build android/ios --clear
? Start with these and we'll see.– ogrodowiczp
Nov 11 at 13:03
Well, that's interesting. Have you tried clearing your env. A little bit? Like, quit your emulator, remove
node_modules
, hooks
and platforms
, then npm i
and tns platform add ios/android
? Maybe something is cached. Maybe some tns build android/ios --clear
? Start with these and we'll see.– ogrodowiczp
Nov 11 at 13:03
And why the heck there are 2x long presses and 1x tap? Hmm.
– ogrodowiczp
Nov 11 at 13:05
And why the heck there are 2x long presses and 1x tap? Hmm.
– ogrodowiczp
Nov 11 at 13:05
Removed node_modules, hooks, and platform, and still getting exactly the same issue. Longpress is fired twice in the beginning and then tap is fired once.
– GeorgeK
Nov 11 at 13:21
Removed node_modules, hooks, and platform, and still getting exactly the same issue. Longpress is fired twice in the beginning and then tap is fired once.
– GeorgeK
Nov 11 at 13:21
1
1
Have you tried defining tap event one level higher - on ListView instead of it's child? I believe there's something like
(itemTapped)
if I recall well– ogrodowiczp
Nov 11 at 13:52
Have you tried defining tap event one level higher - on ListView instead of it's child? I believe there's something like
(itemTapped)
if I recall well– ogrodowiczp
Nov 11 at 13:52
|
show 8 more comments
up vote
0
down vote
I have not been able to solve this issue by adding two different events (tap/longPress).
As a solution i use the following
Inside .html
<StackLayout (touch)="onTouch($event)">
<Contact-Preview [contact]=contactList[i]></Contact-Preview>
</StackLayout>
Inside .ts
onTouch(args: TouchGestureEventData)
if(args.action === "down")
this.start = new Date().getMilliseconds();
if(args.action === "up")
this.end = new Date().getMilliseconds();
const duration = Math.abs(this.start - this.end)
console.log(duration > 150? "long press": "tap")
This prevents tap and longPress events being fired on the same time, thus working around my issue.
add a comment |
up vote
0
down vote
I have not been able to solve this issue by adding two different events (tap/longPress).
As a solution i use the following
Inside .html
<StackLayout (touch)="onTouch($event)">
<Contact-Preview [contact]=contactList[i]></Contact-Preview>
</StackLayout>
Inside .ts
onTouch(args: TouchGestureEventData)
if(args.action === "down")
this.start = new Date().getMilliseconds();
if(args.action === "up")
this.end = new Date().getMilliseconds();
const duration = Math.abs(this.start - this.end)
console.log(duration > 150? "long press": "tap")
This prevents tap and longPress events being fired on the same time, thus working around my issue.
add a comment |
up vote
0
down vote
up vote
0
down vote
I have not been able to solve this issue by adding two different events (tap/longPress).
As a solution i use the following
Inside .html
<StackLayout (touch)="onTouch($event)">
<Contact-Preview [contact]=contactList[i]></Contact-Preview>
</StackLayout>
Inside .ts
onTouch(args: TouchGestureEventData)
if(args.action === "down")
this.start = new Date().getMilliseconds();
if(args.action === "up")
this.end = new Date().getMilliseconds();
const duration = Math.abs(this.start - this.end)
console.log(duration > 150? "long press": "tap")
This prevents tap and longPress events being fired on the same time, thus working around my issue.
I have not been able to solve this issue by adding two different events (tap/longPress).
As a solution i use the following
Inside .html
<StackLayout (touch)="onTouch($event)">
<Contact-Preview [contact]=contactList[i]></Contact-Preview>
</StackLayout>
Inside .ts
onTouch(args: TouchGestureEventData)
if(args.action === "down")
this.start = new Date().getMilliseconds();
if(args.action === "up")
this.end = new Date().getMilliseconds();
const duration = Math.abs(this.start - this.end)
console.log(duration > 150? "long press": "tap")
This prevents tap and longPress events being fired on the same time, thus working around my issue.
answered Nov 11 at 14:34
GeorgeK
548
548
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248470%2flongpress-event-triggers-tap-event%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Elaborate your question.
– Sunil Singh
Nov 11 at 12:02
I have edited with a more specific question.
– GeorgeK
Nov 11 at 12:10