Custom Rules
Custom rules in PurgeTSS let you style Titanium elements, IDs, and classes in config.cjs. You can also target specific platforms, devices, or conditional blocks using global variables.
This is handy when a project spans iOS and Android and you want to keep styles in one place.
Classes, IDs, and Ti Elements
You can style any Ti Element, IDs, or your own classes with as many attributes as needed. You can also target specific platforms, devices, or add conditional blocks with global variables.
Whether you want to style a Ti Element (also known as a markup element), a custom ID prefixed with a hash (#), or a custom class prefixed with a period (.), the structure is the same.
Modifier key
- For Titanium Elements, use the exact name of the element, such as
Label,Button, orScrollView. - For IDs, use
camelCaseto match the JavaScript convention. - For classes, use
kebab-caseto stay compatible with PurgeTSS v6.x and above. For example, use.my-custom-class-nameinstead of.myCustomClassName.
If your project started on PurgeTSS v5 or earlier and you now use 7.x.x or later, set purge.options.missing to true in config.cjs. It will report missing classes at the end of app.tss so you can update them to the new naming convention.
Default, Platform, Device, or Conditional blocks
- To generate a global style, use either the lowercase
defaultor the uppercaseDEFAULTkeyword. - To target a specific platform, use the
iosorandroidkeywords. - To target a specific device, use the
tabletorhandheldkeywords. - To target a condition with a global variable, use the
[if=globalVariableName]keyword.
Property Values
- For
Titaniumconstants,Alloy Configuration Values, orGlobal Variables, always enclose them in quotes. - For
colorvalues, you can usehex,8-digit hex,rgb(R,G,B),rgba(R,G,B,A),transparent, or any of the standard color names. Use hex values if you want to avoid issues with the opacity modifier. - For
spacingvalues, you can use different types of units:em,rem,%,px,dp,cm, orin.%,px,cm, orinare passed through without conversion.emorremvalues are converted with this formula:value * 16.dpremoves the unit and keeps the value as-is.
config.cjs file example
module.exports = {
theme: {
'#main-banner': {
DEFAULT: {
width: '300px',
height: '80px'
},
ios: {
clipMode: 'Ti.UI.iOS.CLIP_MODE_DISABLED'
}
},
'.gallery': {
DEFAULT: {
height: 'Ti.UI.SIZE'
},
ios: {
clipMode: 'Ti.UI.iOS.CLIP_MODE_ENABLED'
},
android: {
hiddenBehavior: 'Ti.UI.HIDDEN_BEHAVIOR_GONE'
},
handheld: {
width: '250px'
},
tablet: {
width: '500px'
}
},
TextField: {
DEFAULT: {
top: 10,
left: 20,
right: 20,
bottom: 0
},
'[if=Alloy.Globals.iPhoneX]': {
bottom: 'Alloy.CFG.iPhoneXNotchSize'
},
android: {
touchFeedback: true
}
},
}
};
/* Property: TextField */
/* Description: A single line text field. */
'TextField': { top: 10, left: 20, right: 20, bottom: 0 }
'TextField[if=Alloy.Globals.iPhoneX]': { bottom: Alloy.CFG.iPhoneXNotchSize }
'TextField[platform=android]': { touchFeedback: true }
/* Custom Classes */
'#main-banner': { width: '300px', height: '80px' }
'#main-banner[platform=ios]': { clipMode: Ti.UI.iOS.CLIP_MODE_DISABLED }
'.gallery': { height: Ti.UI.SIZE }
'.gallery[platform=ios]': { clipMode: Ti.UI.iOS.CLIP_MODE_ENABLED }
'.gallery[platform=android]': { hiddenBehavior: Ti.UI.HIDDEN_BEHAVIOR_GONE }
'.gallery[formFactor=handheld]': { width: '250px' }
'.gallery[formFactor=tablet]': { width: '500px' }
...