Ti.SwipeRefreshLayout
Ti.SwipeRefreshLayout copied to clipboard
App Crash using Alloy TableView when .add SwipeRefresh to main window
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!
Same here. I'd like to use it withe tableView, too.
@n2bSolutions @sakae-nakajima Have you tried it with a dynamically created TableView using JavaScript? I'm not sure if it works with Alloy XML.
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)
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!
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);
});