eclipsesource / tabris-js

Create native mobile apps in JavaScript or TypeScript.
https://tabrisjs.com
BSD 3-Clause "New" or "Revised" License
1.4k stars 170 forks source link

Expose absolute coordinates of widgets on contentview #850

Closed cpetrov closed 5 years ago

cpetrov commented 8 years ago

Currently laid out widget coordinates relative to its parent are exposed by the bounds property. Access to absolute position of a widget on the screen may be useful for advanced animations.

Use case example: scroll view with complex layout. Goal: pop-up animation, scaling an arbitrary scroll view child widget to fit the screen (e.g. modal image details view with a fluid animation). Implementation suggestion:

  1. get the absolute coordinates of the widget.
  2. create a second twin widget and append it to the page using the absolute coordinates from (1).
  3. set visible of the first widget to false.
  4. animate the widget from (2).

Currently (1) is only possible by manually calculating the absolute coordinates of the widget (not easy with complex layouts) respecting the current scroll position.

mpost commented 8 years ago

Agreed on the usability... On Android you can get the absolute coordinates of a view on screen. How about iOS @patrykmol?

patrykmol commented 8 years ago

It is possible but has always been problematic on iOS (lots of calculations).

ralfstx commented 7 years ago

We plan on an absoluteBounds property that returns bounds relative to the contentView.

tbuschto commented 6 years ago

👍 We could also use this in some of our projects.

tbuschto commented 6 years ago

I think this could be implemented easily in JS only, if the existing bound property is precise enough and we limit it to descendants of contentView. I think it should be method though, relativeBounds(someOtherWidget).

mpost commented 6 years ago

Android has the methods https://developer.android.com/reference/android/view/View#getLocationOnScreen(int[]) and https://developer.android.com/reference/android/view/View#getLocationInWindow(int[]) which will be faster than doing it in js.

raphaelpreston commented 5 years ago

Any word on this? In my use case, since negative edge offsets are no longer supported, this would really make my life easier.

mpost commented 5 years ago

Negative bounds have never been supported on Android. We added clarified this in the documentation accordingly. The idea to get the view bounds is still valid though. For the moment you could traverse up the view hierarchy in a resize callback and add up the top/left coordinates.

cookieguru commented 5 years ago

Implemented in a9c2bb2d874a8ba52e92b4a3c2bfc0460af49eb0

mpost commented 5 years ago

@cookieguru Thanks for the heads up. Closing as resolved.