Problem Description
showTimePickerDialog doesn't work if you don't add the picker before to the window.
Steps to reproduce
1. Create a new mobile project
2. Add this testcase to app.js:
var win = Ti.UI.createWindow({
exitOnClose: true
});
var picker = Ti.UI.createPicker({
type: Ti.UI.PICKER_TYPE_TIME
});
var btn = Ti.UI.createButton({
title : 'Show time picker dialog'
});
win.add( btn );
win.open( );
btn.addEventListener( 'singletap', function( ) {
picker.showTimePickerDialog({
callback: function( e ) {
if ( e.cancel ) {
Ti.API.info( 'User canceled dialog' );
} else {
Ti.API.info( 'User selected time: ' + e.value );
}
}
});
});
Console output message:
[WARN] HardwareRenderer: Attempting to initialize hardware acceleration outside of the main thread, aborting
3. Run it in device.
4. Click on show the picker.
Workaround
Set the left element to -1000 (or any negative number outside of the screen, and add the picker to the window.
var win = Ti.UI.createWindow({
exitOnClose : true,
layout : 'vertical'
});
var picker = Ti.UI.createPicker({
type : Titanium.UI.PICKER_TYPE_TIME,
top : 10,
left:-1000,
});
win.add(picker);
var btn = Ti.UI.createButton({
title : 'Show time picker dialog',
top : 10
});
win.add(btn);
//win.add(picker);
win.open();
btn.addEventListener('singletap', function() {
picker.showTimePickerDialog({
callback : function(e) {
if (e.cancel) {
Ti.API.info('User canceled dialog');
} else {
Ti.API.info('User selected time: ' + e.value);
}
}
});
});
Workaround
Set the left element of your picker to -1000, and add it to the window. Check this code:PR: https://github.com/appcelerator/titanium_mobile/pull/8957
Verified fix in SDK Version: 6.2.0.v20170626084207. Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/8957