Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9169489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:53:11+00:00 2026-06-17T15:53:11+00:00

I’m working on a mid-size Appcelerator Titanium app. I want to extend the Ti.UI

  • 0

I’m working on a mid-size Appcelerator Titanium app. I want to extend the Ti.UI object, and I am wondering if this is safe.

What I want to do
Store a number of UI-related helper functions and objects as part of the Ti.UI tree.

A trivial example would be:

Ti.UI.COLORS = {
    RED: '#213234',
    BLUE: '#ABDCEF'
}

My big concern is that this may be unsafe or just not future-proof.

Why I want to do it
I’ve had bad experiences with Titanium’s JSS and I am currently storing and retrieving my files in a CSS.js file. This file bundles a few functions and objects that make styling easier (like the colors example above), and combines them with a big long list of style classes, stored as objects. The classes make use of the helper functions.

Like so:

//Provide helper functions
COLORS = { RED: 'etc' };
IOS_ANDROID = function(iosValue,androidValue){ 
    if (Device.isIOS) {

        return iosValue
    } else {
        return androidValue
    };

//Provide the styles as exports object (using commonJS)
exports.styles = {
    winHome: {
        backgroundColor: COLORS.RED
    },
    winProducts: {
        navBarHidden: IOS_ANDROID(true,false),
    }
}

Now that my app has grown, the size of this styles object is getting annoying. I am trying to split the styles into several .js files and combine them (and the necessary functions) using includes and requires. So I now have a ‘css-Home.js’, ‘css-Products.js’, etc.

This works, sort of, but I currently need to re-include/require the helper functions in every css-.js file. This feels awkward. I am trying to be strict in the CommonJS practice of only using require() and not doing include(). However, if I use require() to add the helper functions, like so…

var cssHelpers = require('css-helpers.js')

…then I would need to prefix all the helpers with that variable, like so…

exports.styles = {
    winHome: { 
        backgroundColor: cssHelpers.COLORS.RED,
    },
}

That’s why I would like to put these basic things into Ti.UI during the app’s initialization. Then I’ll have the style helper functions available wherever.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:53:11+00:00Added an answer on June 17, 2026 at 3:53 pm

    I found a decent solution that doesn’t involve altering Ti.UI. The cue came from trying to run the app on Android and finding that it passes even fewer variables between different parts. So I needed to dig deeper into the CommonJS principles and the meaning of require() and Ti.include().

    The trick to not having to prefix my CSS helpers with their parent’s name is as follows:

    1. Require a CSS-helpers.js file in the file where you need the helper functions.
    2. Have CSS-helper.js’s exports object return just one function.
    3. Execute the function immediately after requiring. Like so:

      //Include CSS helper functions as local variables
      require(‘shared/css-helpers’)();

    4. In the one exports function of CCS-helpers, use the ‘this’ variable to apply functions directly to the js context where globals is included:

      exports = function(){
      this[‘IOS_ANDROID’] = function(ios,android){ etc };
      this[‘otherHelperFunction’] = function(){};
      }

    Now, in the file where CSS-helpers was included, you can use the helper functions like IOS_ANDROID() without any prefix. That’s because the ‘this’ variable in CSS-helpers points to the context that called the function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm interested in microtypography issues on the web. I want a tool to fix:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.