Swipe/Pull to refresh

simeonsimeon USMember ✭✭

Hi,

I have seen a few threads on the swipe/pull to refresh for updating listviews. I have looked and it all looks very promising on iOS but less so on Android.

In my implementation I have created an attached property (a bit like what I used to do in Silverlight to stop me having to subclass the control) that I can attach to a TableView for my "detail" page and ListView for my "master" page. This would let my users swipe the list of data and also the item that has been navigated to run an ICommand to update my data from the webserver. This all seems to work cool on iOS, made a few custom renderers that read the attached properties and hook everything up nice with UIRefreshControls added to the UITableView for both forms controls if needed.

But on Android I would like to use the Android.Support.V4.Widget.SwipeRefreshLayout as this container control should be used to give my Android users the Android style swipe (I am thinking like in GMail with the snazzy colors!) This would stop me from having to worry about the renderer for the listview on Android being protected as really it not up to the listview but more the SwipeRefreshLayout to do its thing...

So I have created a refreshable view control that I can use in my Xaml document to wrap my original content that derives from Xamarin.Forms.ContentView, a custom render that creates the Android.Support.V4.Widget.SwipeRefreshLayout for my new content control and I can use my attached properties again on this control to trigger the refresh.

Sounds good, I get one Xaml document that has swipe for iOS and Android, for lists and data pages, but, it works fine on iOS but fails on Android as my custom renderer for the SwipeRefreshLayout is wrong. It throws an exception about its children. Anyone got any ideas on how to create the renderer for the SwipeRefreshLayout as once I have this I will open it up on Github for other people to use.

Cheers,

Simeon

Trace:
{System.InvalidOperationException: SetElement did not create the correct number of children
at Xamarin.Forms.Platform.Android.VisualElementPackager.SetModel (Xamarin.Forms.VisualElement oldModel, Xamarin.Forms.VisualElement newModel) [0x00000] in :0
at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x00000] in :0
at Xamarin.Forms.Platform.Android.VisualElementRenderer1[Simeon.Common.UI.RefreshableView].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.Android.VisualElementRenderer1[Simeon.Common.UI.RefreshableView].SetElement (Simeon.Common.UI.RefreshableView element) [0x00000] in :0
at Xamarin.Forms.Platform.Android.VisualElementRenderer1[Simeon.Common.UI.RefreshableView].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.Android.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement view) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, Boolean sameChildren) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.Android.VisualElementPackager.SetModel (Xamarin.Forms.VisualElement oldModel, Xamarin.Forms.VisualElement newModel) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.Android.VisualElementRenderer1[Xamarin.Forms.Page].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00000] in :0
at Xamarin.Forms.Platform.Android.VisualElementRenderer1[Xamarin.Forms.Page].SetElement (Xamarin.Forms.Page element) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.Android.VisualElementRenderer1[Xamarin.Forms.Page].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in :0
at Xamarin.Forms.Platform.Android.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement view) [0x00000] in :0
at Xamarin.Forms.Platform.Android.NavigationRenderer.SwitchContentAsync (Xamarin.Forms.Page view, Boolean animated, Boolean removed) [0x00000] in :0
at Xamarin.Forms.Platform.Android.NavigationRenderer.OnPushAsync (Xamarin.Forms.Page view, Boolean animated) [0x00000] in :0
at Xamarin.Forms.Platform.Android.NavigationRenderer.PushViewAsync (Xamarin.Forms.Page page, Boolean animated) [0x00000] in :0
at Xamarin.Forms.Platform.Android.NavigationRenderer.b__0 (Xamarin.Forms.Page p) [0x00000] in :0
at Xamarin.Forms.EnumerableExtensions.ForEach[Page] (IEnumerable1 enumeration, System.Action1 action) [0x00000] in :0
at Xamarin.Forms.Platform.Android.NavigationRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs1 e) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.Android.VisualElementRenderer1[Xamarin.Forms.NavigationPage].SetElement (Xamarin.Forms.NavigationPage element) [0x00000] in :0
at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[Xamarin.Forms.NavigationPage].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in :0
at Xamarin.Forms.Platform.Android.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement view) [0x00000] in :0
at Xamarin.Forms.Platform.Android.MasterDetailContainer.set_ChildView (Xamarin.Forms.VisualElement value) [0x00000] in :0
at Xamarin.Forms.Platform.Android.MasterDetailRenderer.UpdateDetail () [0x00000] in :0
at Xamarin.Forms.Platform.Android.MasterDetailRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in :0
at Xamarin.Forms.Platform.Android.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement view) [0x00000] in :0
at Xamarin.Forms.Platform.Android.Platform.AddChild (Xamarin.Forms.VisualElement view) [0x00000] in :0
at Xamarin.Forms.Platform.Android.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00000] in :0
at Xamarin.Forms.Platform.Android.AndroidActivity.SetPage (Xamarin.Forms.Page page) [0x00000] in :0
at Simeon.AdvancedServices.ApplicationHub.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00021] in c:\Development\Framework II\Android\Simeon.AdvancedServices.ApplicationHub.Android\MainActivity.cs:27 }

Posts

  • PeterGoddardPeterGoddard USMember

    I am also very interested in this issue!

  • DH80DH80 USMember ✭✭

    Can you share the source for your swipe refresh control?

  • simeonsimeon USMember ✭✭

    Yeah but on Android you cant really just user the listview renderer as it would need to be wrapped in the SwipeRefreshLayout. I looked at his code and it was very nice but I think to make it work on android we need a renderer that sorts the swipe layout.

    My code is embedded in my companies commercial application at the moment. But we intend to strip it out and let the community have it if we can get it working. I'll post some stuff later once its stripped out.

  • simeonsimeon USMember ✭✭

    Hi I have stripped out my code. It doesn't work 100% but hopefully it gives you the idea of what I would like to achieve.

  • DH80DH80 USMember ✭✭

    nice! thanks!

Sign In or Register to comment.