Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24190] Android: Adding getLocationOnScreen() to retrieve location after translation

GitHub Issuen/a
TypeNew Feature
PriorityCritical
StatusClosed
ResolutionInvalid
Resolution Date2017-03-06T13:31:26.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, community, notable, position
ReporterMichael Gangolf
AssigneeFrankie Merzadyan
Created2016-12-01T19:15:36.000+0000
Updated2017-03-06T13:31:26.000+0000

Description

Animating a view using transform and a 2DMatrix will return the left coordinate and not the new position. The new method getLocationOnScreen() will return the actual x/y value. Example
var win = Ti.UI.createWindow({
    backgroundColor: "#fff"
});

var v = Ti.UI.createView({
    left: 0,
    top: 0,
    width: 100,
    height: 100,
    backgroundColor: "#f00"
});

var dpi = Ti.Platform.displayCaps.logicalDensityFactor;

win.addEventListener("open", function() {
    v.animate({
        left: 200,
        duration: 1000
    }, function() {
        console.log("Animate left:");
        console.log("left: " + v.left);
        console.log("rect.x: " + v.rect.x);
        console.log("locationOnScreen: " + v.getLocationOnScreen().x);
        console.log("------------------------");

        var matrix = Ti.UI.create2DMatrix()
        matrix = matrix.translate(-200*dpi, 0);

        v.animate({
            transform: matrix,
            duration: 1000
        }, function() {
            console.log("Animate transform:");
            console.log("left: " + v.left);
            console.log("rect.x: " + v.rect.x);
            console.log("locationOnScreen: " + v.getLocationOnScreen().x);
            console.log("------------------------");
        });
    });
})
win.add(v);
win.open();
The output will be: Animate left: left: 200 rect.x: 200 locationOnScreen: 200 ------------------------ Animate transform: left: 200 *<---- wrong, last left value* rect.x: 200 *<---- wrong, last left value* locationOnScreen: 0 *<-----correct position after translate* ------------------------ It can be very handy if you drag objects using translateX/translateY and want to check the actual position

Comments

  1. Hans Knöchel 2016-12-02

    Danke Michael! [~fmerzadyan], can you do the CR & FT for this? Thx! *EDIT*: The community PR was revoked, so pulling it out of 6.1.0
  2. Gary Mathews 2017-03-06

JSON Source