Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23915] Hyperloop - iOS: Touch event properties and methods are undefined

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionDuplicate
Resolution Date2017-02-08T11:25:31.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsHyperloop, iOS
LabelsHyperloop
ReporterBrian García
AssigneeJan Vennemann
Created2016-09-16T09:05:33.000+0000
Updated2017-03-24T18:35:47.000+0000

Description

Trying to get lastPoint touched in screen return
JS exception encountered calling callback: undefined is not a function (evaluating 'UITouch.prototype.locationInView($.win)')
code to reproduce: it assumes there is a win defined in xml.
var UIView = require('UIKit/UIView');
var DrawView = Hyperloop.defineClass('DrawView', 'UIView');

DrawView.addMethod({
    selector : 'touchesBegan:withEvent:',
    instance : true,
    arguments : ['NSSet', 'UIEvent'],
    callback : function(touches, event) {
        var touch = touches.anyObject();
        var lastPoint = touch.locationInView($.win);
        console.log(lastPoint);
    }
});

var drawSurface = DrawView.alloc().initWithFrame(50, 0, 350, 350);
drawSurface.backgroundColor = UIColor.yellowColor();
$.win.add(drawSurface);

Comments

  1. Hans Knöchel 2016-09-16

    You are passing a Ti.UI.Window to a native API, that won't work:
       touch.locationInView($.win);
       
    Instead, you may try to cast it to a UIView, using UIView.cast($.win)
  2. Brian García 2016-09-16

    Same result with casting:
       JS exception encountered calling callback: undefined is not a function (evaluating 'touch.locationInView(UIView.cast($.win))')
       
  3. Hans Knöchel 2016-09-16

    Then I guess touch is already null before. Try:
       var touch = touches.allObjects[0];
       
    instead.
  4. Brian García 2016-09-17

    touch returns a valid object:
       <UITouch: 0x7872dc10> phase: Began tap count: 1 window: <UIWindow: 0x789316c0; frame = (0 0; 320 480); gestureRecognizers = <NSArray: 0x78932280>; layer = <UIWindowLayer: 0x7892e9c0>> view: <DrawView: 0x7869b370; frame = (0 0; 320 480); layer = <CALayer: 0x7869a430>> location in window: {149.5, 225.5} previous location in window: {149.5, 225.5} location in view: {149.5, 225.5} previous location in view: {149.5, 225.5}
       
    any way touches.allObjects[0]; returns null
  5. Hans Knöchel 2016-09-17

    Ok, so it's really only about the locationInView method then. I also noticed that the log of the object returns location in view: {149.5, 225.5} so at least something is there. I will move to TIMOB for further investigations. Please also attach your generated metabase from build/hyperloop/ios, thx!
  6. Hans Knöchel 2016-12-12

    Hey Brian, out of interest: When you include a Foundation class (e.g. require('Foundation/NSURL')), does that fix the issue? It might be related to a different issue of the same type. Thx!
  7. Brian García 2016-12-13

    Hi Hans, I tried what you suggested but with no success, it still failling with the same error. I've just seen that you need the metabase, here is the gist (if you need a downloadable file let me know)[https://gist.github.com/Brianggalvez/1697f824da98bd1a6c002b848a79d49d]
  8. Jan Vennemann 2017-02-08

    I discovered a similar behavior when testing for TIMOB-24242. The NSSet will be populated with NSTouch objects on the native side. Somehow Hyperloop fails to properly wrap those objects when retrieving them from the NSSet, preventing any property access or method calls. I opened TIMOB-24383 to keep track of the root issue.
  9. Hans Knöchel 2017-02-08

    Resolving as Duplicate to keep track in the root-ticket. Thx!
  10. Lee Morris 2017-03-24

    Closing ticket as duplicate with reference to the linked issues.

JSON Source