Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26374] Android: Ti.UI.Button can't be disabled until displayed as of 6.1.0

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2018-09-14T22:25:43.000+0000
Affected Version/sRelease 6.1.0
Fix Version/sRelease 7.5.0
ComponentsAndroid
Labelsandroid, button
ReporterMichael Gangolf
AssigneeYordan Banev
Created2018-09-10T11:37:59.000+0000
Updated2018-09-23T12:58:17.000+0000

Description

It is not possible to disable a button via it's "enabled" property upon creation on Android:
var win = Ti.UI.createWindow({
    backgroundColor: '#fff'
});

var btn = Ti.UI.createButton({
    title: "test",
    enabled: false
})

btn.addEventListener("click",function() {
    alert("enabled")
});

win.add(btn);
win.open();
The button is still clickable and has the default style (touch effect). Using the setEnabled method didn't work either. HTC A9, Android 7 Ti SDK 7.3.1.GA

Comments

  1. Joshua Quick 2018-09-10

    I've confirmed that the "enabled" property is ignored upon creation. This has been an as issue since Titanium 6.1.0. *Work-Around:* You can enable/disable the button once its hosting window has been opened. For example...
       var window = Ti.UI.createWindow();
       var button = Ti.UI.createButton({
       	title: "Test",
       // This does not work on Android.
       //	enabled: false,
       });
       window.add(button);
       window.addEventListener("open", function() {
       	// This works on both Android and iOS.
       	button.enabled = false;
       });
       window.open();
       
  2. Yordan Banev 2018-09-12

    PR: https://github.com/appcelerator/titanium_mobile/pull/10320
  3. Michael Gangolf 2018-09-12

    [~ybanev] sorry had no time to compile your PR, but does this change put the button into disabled mode? like this: https://materialdoc.com/images/raised-button-intro-v2.png
  4. Yordan Banev 2018-09-12

    [~michael] Yes.
  5. Samir Mohammed 2018-09-17

    *Closing ticket.* Verified fix in SDK Version: 7.5.0.v20180914153007. Button is now able to be disabled. *FR passed (Test steps):*

    Created a new Titanium application

    Added the code in the description above in to the app

    Ran the application

    Button was now disabled when the application was ran

    Changed the test case to match the test case in https://github.com/appcelerator/titanium_mobile/pull/10320

    Button properties seem to work as intended

    *Test Environment*
       APPC Studio: 5.1.0.201808080937
       APPC CLI: 7.0.7-master.1
       Nexus 6P (API 23)
       Operating System Name: Mac OS High Sierra
       Operating System Version: 10.13.6
       Node.js Version: 8.9.1
       
  6. Michael Gangolf 2018-09-23

    Hi [~ybanev], I was playing with 7.5.0 today and used and older project with a drag feature:
       var win = Ti.UI.createWindow({
       	backgroundColor: "white"
       });
       var view = Ti.UI.createView({
       	width: 150,
       	height: 300,
       	backgroundColor: "red",
       	borderRadius: 10,
       	touchEnabled: false
       })
       
       // setInterval(function(){
       // 	view.rotation +=1;
       // },100)
       //
       win.add(view);
       var sx = 0;
       var sy = 0;
       var cx = 0;
       var cy = 0;
       var dpi = Ti.Platform.displayCaps.logicalDensityFactor;
       var WIDTH = Ti.Platform.displayCaps.platformWidth / dpi;
       var HEIGHT = Ti.Platform.displayCaps.platformHeight / dpi;
       
       function onTouchStart(e) {
       	// start movement
       
       	console.log("start", e);
       
       	sx = e.x;
       	sy = e.y;
       
       	cx = e.x;
       	cy = e.y;
       }
       
       function onTouchMove(e) {
       	var xDistance = cx - sx;
       	var yDistance = cy - sy;
       
       	var rotationStrength = Math.min(xDistance / (WIDTH), 1);
       
       	var rotationAngel = (2 * Math.PI * rotationStrength / 16);
       
       	var rotationStrengthX = Math.min(yDistance / (HEIGHT), 1);
       	var rotationAngelX = (2 * Math.PI * rotationStrengthX / 16);
       
       	var scaleStrength = 1 - Math.abs(rotationStrength) / 4;
       	var scale = Math.max(scaleStrength, 0.93)
       
       	view.rotation = rotationAngel * 20;
       
       	view.rotationX = rotationAngelX * 20;
       	view.translationX = xDistance;
       	view.setTranslationY(yDistance);
       	view.scaleX = scale;
       	view.scaleY = scale;
       
       	cx = e.x;
       	cy = e.y;
       }
       win.addEventListener("touchmove", onTouchMove);
       win.addEventListener("touchstart", onTouchStart);
       win.open();
       
    With 7.4.0.GA it is working fine, with 7.5.0 the disabled view (touchEnabled:false) is still appearing in the touchstart event of the window. The console.log shows two elements (window and view). While I can work around that issue and use the coordinates from the correct source it would bring some changes to existing apps.

JSON Source