[ALOY-871] Custom TSS device queries
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-05-07T15:57:07.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Alloy 1.4.0 |
Components | Samples & Templates |
Labels | notable, qe-testadded |
Reporter | David Bankier |
Assignee | Tim Poulsen |
Created | 2013-10-30T22:47:45.000+0000 |
Updated | 2014-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.
Tony, I'm happy to work on it if you back the idea.
Vote from me.
Only just saw this: https://github.com/appcelerator/alloy/pull/263 Guess I'm a day late...
[~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 unlikeformFactor
,platform
is processed at compile time. As I stated in the github PR, I suggested a new field, likecondition
. We'll continue the conversation there.@Tony - I really like the idea of the new
condition
field, will say the same thing in the PR.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.
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.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* essentiallyif
'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 asif=
. *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 ofAlloy.Globals.\*
introduce a specific namespace likeAlloy.Constants.\*
. In the TSS and XML skip theif=
and just acceptAlloy.Constants.*
. In the JS acceptCONSTANT_IOS7
forAlloy.Constants.iOS7
.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).
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 :)PR updated to handle XML now. The functional test app included in the PR now has an XML element demonstrating the new if attribute.
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.