Titanium JIRA Archive
Alloy (ALOY)

[ALOY-871] Custom TSS device queries

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-05-07T15:57:07.000+0000
Affected Version/sn/a
Fix Version/sAlloy 1.4.0
ComponentsSamples & Templates
Labelsnotable, qe-testadded
ReporterDavid Bankier
AssigneeTim Poulsen
Created2013-10-30T22:47:45.000+0000
Updated2014-05-29T05:02:20.000+0000

Description

Currently alloy supports the tablet and handheld platform types. It would be nice if users could define custom platform types. For example a user could define in the alloy.js file
exports.isSmalltablet = function() {
  return OS_ANDROID &&Ti.Platform.Android.physicalSizeCategory ===  Ti.Platform.Android.PHYSICAL_SIZE_CATEGORY_LARGE
}
and then use
platform=smalltablet
in the xml and tss files.

Comments

  1. David Bankier 2013-10-30

    Tony, I'm happy to work on it if you back the idea.
  2. Malcolm Hollingsworth 2013-10-31

    Vote from me.
  3. David Bankier 2013-10-31

    Only just saw this: https://github.com/appcelerator/alloy/pull/263 Guess I'm a day late...
  4. Tony Lukasavage 2013-11-01

    [~mrahman] who is the original reporter of this issue? Can you please note that in situations where you don't preserve it? [~dbankier] and [~core13] since the conversation already started in that PR, please continue any more feedback there. My opinion is that I like the idea of opening up conditionals in the TSS/XML, but definitely not with the platform keyword. platform has a specific meaning, and is unique in that unlike formFactor, platform is processed at compile time. As I stated in the github PR, I suggested a new field, like condition. We'll continue the conversation there.
  5. Malcolm Hollingsworth 2013-11-01

    @Tony - I really like the idea of the new condition field, will say the same thing in the PR.
  6. David Bankier 2013-11-02

    Sorry Tony, my original suggestion was meant to be on form factor but I like the if property on a Alloy.Global constant like you suggested in the PR.
  7. Tim Poulsen 2014-03-28

    PR: https://github.com/appcelerator/alloy/pull/355 Functional test:

    Build the associated app for the iOS simulator.

    Compare the styles applied to the label to the rules defined in styles/index.tss

    From the simulator's Hardware menu, choose Device, then a different device to emulate.

    Once the simulator restarts, open the app again. Again, compare the styles applied to those defined.

    The if rules take precedence over other rules.
  8. Fokke Zandbergen 2014-03-29

    Thx [~skypanther]! Some questions/ideas though: *-if=-* Looking at the code I understand why, but from the user/dev/syntax perspective I find the if= prefix confusing and unneeded. I mean, all conditionals *are* essentially if's: *if*[platform=ios], so when combining them you get: *if*[platform=ios,if=Alloy.Globals.ios7]. Why not just accept [platform=ios,Alloy.globals.ios7]. For the compiler, finding no = simply means assuming what is now done as if=. *XML* I don't see an implementation for supporting these custom conditionals in the XML. Is that coming as well? *CONSTANT_IOS7* Same for the controllers. I know this is more challenging. What about the following idea for both the TSS, XML and JS: Instead of Alloy.Globals.\* introduce a specific namespace like Alloy.Constants.\*. In the TSS and XML skip the if= and just accept Alloy.Constants.*. In the JS accept CONSTANT_IOS7 for Alloy.Constants.iOS7.
  9. Tim Poulsen 2014-03-31

    I need a key/name to hook into in the styler.js script. Discussion on the original PR identified "if" as the preferred choice. There's an appeal to something like [ios,Alloy.globals.ios7] or [tablet,ios]. But we'd still need an attribute name in XML. Feel free to file a separate feature request. XML - I'll amend my PR to accept the conditionals in the XML as well. CONSTANT_IOS7 - Since we already have one global object (Alloy.Globals), I don't see an advantage to adding another (Alloy.Constants) plus a varying set of aliases (CONSTANT_IOS7).
  10. Fokke Zandbergen 2014-04-01

    You got me on the attribute name for XML. You are also right that in the controller you could just use Alloy.Globals.myCondition and since these are variables only known at run-time the compiler could not strip the code anyway, so forget about that too ;) Just the XML plz :)
  11. Tim Poulsen 2014-04-01

    PR updated to handle XML now. The functional test app included in the PR now has an XML element demonstrating the new if attribute.
  12. Tim Poulsen 2014-05-07

    PR for ALOY-1004 updates the sample apps for this ticket along with the advanced/custom_tss_queries sample. That PR has been merged, resolving this ticket.
  13. Federico Casali 2014-05-07

JSON Source