FokkeZB / nl.fokkezb.loading

The widget provides a simple loading mask that can be easily styled and configured.
93 stars 18 forks source link

can't show the loader in an commonjs module #30

Closed navidmirzaie closed 8 years ago

navidmirzaie commented 8 years ago

Hi Fokke , great widget you have here, much better then the default indicator. I only have a question i red your documentation but i couldn't figure out how to use it. I want to add the indicator in my module but i couldn't figure out how to do it.

Ive made the global loading var in Alloy like you mentioned: Alloy.Globals.loading = Alloy.createWidget("nl.fokkezb.loading");

But when i want to show the progress bar in my module it doesn't show up. Below example of my code.

FacebookBtn.js

  'use strict';

var FBLoginButton = (function () {

    var fb = Alloy.Globals.facebook;

    var User = require('User');
    fb.permissions = [''];

    //constructor
    function FBLoginButton(win) {

        this.window = win;

        //Create the button
        this.facebookButton = Ti.UI.createButton({
            backgroundImage:'images/facebooklogin.png',
            width:298,
            height:45,
            bottom:'20%'
        });

        this.overlay = Ti.UI.createView({
            backgroundColor:'#000',
            width:80,
            height:80,
            top:250,
            borderRadius:10,
            opacity:0.75,
            visible:false
        });

        //THIS CODE DOESN'T WORK
                var myInstance = Alloy.createWidget('nl.fokkezb.loading', 'window');
        myInstance.show('My message', myCancelCallback);

        win.add(this.facebookButton);
        this.attachEvents();

    }

Im using the above code in the following js file: register.js


function init(){

    $.window.removeEventListener('open', init);

    var brand = Titanium.UI.createImageView({
    image:"images/fonk_logo.png",
        top:170,
        width:'50%',
        height:'auto',
    });

    var fbButton = new FacebookButton(window);
    window.add(brand);

}

It would be great if i can get some help from you. Tnx in advanced.

FokkeZB commented 8 years ago

Although..

        var myInstance = Alloy.createWidget('nl.fokkezb.loading', 'window');
        myInstance.show('My message', myCancelCallback);

Looks fine and should work https://github.com/FokkeZB/nl.fokkezb.loading/blob/master/controllers/window.js#L63

If you already have a global instance like you said

Alloy.Globals.loading = Alloy.createWidget("nl.fokkezb.loading");

Then why not just do:

Alloy.Globals.loading.show('My message', myCancelCallback);
navidmirzaie commented 8 years ago

I Already got it working on with the view way. In register js i required the widget and made the global var that refrenced the instance of the widget and in the facebookbtn called it.

I checked your source and the way you documented should indeed work. But i think it is because i have a modal window.

Tnx Fokke.

FokkeZB commented 8 years ago

Yes indeed, in a modal window you need the view, since no window will open over a modal one.