Search code examples
titaniumtitanium-mobiletitanium-alloy

In Alloy Titanuim, How to close widget's parent window


I have a widget that contain a back button, when click that back button i want to close the window that having the widget (parent window). here is my widget.xml :

<Alloy>
    <View id="topBar">
        <View id="leftItems">
            <ImageView id="backIcon" onClick="previousPage" />
            <ImageView id="logo" />
        </View>
        <View id="midItems">
            <Label id="pageTitle"></Label>
            <ImageView id="searchIcon" onClick="searchIcon" platform="ios" />
            <SearchBar id="searchBar" platform="ios" />
            <SearchView id="searchView" ns="Ti.UI.Android" platform="android" onBlur="pageTitleVisiability" onFocus="pageTitleVisiability" />
        </View>
        <View id="rightItems">
            <ImageView id="createIcon" onClick="createPost" />
        </View>
    </View>
</Alloy>

and in widget.js :

function previousPage(argument) {
    // closing the window
}

i tried to send the custom property in the widget with the window name like this:

Alloy.createController('windowName').close();

but it says that the window is not opened


Solution

  • You can't create the controller in the widget and try to close it, you are creating a new instance of the window, not referencing the calling controller. I would use messaging to perform the close. Inside you previousPage function, add "$.trigger('closeParent');" to signal to close the window. Then inside the calling window (where the widget is referenced) add something like "$..on('closeParent', );" and then close the window in the function. I hope that makes sense.