Titanium JIRA Archive
Alloy (ALOY)

[ALOY-719] Alloy Android feature request: view/style API level conditional code

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionDuplicate
Resolution Date2014-05-13T20:17:01.000+0000
Affected Version/sn/a
Fix Version/sAlloy 1.4.0
ComponentsRuntime, XML
Labelsalloy, android
ReporterMark Mokryn
AssigneeTony Lukasavage
Created2013-06-23T09:17:32.000+0000
Updated2014-05-13T23:33:40.000+0000

Description

For Android, there is often conditional UI code based on the presence/absence of Action Bar capabilities. I find myself doing this manually on very single window, and it's a chore (e.g. configure the action bar in my controller code, or set up an action bar lookalike for API <= 10).... It would be great to add to the "platform=..." flags something along the line of "android-api-lte10" and "android-api-gt10" for views and styles. Edit: the Android API level is determined at runtime, and the platform view/style attribute is used at build. So to generalize this request - what we really need is a runtime view/style conditional attribute, e.g. "condition = someVariable", where someVariable would be set at controller init, e.g. in my case it would be someVariable = Ti.Platform.Android.API_LEVEL <= 10 for a pre-Action Bar window header.

Comments

  1. Tony Lukasavage 2013-06-24

    [~mokesmokes] can you please include a proposed use case with code? I'd like to see the XML/JS you'd like this feature to encompass.
  2. Mark Mokryn 2013-06-24

    XML:
       <Alloy>
         <Window id="genericWin" class="container">
           <View id="fakeAndroidActionBar" platform="android" condition="preHoneycomb">
       ....
       
    controller code:
       if (OS_ANDROID) {
         var preHoneycomb = Ti.Platform.Android.API_LEVEL < 11;
       }
       
    I'm wondering if we need it in style files as well, in similar fashion. Not sure if it's a must, but perhaps it should be mirrored there, as done today for "platform". The use case I have today is indeed for Android Action Bars, where I like to have them where possible, and provide a view look-alike on 2.x. However, since this is done at runtime, why not just make it a generic conditional? Could be useful in many other cases as well.
  3. Mark Mokryn 2013-06-24

    Just a couple more thoughts.... the example above is a simple case where the condition is static, and can be evaluated at controller initialization. Another class of conditions (unrelated to this specific case) would be binding the creation/destruction of views to models.
  4. Tim Poulsen 2014-05-13

    [~mokesmokes] I think your request is at least partially resolved by ALOY-871. With that change, you can use the custom conditionals (with conditions defined in alloy.js as properties of Alloy.Globals) to accomplish the XML example you gave above. Those globals would also accomplish the controller code you show, though because those are evaluated at run time, non-matching branches can't be optimized out like the compile-time OS_* globals. Finally, Titanium 3.3 will include the AppCompat library to support the ActionBar on pre-ICS devices. Is there more to your request or could this be considered resolved by the other ticket and closed?
  5. Mark Mokryn 2014-05-13

    Awesome - yes, you can close this ticket. Thanks.
  6. Tim Poulsen 2014-05-13

    Resolved by ALOY-871 so closing this as a duplicate (yeah, this one came in first ...)

JSON Source