Opening and closing of a modal popup.

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

Hi All,

I have to make a modal popup in one of my app. Where I have added a new window with a black background with opacity. And added a view to that window to show the custom message. Here is my code block.

exports.modalWin = function(){
    var popupWin = Ti.UI.createWindow({
        backgroundColor : 'black',
        opacity         : 0.5,
        fullscreen      : true
    });
 
    var popupView = Ti.UI.createView({
        width   : 200,
        height  : 100,
        backgroundColor : 'white',
        borderRadius : 5,
        borderColor : 'red',
        borderWidth : 3
    });
    popupView.add(Ti.UI.createLabel({ width : 150, height : 'auto', top : 10 ,
                                    text : 'This is Modal Window', backgroundColor : 'green',
                                    font  : { fontSize : 14, fontWeight : 'bold'}}));
 
    popupWin.add(popupView);
 
    popupWin.addEventListener('click', function(e){ popupWin.close()});
 
    return popupWin;
};
Now my issues is that, I have a window click event which will close the popup window. But If click on the view resides within that window, the window should not closed. I have tested the above code in android.

Please point me if I am wrong anywhere.

1 Answer

what you can do you can add an click eventListener on your view or that window on which the popup is coming. write the popupWin.close code in there.

so when you touch the view or window the popup will also close.

— answered 9 months ago by Ajeet pratap Maurya
answer permalink
7 Comments
  • Hello Ajeet, Currently I am able to close the popup window, if I click on window or view as you have told with that above code. But actually what I need is, If I click on the view it should not close the window.

    Please suggest ...

    — commented 9 months ago by Raju Mahato

  • The view you are talking about is popupView in your above code?? or its a different view.

    If you dont want to hide the popup on view click hen don't add the click event listener to that view..

    — commented 9 months ago by Ajeet pratap Maurya

  • is your problem is solved??

    — commented 8 months ago by Ajeet pratap Maurya

  • Show 4 more comments

Your Answer

Think you can help? Login to answer this question!