Topener / nl.fokkezb.pullToRefresh

Widget to implement a table pull-to-refresh header in Titanium Alloy
184 stars 60 forks source link

ScrollableView in combination with pull to refresh crashes on Android #32

Closed yhanssens closed 9 years ago

yhanssens commented 9 years ago

In my app I have a ScrollableView with three pages. Each of those pages contain a TableView which you can pull to refresh. This works perfectly on iOS unfortunately when I switch pages a couple of times on Android it always seems to crash.

FokkeZB commented 9 years ago

Which version of the widget are you using?

What is the crash log?

yhanssens commented 9 years ago

I've installed the widget using gittio so I'm presuming the latest version.

[DEBUG] : AndroidRuntime: Shutting down VM [WARN] : dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa61f1908) [ERROR] : TiApplication: (main) [26492,26492] 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.4.1,2014/11/13 13:33,5982e8f [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:3339) [ERROR] : TiApplication: at android.view.ViewGroup.addView(ViewGroup.java:3210) [ERROR] : TiApplication: at android.view.ViewGroup.addView(ViewGroup.java:3155) [ERROR] : TiApplication: at android.view.ViewGroup.addView(ViewGroup.java:3131) [ERROR] : TiApplication: at com.rkam.swiperefreshlayout.SwipeRefresh.processProperties(SwipeRefresh.java:67) [ERROR] : TiApplication: at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:1185) [ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:500) [ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:491) [ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:469) [ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:507) [ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:491) [ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:469) [ERROR] : TiApplication: at ti.modules.titanium.ui.widget.TiUIScrollableView$ViewPagerAdapter.instantiateItem(TiUIScrollableView.java:516) [ERROR] : TiApplication: at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:110) [ERROR] : TiApplication: at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:832) [ERROR] : TiApplication: at android.support.v4.view.ViewPager.populate(ViewPager.java:1016) [ERROR] : TiApplication: at android.support.v4.view.ViewPager.populate(ViewPager.java:914) [ERROR] : TiApplication: at android.support.v4.view.ViewPager$3.run(ViewPager.java:244) [ERROR] : TiApplication: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) [ERROR] : TiApplication: at android.view.Choreographer.doCallbacks(Choreographer.java:562) [ERROR] : TiApplication: at android.view.Choreographer.doFrame(Choreographer.java:531) [ERROR] : TiApplication: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) [ERROR] : TiApplication: at android.os.Handler.handleCallback(Handler.java:725) [ERROR] : TiApplication: at android.os.Handler.dispatchMessage(Handler.java:92) [ERROR] : TiApplication: at android.os.Looper.loop(Looper.java:137) [ERROR] : TiApplication: at android.app.ActivityThread.main(ActivityThread.java:5041) [ERROR] : TiApplication: at java.lang.reflect.Method.invokeNative(Native Method) [ERROR] : TiApplication: at java.lang.reflect.Method.invoke(Method.java:511) [ERROR] : TiApplication: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) [ERROR] : TiApplication: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) [ERROR] : TiApplication: at dalvik.system.NativeStart.main(Native Method) -- End application log -------------------------------------------------------

FokkeZB commented 9 years ago

Could you also paste the code to show how you implemented the widget and the callback for the refresh?

yhanssens commented 9 years ago

Created this project as a test:

index.xml

<Alloy>
    <Window class="container">
        <View id="tabHolder" class="tabHolder">
            <View class="tab" index="0" backgroundColor="#fff"><Label>Table 1</Label></View>
            <View class="tab" index="1" backgroundColor="#ddd"><Label>Table 2</Label></View>
            <View class="tab" index="2" backgroundColor="#aaa"><Label>Table 3</Label></View>
        </View>
        <ScrollableView id="scroll">
            <View backgroundColor="#fff"><Require src="tableview"></Require></View>
            <View backgroundColor="#ddd"><Require src="tableview"></Require></View>
            <View backgroundColor="#aaa"><Require src="tableview"></Require></View>
        </ScrollableView>
    </Window>
</Alloy>

tableview.xml

<Alloy>
    <Widget id="ptr" src="nl.fokkezb.pullToRefresh" onRelease="myRefresher">
        <TableView>
            <TableViewRow title="row1"></TableViewRow>
            <TableViewRow title="row2"></TableViewRow>
            <TableViewRow title="row3"></TableViewRow>
            <TableViewRow title="row4"></TableViewRow>
            <TableViewRow title="row5"></TableViewRow>
            <TableViewRow title="row6"></TableViewRow>
            <TableViewRow title="row7"></TableViewRow>
            <TableViewRow title="row8"></TableViewRow>
            <TableViewRow title="row9"></TableViewRow>
            <TableViewRow title="row10"></TableViewRow>
        </TableView>
    </Widget>
</Alloy>

index.js

function doClick(e) {
    alert($.label.text);
}

$.tabHolder.addEventListener('click', function (e)
{
    var index = (typeof e.source.index !== 'undefined') ? e.source.index : e.source.getParent().index;
    $.scroll.currentPage = parseInt(index);
});

$.index.open();

tableview.js

function myRefresher(e) {
   setTimeout(function ()
   {
        e.hide();
   }, 2000);
}
FokkeZB commented 9 years ago

Well, the key of the problem is:

[ERROR]  .. The specified child already has a parent

I think you'll have to add a bunch of listeners on different spots in and around the widget to track this baby. Can't help you much with that I'm afraid.

If you find it is a widget bug, please reopen.

dzHamid commented 8 years ago

I have the same issue Mr @FokkeZB. Any solution please !

yhanssens commented 8 years ago

@dzHamid I solved my problem by not using this widget anymore but instead use the module Fokke uses in his widget: https://github.com/raymondkam/Ti.SwipeRefreshLayout directly. Then there shouldn't be a problem :-)

dzHamid commented 8 years ago

thank you @joertler 💃