Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get e.globalPoint in Titanium 3.1.0 GA

Tags:

titanium

I am trying to get globalPoint in Titanium iPhone application when touchmove event occur, I use following code to get globalPoint

var x = parseInt(e.globalPoint.x, 10);

It work fine until I updated Titanium 3.0.2 GA to 3.1.0 GA, after updating I run the application I got following error

'undefined' is not an object (evaluating 'e.globalPoint.x')

I am using this code for swiping window

var animateLeft = Ti.UI.createAnimation({
    left : 250,
    curve : Ti.UI.ANIMATION_CURVE_EASE_OUT,
    duration : 150
});

var animateRight = Ti.UI.createAnimation({
    left : 0,
    curve : Ti.UI.ANIMATION_CURVE_EASE_OUT,
    duration : 150
});

var touchStartX = 0;
var touchStarted = false;

$.innerwin.addEventListener('touchstart', function(e) {
    touchStartX = parseInt(e.x, 10);
});

$.innerwin.addEventListener('touchend', function(e) {
    touchStarted = false;
    if ($.win.left >= 150) {
        $.win.animate(animateLeft);
        hasSlided = true;
    } else {
        $.win.animate(animateRight);
        hasSlided = false;
    }
});

$.innerwin.addEventListener('touchmove', function(e) {
    var x = parseInt(e.globalPoint.x, 10);
    var newLeft = x - touchStartX;
    if (touchStarted) {
        if (newLeft <= 250 && newLeft >= 0) {
            $.win.left = newLeft;
        }
    }
    if (newLeft > 30) {
        touchStarted = true;
    }
});

$.button.addEventListener('singletap', function(e) {
    $.toggleSlider();
});

var hasSlided = false;
exports.toggleSlider = function() {
    if (!hasSlided) {
        $.win.animate(animateLeft);
        hasSlided = true;
    } else {
        $.win.animate(animateRight);
        hasSlided = false;
    }
}
like image 705
Praveen Kumar Avatar asked Nov 29 '25 15:11

Praveen Kumar


1 Answers

This has been deprecated:

Instead you need to do this (in this very contrived example), and use the convertPointToView method:

var baseview = Ti.UI.createView({width : Ti.UI.FILL, height : Ti.UI.FILL});
var view = Ti.UI.createView({ width : 20, height : 20 });
view.addEventListener('touchmove', function(e) {
    var globalPoint = convertPointToView({x : e.x, y : e.y}, baseview);
});
like image 112
Josiah Hester Avatar answered Dec 02 '25 06:12

Josiah Hester