Skip to content

Instantly share code, notes, and snippets.

@nuno
Last active March 14, 2017 23:04
Show Gist options
  • Save nuno/15b01d2f6ad6c11f594e190d7f90e5c1 to your computer and use it in GitHub Desktop.
Save nuno/15b01d2f6ad6c11f594e190d7f90e5c1 to your computer and use it in GitHub Desktop.
Workaround for, textField passwordMask toggle set incorrect fontFamily and fontSize. More info: https://jira.appcelerator.org/browse/TIMOB-16100 please see the comments. Based on http://stackoverflow.com/questions/35293379/uitextfield-securetextentry-toggle-set-incorrect-font
var win = Ti.UI.createWindow();
var view = Ti.UI.createView( {
width: ( Ti.Platform.displayCaps.platformWidth - 20 ),
top: 200,
layout: 'vertical'
} );
var button = Ti.UI.createButton( {
backgroundColor: 'gray',
title: 'Pass focus',
top: 30
} );
var password = Ti.UI.createTextField( {
width: Ti.UI.FILL,
height: 40,
font: {
fontSize: 14,
fontFamily: "Times"
},
textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT,
paddingLeft: 10,
passwordMask: false,
hintText: "password",
backgroundColor: "#ccc",
tintColor: 'red',
autocorrect: false,
autocapitalization: Titanium.UI.TEXT_AUTOCAPITALIZATION_NONE,
returnKeyType: Ti.UI.RETURNKEY_DONE
} );
var label = Ti.UI.createLabel( {
right: 10,
text: "hide"
} );
label.addEventListener( "click", function() {
if ( password.passwordMask ) {
label.text = "hide";
password.passwordMask = false;
password.font = null;
password.font = {
fontSize: 14,
fontFamily: "Times"
};
password.blur();
} else {
label.text = "show";
password.passwordMask = true;
password.blur();
}
console.log( '"' + password.value + '"' );
} );
password.addEventListener( 'focus', function _focus( e ) {
console.log( '_focus: ', JSON.stringify( e, null, 2 ) );
password.font = null;
e.source.font = {
fontSize: 14,
fontFamily: "Times"
};
} );
password.addEventListener( 'blur', function _blur( e ) {
console.log( '_blur: ', JSON.stringify( e, null, 2 ) );
password.font = null;
e.source.font = {
fontSize: 14,
fontFamily: "Times"
};
} );
button.addEventListener( 'click', function( e ) {
password.focus();
} );
//password.add(label);
view.add( label );
view.add( password );
view.add( button );
win.add( view );
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment