iskugor / Ti.SwipeRefreshLayout

Titanium module for Android's SwipeRefreshLayout.
56 stars 19 forks source link

Use alloy on both platforms without needing to use require or duplicating XML - a new solution #7

Closed TinyGiantDigital closed 9 years ago

TinyGiantDigital commented 9 years ago

Hi, this is more of a new solution than an issue!

I was getting frustrated with duplicating my xml code just so that i could wrap it in <SwipeRefresh> for Android, also using 'Require' to pull in the code was proving messy. The solution was simpler than I thought... simply 'remove' the ListView from the display before then adding it to the swipeRefresh module.

Consider the following:

<Alloy>
    <View id="main">
        <ListView id="scrollContent">
           // my content
        </ListView>
    </View>
</Alloy>

In your controller you can do this:

if (OS_ANDROID){
    var swipeRefreshModule = require('com.rkam.swiperefreshlayout');

    $.main.remove($.scrollContent);   // application crashes without this line

    var swipeRefresh = swipeRefreshModule.createSwipeRefresh({
        view:   $.scrollContent,
        height: Ti.UI.FILL,
        width:  Ti.UI.FILL
    });
    $.main.add(swipeRefresh);
}

Hope this helps some people!

iskugor commented 9 years ago

Thanks. Although I would prefer to stick to standard practice since ListView can be anywhere in view hierarchy and therefore re-adding does not necessary produce same result.