Titanium JIRA Archive
Alloy (ALOY)

[ALOY-911] touchEnabled property in Alloy xml crashes on Android with Titanium SDK 3.2.0.GA

GitHub Issuen/a
TypeImprovement
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2014-02-05T18:40:35.000+0000
Affected Version/sn/a
Fix Version/sAlloy 1.4.0, 2014 Sprint 03
ComponentsXML
Labels3.2.0, alloy, android, qe-testadded, touchEnabled, xml
ReporterMatt Moskal
AssigneeTim Poulsen
Created2013-12-27T10:33:20.000+0000
Updated2014-05-08T02:54:32.000+0000

Description

This code crashes on Android (not iOS): // From console: Caused by: java.lang.ClassCastException: java.lang.String However, touchEnabled works properly when set in tss styling. So current work- around is to create a class in app.tss that can be called to set the touchEnabled property.

Comments

  1. Tony Lukasavage 2013-12-30

    Changing this to an "improvement" rather than a "bug". XML attributes contain strings, pure and simple. The reason this works on iOS is that iOS does a type conversion from string to boolean. Android does not, and fails with the string exception. This could actually be fixed at the platform-level to have Android perform type conversions, but I'll instead modify it in Alloy to make things easier. Long story short, if you want to assign a non-string property to a view in Alloy, the safest, cross-platform way to do so is with the actual types in TSS, not trying to coerce types in the XML attributes, which are always strings.
  2. Matt Moskal 2013-12-30

    Yes, I agree , but .... 1) I have not come across any other true/false attributes that could not be set in XML for Android. 2) Prior to 3.2.0, touchEnabled could be set in XML for Android. It took me quite a while to isolate the issue that apps were crashing because of this change in behavior - made harder to isolate/find because other true/false attributes were being set for the very same View in XML, and those other attributes worked fine. In fact the only reason I found this was because I ran across a thread that mentioned a past issue of touchEnabled causing app crashes when set in TSS (not XML). Not sure the right answer. But because true/false attributes are so common and so many, it seems rather cumbersome to set every one in TSS when needed. Is there not some way to have "true" and "false" strings in XML interpreted as boolean values?
  3. Tony Lukasavage 2013-12-30

    [~matt_m] No, there is no true non-string values in XML attributes. The attributes in XML, by definition, are strings. That said, in certain situations Alloy can workaround this by explicitly coercing string values to different types. Whether or not other properties in Android handle this coercion automatically or not has nothing to do with Alloy's XML. It has to do with whether or not these are handled by Titanium in its Android code. As I mentioned before, if you want the true root of this problem handled, log a ticket that doesn't show this as an Alloy-specific issue. Instead, show that this same situation occurs when you attempt to use a string for a boolean value in traditional titanium. Chances are you will get a response along the lines of "The API states that it is boolean, so that's what it expects." But you can at least make a case for a resolution at the platform level if you think it is compelling. In lieu of that, I can make tweaks in Alloy to try and make it handle it automatically.
  4. Tim Poulsen 2014-01-30

    PR: https://github.com/appcelerator/alloy/pull/316 test app: https://github.com/appcelerator/alloy/tree/master/test/apps/testing/ALOY-911 Functional test: 1. Run the app for Android 2. The app does not crash. The red View is not clickable. 3. Check the generated code and the touchEnabled property should equal the boolean false rather than the string 'false' 4. You can modify the XML to set and rebuild the app; view will be clickable and generated code has boolean true value
  5. Tim Poulsen 2014-02-04

    Reopening
  6. Tony Lukasavage 2014-02-05

    PR: https://github.com/appcelerator/alloy/pull/326 test app: https://github.com/appcelerator/alloy/tree/master/test/apps/testing/ALOY-911 Functional test should involve running the test app on android. It should look roughly like the screenshot (depending on emulator or device). Additionally, the rows should fire the click event, but the red footer at the bottom should not.
  7. Federico Casali 2014-05-08

    Verified working as expected. TiSDK 3.3.0.v20140507141712 Alloy 1.4.0-dev Appcelerator Studio 3.3.0.201405011408 CLI 3.3.0-dev Closing.

JSON Source