Skip to content

fix: update tap event data#8415

Merged
vtrifonov merged 13 commits into
NativeScript:masterfrom
mudlabs:tap-event-data
Mar 19, 2020
Merged

fix: update tap event data#8415
vtrifonov merged 13 commits into
NativeScript:masterfrom
mudlabs:tap-event-data

Conversation

@mudlabs

@mudlabs mudlabs commented Mar 5, 2020

Copy link
Copy Markdown
Contributor

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 TapGestureEventData interface, available to tap and doubleTap events.

The getX(), getY(), and getPointerCount() methods of touch events are now available to tap, and doubleTap events.

export function myTapEvent(args: TapGestureEventData): void {
  const [ x, y ] = [args.getX(), args.getY()];
  const pointers = args.getPointerCount();

  console.log(`Tap location: (${x}, ${y}). Number of Pointers: ${pointers}`);
}

Implements #8407

BREAKING CHANGES:

None

mudlabs added 2 commits March 5, 2020 18:22
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.
@cla-bot cla-bot Bot added the cla: yes label Mar 5, 2020
@mudlabs mudlabs changed the title ui(gestures): update tap event data fix: update tap event data Mar 5, 2020
@NathanaelA

This comment was marked as abuse.

@mudlabs

mudlabs commented Mar 6, 2020

Copy link
Copy Markdown
Contributor Author

@NathanaelA ok.

What about the conflict with iOS vs Android touch Pointers?

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.

@farfromrefug

Copy link
Copy Markdown
Collaborator

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 vmutafov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/package.json Outdated
@mudlabs

mudlabs commented Mar 7, 2020

Copy link
Copy Markdown
Contributor Author

@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.


@NathanaelA @farfromrefug

@vmutafov

vmutafov commented Mar 9, 2020

Copy link
Copy Markdown
Contributor

Personally, I'm not a fan of methods starting with get having a boolean parameter. It seems like a code smell to me, so I would prefer B) or C)

@farfromrefug

Copy link
Copy Markdown
Collaborator

@vmutafov i understand your point
But to me if we want not to break anything and still be consistent with the way it works everywhere else A seems the best to me

@NathanaelA

This comment was marked as abuse.

@mudlabs

mudlabs commented Mar 10, 2020

Copy link
Copy Markdown
Contributor Author

@NathanaelA Does it clutter the API do have both getXDIP() and getXPixels() etc..?

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 layout.getDisplayDensity(), screen.mainScreen.scale, or how to get the values from the underlying native object.

This is why I think DIP should be the standardised default throughout the API. And why my initial PR was just an override of getX()/getY(), because if it's all standardised to DIP we don't need to specify format in property/method names.

@farfromrefug

Copy link
Copy Markdown
Collaborator

@mudlabs I totally agree. I don't see the need for both.

@NathanaelA

This comment was marked as abuse.

@mudlabs

mudlabs commented Mar 11, 2020

Copy link
Copy Markdown
Contributor Author

Found more inconsistencies

On iOS the return values from getFocusX()/getFocusY() of Pinch events, and the values for deltaX/deltaY of Pan events are all in DP format.

On Android these are all in DIP format.


I think I'm going to just keep this PR to implementing the getX()/getY() methods for tap events. These will return DIP.

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.

  • If we can get that standardised then to get the DP off any value you'll only ever need to use layout.toDevicePixels(DIPValue).

mudlabs and others added 3 commits March 11, 2020 12:54
Tap and doubleTap event data now include getX and getY methods for event location. These are in DIP format.

getPointerCount is also available.
@mudlabs mudlabs requested a review from vmutafov March 11, 2020 02:04
@mudlabs

mudlabs commented Mar 15, 2020

Copy link
Copy Markdown
Contributor Author

@vmutafov any chance of getting that review closed?

@vtrifonov vtrifonov merged commit 8dbb623 into NativeScript:master Mar 19, 2020
NathanWalker pushed a commit that referenced this pull request Aug 7, 2020
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants