Skip to content

Instantly share code, notes, and snippets.

@yomybaby
Last active December 24, 2015 05:09
Show Gist options
  • Save yomybaby/6748765 to your computer and use it in GitHub Desktop.
Save yomybaby/6748765 to your computer and use it in GitHub Desktop.
How to add a Alloy custome formFactor

since 1.4.x, Alloy has the ability to use a custom query to determine if a style should be applied or not.

See also:



How to add a Alloy custome formFactor

If you want add custom formFactor, follow below steps.

  • add condition styler.js
    (/usr/local/lib/node_modules/alloy/Alloy/commands/compile)

      // line 379
      if (q.formFactor === 'tablet') {
          conditionals.formFactor = 'Alloy.isTablet';
      } else if (q.formFactor === 'handheld') {
          conditionals.formFactor = 'Alloy.isHandheld';
      }else if (q.formFactor === 'ios7') {
          conditionals.formFactor = 'Alloy.isiOS7';
      }
    
  • add condition compilerUtils.js
    (/usr/local/lib/node_modules/alloy/Alloy/commands/compile)

      // line 45
      exports.CONDITION_MAP = {
           handheld: {
                runtime: "!Alloy.isTablet"
           },
           tablet: {
                runtime: "Alloy.isTablet"
           },
           ios7 : {
                runtime: "Alloy.isiOS7"
           }
      };
    
  • add condition alloy.js on your project

    Alloy.isiOS7 = Ti.Platform.name == 'iPhone OS' && parseInt(Ti.Platform.version)==7;

Done! Now you can use like this :

on View

<View formFactor="ios7"></View>

on Style

"View[formFactor=ios7]":{
    	visible : false
    }  
@jhaynie
Copy link

jhaynie commented Sep 29, 2013

Definitely something we need to enable without modification of source

@yomybaby
Copy link
Author

Yes, It's very helpful to remove duplicated conditions in Alloy controller.

@yomybaby
Copy link
Author

@jhaynie I made what you say! ;)
tidev/alloy#263

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment