fix: update tap event data#8415
Conversation
Adds a: - TabGestureEventData interface, which can be used for both tap and doubleTap events. - The event object returned by both tap and doubleTap events now have getX(), getY(), and getPointersCount() methods. These facilitate the same function as those of the touch event object.
Updates the getX() and getY() methods of Tap, doubleTap and touch events to return DIP instead of DP.
This comment was marked as abuse.
This comment was marked as abuse.
|
@NathanaelA ok. What about the conflict with iOS vs Android As it stands: function myTouchEvent(args: TouchGestureEventData): void {
const pointer = args.getActivePointers()[0];
const x = pointer.getX();
// x is in DP on iOS, but DIP on Android
console.log(x);
}Should I leave iOS as DP for now. Or correct it to match Android. They should both be the same. P.S. I think all properties and methods provided by the NativeScript API should default to DIP, unless otherwise noted. |
|
Agree everything should return dip! I wrote a plugin for better gestures based on the great react native plugin. This was one of the reason. I think that PR should be a amazing addition |
vmutafov
left a comment
There was a problem hiding this comment.
Thank you really much for the PR :) We would appreciate it if there are no breaking changes and probably a good approach is to have slightly differently named methods instead of reusing getX and getY. In the PR comments, @NathanaelA also gave you this advice and I believe he is right. Also, could you please preserve the formatting which was used in the code or if you think better formatting is needed, commit it in a different PR.
|
@vmutafov , Sorry about the formatting. My VSCode just does that every time I save a file. I must have installed a formatter at some point. Not sure how to deactivate it, we'll look into it. I will rework the branch to remove breaking changes. As for the method implementation do we prefer:// A) Same method names, but an optional boolean specifies the format.
getX(DIP?: boolean): number;
// B) Method names specify format, then property.
getDIPX(): number;
// C) Method names specify property, then format.
getXDIP(): number;Personally I prefer either A or C. If there's already a convention where object properties would follow C, then it could make sense to do likewise with methods. Although, if the methods return the same type then A could be the go, as it follows the same convention, only in a method centric way, and with one less function declaration. |
|
Personally, I'm not a fan of methods starting with |
|
@vmutafov i understand your point |
This comment was marked as abuse.
This comment was marked as abuse.
|
@NathanaelA Does it clutter the API do have both I feel like I've seen comments from the NativeScript team indicating they only want their API to offer properties/methods that have I high need from most users. I think most will probably just need DIP. Unless you are diving down into native code DIP is what you'll need to update the UI; if that's why you need the coordinates. Devs needing pixels (DP) are likely implementing native code, and probably know about This is why I think DIP should be the standardised default throughout the API. And why my initial PR was just an override of |
|
@mudlabs I totally agree. I don't see the need for both. |
This comment was marked as abuse.
This comment was marked as abuse.
Found more inconsistenciesOn iOS the return values from On Android these are all in DIP format. I think I'm going to just keep this PR to implementing the I'll undo any other changes so we don't have any breakages. And leave in all the inconsistencies for now. Then I'll open a new issue outlining our desire to see a standardised use of DIP throughout the API. And then create a new PR with breaking changes for v7.
|
Tap and doubleTap event data now include getX and getY methods for event location. These are in DIP format. getPointerCount is also available.
|
@vmutafov any chance of getting that review closed? |
* Update tap event data object Adds a: - TabGestureEventData interface, which can be used for both tap and doubleTap events. - The event object returned by both tap and doubleTap events now have getX(), getY(), and getPointersCount() methods. These facilitate the same function as those of the touch event object. * ui(gesture): getX,getY in DIP Updates the getX() and getY() methods of Tap, doubleTap and touch events to return DIP instead of DP. * ui(gesture): tap event data includes location Tap and doubleTap event data now include getX and getY methods for event location. These are in DIP format. getPointerCount is also available. * Fix tslint errors * fix minor formatting issues for api-extrector
PR Checklist
What is the current behavior?
Tap and doubleTap events do not provide first-class methods for obtaining the tap location or pointer count, unlike touch events.
What is the new behavior?
There is now a
TapGestureEventDatainterface, available totapanddoubleTapevents.The
getX(),getY(), andgetPointerCount()methods oftouchevents are now available totap, anddoubleTapevents.Implements #8407
BREAKING CHANGES:
None