Common Js module for activity Indicator

You must Login before you can answer or comment on any questions.

Hi, How to create a common module for activity indicator using exports in some file and use it through require('relative path').func() to call hide/show methods, wherever its required through out the app. Instead of using Ti.App.fireEvent or Ti.include('activity.js') in all files, how to achieve a common module which can be effectively used in Ipad/iphone. help me out with a snippet.

2 Answers

This is how I'm using it. Any suggestion is welcome.

utilities.js :

function loadingWindow() {
    // window container
    var self = Ti.UI.createWindow({
        height:80,
        width:200,
        touchEnabled:false
    });
 
    var activityIndicator = Ti.UI.createActivityIndicator({
        message : L("loading_data"),
        color : 'white',
        height : 50,
        width : 10,
        font : {fontSize:18,fontWeight:'bold'},
        touchEnabled:false
    });
    activityIndicator.show();
 
    var transparentView = Ti.UI.createView({
        height:80,
        width:200,
        backgroundColor:'#000',
        borderRadius:10,
        opacity:0.75,
        touchEnabled:false
    });
 
    self.add(transparentView);
    self.add(activityIndicator);
 
    return self;
};
exports.loadingWindow = loadingWindow;
And to use it
var loadingWindow = utilities.loadingWindow();
The Loading window will be shown immediately.

So, when you want to hide it you need to use:

loadingWindow.hide();
And whenever you need to show it again.
loadingWindow.show();
I hope that helps.

— answered 1 year ago by Cesar Estrada
answer permalink
3 Comments
  • You need to require the utilities.js before you can call it.

    Mine is inside a folder called services:

    var utilities = require('/services/utilities');
    Before you can use it.

    — commented 1 year ago by Cesar Estrada

  • Thanks Cesar

    — commented 1 year ago by karthi keyan

  • You are welcome!

    — commented 1 year ago by Cesar Estrada

Your Answer

Think you can help? Login to answer this question!