Ti.SwipeRefreshLayout icon indicating copy to clipboard operation
Ti.SwipeRefreshLayout copied to clipboard

App Crash using Alloy TableView when .add SwipeRefresh to main window

Open n2bSolutions opened this issue 10 years ago • 5 comments

Hello,

When i try to $.tableWrapper.add(swipeRefresh) application crash !!

The View :

<View id="tableWrapper">
            <TableView id="container" filterAttribute="indice">
                <RefreshControl platform="ios" id="ptr" tintColor="black" onRefreshstart="ptrRelease"/>
                <SearchBar id="barraDeBusqueda" platform="ios,android"></SearchBar>                 
            </TableView>
</View>
</code>

The Controller:

if(Ti.Platform.name == "android") {
    var swipeRefreshModule = require('com.rkam.swiperefreshlayout');
    var swipeRefresh = swipeRefreshModule.createSwipeRefresh({
        view: $.container, // el id de la tableView
        height: Ti.UI.FILL,
        width: Ti.UI.FILL
    });

    //$.scroll.add(swipeRefresh);
    $.tableWrapper.add(swipeRefresh); ---> Crash the App :-/
}

Appcelerator 3.3.0 Alloy 1.4.0 ...

Any Ideas?

Thxs a lots!

n2bSolutions avatar Sep 05 '14 10:09 n2bSolutions

Same here. I'd like to use it withe tableView, too.

sakae-nakajima avatar Sep 08 '14 23:09 sakae-nakajima

@n2bSolutions @sakae-nakajima Have you tried it with a dynamically created TableView using JavaScript? I'm not sure if it works with Alloy XML.

raymondkam avatar Sep 08 '14 23:09 raymondkam

Yes, that's how I am trying to use.

var tableView = Ti.UI.createTableView(options); var swipeRefreshModule = require('com.rkam.swiperefreshlayout'); var swipeRefresh = swipeRefreshModule.createSwipeRefresh({ view: tableView, height: Ti.UI.FILL, width: Ti.UI.FILL }); tableView.addEventListener("postlayout", function handler() { tableView.removeEventListener("postlayout", handler); tableView.getParent().add(swipeRefresh); // tableView.getParent() is window });

This is what I get: [ERROR] : TiApplication: (main) [4766,4766] Sending event: exception on thread: main msg:java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.; Titanium 3.3.0,2014/07/11 12:36,787cd39 [ERROR] : TiApplication: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. [ERROR] : TiApplication: at android.view.ViewGroup.addViewInner(ViewGroup.java:3378) [ERROR] : TiApplication: at android.view.ViewGroup.addView(ViewGroup.java:3249) [ERROR] : TiApplication: at android.view.ViewGroup.addView(ViewGroup.java:3194) [ERROR] : TiApplication: at android.view.ViewGroup.addView(ViewGroup.java:3170) [ERROR] : TiApplication: at com.rkam.swiperefreshlayout.SwipeRefresh.processProperties(SwipeRefresh.java:66)

sakae-nakajima avatar Sep 09 '14 00:09 sakae-nakajima

Ok, I now know the reason for the crash.

I was using Alloy to add the table, then passing the table to the swipeRefreshLayout as a value for the view attribute. Looking at the source code, I noticed that this was the root cause.

As you pointed out, creating the table in JS and passing it to the swipeRefreshLayout works fine. Note that the table will be added to the swipeRefreshLayout by the module, so don't add it to a parent by yourself!

Now, the following request makes sense to those who are familiar with Alloy way:
https://github.com/raymondkam/Ti.SwipeRefreshLayout/issues/3

Thank you for your great job!

sakae-nakajima avatar Sep 09 '14 09:09 sakae-nakajima

For those who like to stick with Alloy, this is a workaround until we have #3 become available.

    tableView.addEventListener("postlayout", function handler() {
        tableView.removeEventListener("postlayout", handler);
        // removes the table view from window
        var parent = tableView.getParent();
        parent.remove(tableView);
        // creates refresh control
        var swipeRefreshModule = require('com.rkam.swiperefreshlayout');
        var swipeRefresh = swipeRefreshModule.createSwipeRefresh({
            view: tableView,
            zIndex: tableView.zIndex,
            backgroundColor: tableView.backgroundColor,
            height: tableView.height,
            width: tableView.width,
            // or whatever you like to inherit
        });
        swipeRefresh.addEventListener('refreshing', function () {
            console.log('Hoy');
        });
        // adds it
        parent.add(swipeRefresh);
    });

sakae-nakajima avatar Sep 09 '14 09:09 sakae-nakajima