[TIMOB-24097] Windows: Native event handling
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-12-09T00:28:56.000+0000 |
Affected Version/s | Release 5.4.0 |
Fix Version/s | Release 6.1.0 |
Components | Windows |
Labels | n/a |
Reporter | Kota Iguchi |
Assignee | Kota Iguchi |
Created | 2016-11-04T00:26:27.000+0000 |
Updated | 2017-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();
https://github.com/appcelerator/titanium_mobile_windows/pull/899
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.