Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13558] Android: Button with a touchstart event can look disabled if you call setEnabled(true)

GitHub Issuen/a
TypeBug
PriorityHigh
StatusReopened
ResolutionUnresolved
Affected Version/sRelease 3.2.0
Fix Version/sn/a
ComponentsAndroid
Labelsexalture, supportTeam
ReporterEduardo Gomez
AssigneeUnknown
Created2013-04-15T17:20:20.000+0000
Updated2018-02-28T20:03:20.000+0000

Description

Problem

if you have a Button with a touchstart event it can look disabled if you call setEnabled(true) after the button is clicked. If they use a touchend, or click event then this issue is not present or if I use the 2.1.3.GA sdk then this issue does not occur with the touchstart event.

To reproduce

1. Install this app to a android device. 2. Launch ADB so you can see when the buttons are pressed. 3. Click Button 1, watch the logs to verify the button was clicked. 4. Click Enable Button 1 5. Notice that Button 1 is now in a depressed state. 6. Click on Button 1, notice it clicked and is now in a enabled state 7. Click Enable BUtton 8. Notice its back to the depressed state.

== app.js ==

var view = require('FirstView')();
var win = Ti.UI.createWindow({
	backgroundColor: "white"
});
win.add(view);
win.open();

== FirstView.js ==

//FirstView Component Constructor
function FirstView() {

	var self = Ti.UI.createView();

	var defaults = {
		enabled: true,//me
		title : "Button 1",
		top : 20,
		width : 400,
		height : 200,
		backgroundTopCap : 50,
		backgroundLeftCap : 50,
		color : "#2C4471",
		selectedColor : "#2C4471",
		font : {
			"fontSize" : "16dp",
			"fontFamily" : "HelveticaNeue-Bold",
			"fontWeight" : "bold"
		},
		backgroundImage : '/global-btn-up.png',
		backgroundSelectedImage : '/global-btn-down.png',
		shadow : {
			shadowRadius : 4,
			shadowOpacity : 0.2,
			shadowOffset : {
				x : 0,
				y : 0
			}
		}
	}

	var button = Titanium.UI.createButton(defaults);

	self.add(button);

	button.addEventListener('touchstart', function() {
		button.setEnabled(false);
		Ti.API.info("[INFO] [Button 1 clicked!!]");
	});

	var button2 = Titanium.UI.createButton(defaults);
	button2.top = 260;
	button2.title = "Enable Button 1";
	self.add(button2);

	button2.addEventListener('touchstart', function() {
		button.setEnabled(true);
		Ti.API.info("[INFO] [Button 2 clicked!!]");
	});

	return self;

}

module.exports = FirstView; 

Attachments

FileDateSize
global-btn-down.9.png2013-04-15T17:20:20.000+00001788
global-btn-up.9.png2013-04-15T17:20:20.000+00001674

Comments

  1. Sunila 2013-06-06

    I have logged my findings
  2. Daniel Fortner 2014-03-17

  3. Sunila 2014-03-23

    This looks like an Android issue where the state is messed up if the button is disabled during touch event. One workaround could be to use 'touchend' instead of 'touchstart'
  4. Neeraj Gupta 2014-03-24

    It appears that it worked with a previous Titanium SDK version. Can you reproduce this issue with a native application? If yes, can we have a workaround for Titanium SDK?

JSON Source