Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24097] Windows: Native event handling

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2016-12-09T00:28:56.000+0000
Affected Version/sRelease 5.4.0
Fix Version/sRelease 6.1.0
ComponentsWindows
Labelsn/a
ReporterKota Iguchi
AssigneeKota Iguchi
Created2016-11-04T00:26:27.000+0000
Updated2017-03-02T23:12:40.000+0000

Description

Event handling following JavaScript syntax by adding/removing event handlers with the addEventListener() and removeEventListener() methods rather than the C++/C# syntax. In C++/CX, we used to do like below:
click_event_ = component->Tapped += ref new TappedEventHandler([this, ctx](Platform::Object^ sender, TappedRoutedEventArgs^ e) {
    // do something
});
But in JavaScript, we want to do like this:
component.addEventListener('Tapped', function(e) {
    // do something
});
FYI: [Windows Runtime Direct API Access - Event Handling](http://docs.appcelerator.com/platform/latest/#!/guide/Windows_Runtime_Direct_API_Access-section-43315893_WindowsRuntimeDirectAPIAccess-EventHandling) Test code:
require('Windows.UI.Xaml.Input.TappedRoutedEventArgs');

var win = Ti.UI.createWindow({ backgroundColor: 'green' }),
    Button = require('Windows.UI.Xaml.Controls.Button'),
    button = new Button();

button.Content = "PUSH";
button.addEventListener('Tapped', function (e) {
    var pos = e.GetPosition(null);
    Ti.API.info(pos.X + ' -' + pos.Y);
});

win.add(button);
win.open();

Comments

  1. Kota Iguchi 2016-12-07

    https://github.com/appcelerator/titanium_mobile_windows/pull/899
  2. Abir Mukherjee 2017-03-02

    Environment: NPM Version: 2.15.9 Node Version: 4.6.0 Windows OS: 10.0.14393.693 Appc CLI: 6.1.0 Appc CLI NPM: 4.2.8 Titanium SDK version: 6.1.0.v20170227120704 Appcelerator Studio, build: 4.8.1.201612050850 Windows Device: 8.1 and 10.0.14393 Windows Emulator 8.1 and 10.0.14393 I validated the fix with both emulator and device using the demo code given in the description. I found that the app worked as expected. That is when I clicked on the "Push" button, I was able to see the xy info on the console.

JSON Source