You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the longPress gesture, it will fire once (as it should) and then when you let go of your finger, it fires again. This isn't intentional, is it?
There's no state or action property of the event, so there's no such thing as an "up" event to handle.
Hi @NordlingArt,
Thank you for reporting this issue.
I was able to reproduce this behavior on my side and confirm that this is a real issue for iOS. I am also attaching sample code, where the problem could be reproduced.
import { EventData } from 'data/observable';
import { Page } from 'ui/page';
import { HelloWorldModel } from './main-view-model';
import { GestureTypes, GestureEventData, TouchGestureEventData } from "ui/gestures";
import labelModule = require("ui/label");
import {isIOS} from "platform"
// Event handler for Page "navigatingTo" event attached in main-page.xml
var viewmodel = new HelloWorldModel()
var statedown=true
export function navigatingTo(args: EventData) {
let page = <Page>args.object;
page.bindingContext = viewmodel;
}
export function labelLoaded(args){
var label = args.object;
label.on("longPress", function (args: GestureEventData) {
console.log("longPress");
console.log(args.eventName);
console.log(args.type);
});
}
As a workaround, you could create one custom flag, which will allow you to determine the second fire of the event on iOS.
main-page.ts
import { EventData } from 'data/observable';
import { Page } from 'ui/page';
import { HelloWorldModel } from './main-view-model';
import { GestureTypes, GestureEventData, TouchGestureEventData } from "ui/gestures";
import labelModule = require("ui/label");
import {isIOS} from "platform"
// Event handler for Page "navigatingTo" event attached in main-page.xml
var viewmodel = new HelloWorldModel()
var statedown=true
export function navigatingTo(args: EventData) {
let page = <Page>args.object;
page.bindingContext = viewmodel;
}
export function labelLoaded(args){
var label = args.object;
label.on("longPress", function (args: GestureEventData) {
console.log(statedown)
if(isIOS){
if(statedown){
console.log("longPress");
console.log(args.eventName);
console.log(args.type);
statedown=false;
}
else{
statedown=true;
}
}
});
}
longPress gesture does not have state or action property. For this case, you could use touch gesture, where you could handle the state while using its action property.
Hi @terreb,
This is still a valid issue for iOS. Regarding that, this problem is still under review and I could not commit to the exact time, where it would be fixed. You could keep track on the issue for further info and in the meantime, you could use the above-given workaround.
They implemented states into event. You can track when it starts, continues and ends. That means it is clearly something intended. Not a bug. Maybe you can use this to drag something around. It would be handy if you could track that.
// Assume platform is iOSexports.onLongPress=args=>{switch(args.ios.state){caseUIGestureRecognizerStateBegan: // 1// The long press event has begun.break;caseUIGestureRecognizerStateChanged: // 2// The long press event has changed.break;caseUIGestureRecognizerStateEnded: // 3// The long press event has ended.break;}}
Just ran in to this issue myself ({N}6.3), and while the solution provided above (manually checking the UIGestureRecognizer's state) works, I wondered if this will be fixed in upcoming releases of NS...
These are the sorts of things that (I feel) are holding NativeScript back––weird, inconsistent behaviour across versions, platforms, etc. (though they are also the hardest to perfect, of course)
@farfromrefug@fgutteridge I've opened this PR which is proving the state as an argument for longPress event on iOS (via GestureEventDataWithState interface).
Activity
tsonevn commentedon Feb 6, 2017
Hi @NordlingArt,
Thank you for reporting this issue.
I was able to reproduce this behavior on my side and confirm that this is a real issue for iOS. I am also attaching sample code, where the problem could be reproduced.
main-page.xml
main-page.ts
As a workaround, you could create one custom flag, which will allow you to determine the second fire of the event on iOS.
main-page.ts
longPressgesture does not havestateoractionproperty. For this case, you could usetouchgesture, where you could handle the state while using itsactionproperty.NordlingDev commentedon Feb 7, 2017
@tsonevn - Thanks for confirming issue. I have applied a custom flag as a temporary work around.
NathanaelA commentedon Feb 8, 2017
terreb commentedon Aug 17, 2017
Having the same, any updates?
tsonevn commentedon Aug 21, 2017
Hi @terreb,
This is still a valid issue for iOS. Regarding that, this problem is still under review and I could not commit to the exact time, where it would be fixed. You could keep track on the issue for further info and in the meantime, you could use the above-given workaround.
terreb commentedon Aug 21, 2017
@tsonevn, ok thank you.
two-bridges commentedon Oct 30, 2017
TNS 3.2.1, iOS
Having the same, any updates?
tsonevn commentedon Feb 7, 2018
Base on the iOS documentation, we could check the state of the gesture and to allow executing our functionality only on long press ended.
In the meantime, we could workaround this case as follow:
tsonevn commentedon Jul 30, 2018
reproducible with modules 4.1
erkanarslan commentedon Aug 27, 2018
This is not a bug but a feature of iOS I guess. We should just check the state on iOS. Should this issue still be opened?
shaedrich commentedon Aug 27, 2018
Can you explain why triggering a method can be a feature?
erkanarslan commentedon Aug 27, 2018
They implemented states into event. You can track when it starts, continues and ends. That means it is clearly something intended. Not a bug. Maybe you can use this to drag something around. It would be handy if you could track that.
mudlabs commentedon Jul 25, 2019
farfromrefug commentedon Sep 27, 2019
A good thing would be to return the state directly in the gesture event and in the ios object. It is the case for some gesture events but not all.
fgutteridge commentedon Jan 2, 2020
Hey @NickIliev...
Just ran in to this issue myself ({N}6.3), and while the solution provided above (manually checking the UIGestureRecognizer's state) works, I wondered if this will be fixed in upcoming releases of NS...
These are the sorts of things that (I feel) are holding NativeScript back––weird, inconsistent behaviour across versions, platforms, etc. (though they are also the hardest to perfect, of course)
Thanks for your help, @tsonevn and @NickIliev!
NickIliev commentedon Jan 3, 2020
@farfromrefug @fgutteridge I've opened this PR which is proving the state as an argument for longPress event on iOS (via
GestureEventDataWithStateinterface).Example:
Note: As Android doesn't support states I've made it so it would always return state 1 when the long press is triggered on Android
fgutteridge commentedon Jan 3, 2020
Looks great, @NickIliev! Thanks so much for your help. Yes, having the
longPressevent exposed statefully (for iOS at least) makes the most sense.