Code Monkey home page Code Monkey logo

xamarin.forms-pulltorefreshlayout's Introduction

PullToRefreshLayout for Xamarin.Forms

Implementation of pull to refresh layout for Xamarin.Forms targeting iOS and Android.

The goal was to create a cross-platform Xamarin.Forms Layout that could have it’s content set to anything and would enable pull to refresh capabilities.

A BIG thank you to Jason Smith for his assistance on some tricky logic.

For a detailed overview of the API and sample please read through my blog: http://motzcod.es/post/128274430137/pull-to-refresh-anyish-xamarinforms-view

Also available as a NuGet: https://www.nuget.org/packages/Refractored.XamForms.PullToRefresh/

Build Status: Build status

Important

If you are using the NuGet ensure that you call “PullToRefreshLayoutRenderer.Init();” in both your MainActivity and AppDelegate. (Similar to Xamarin.Forms.Maps).

Android: You must build and compile against SDK 7.1+ as this uses Android Support 25.4.0.2!

API

Simply create a PullToRefreshLayout like any other Layout and set the Content to a supported view.

var scrollView = new ScrollView
{
  VerticalOptions = LayoutOptions.FillAndExpand,
  HorizontalOptions = LayoutOptions.FillAndExpand,
  Content = /* Anything you want in your ScrollView */
};

var refreshView = new PullToRefreshLayout {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Content = scrollView,
                RefreshColor = Color.FromHex("#3498db")
            };

//Set Bindings
refreshView.SetBinding<TestViewModel> (PullToRefreshLayout.IsRefreshingProperty, vm => vm.IsBusy, BindingMode.OneWay);
refreshView.SetBinding<TestViewModel>(PullToRefreshLayout.RefreshCommandProperty, vm => vm.RefreshCommand);

Content = refreshView;

Additionally, your content could be anything you want including a StackLayout:

Content = new StackLayout
{
  Children = 
  {
    new Label { Text = “Hello Pull to Refresh“ },
    refreshView
  }
};

You can of course do it in XAML:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    x:Class="RefreshSample.Views.ScrollViewXamlPage"
    xmlns:controls="clr-namespace:Refractored.XamForms.PullToRefresh;assembly=Refractored.XamForms.PullToRefresh"
    Title="Xaml Scroll">
   <controls:PullToRefreshLayout
          IsPullToRefreshEnabled="True"
          RefreshCommand="{Binding RefreshCommand}"
          IsRefreshing="{Binding IsBusy}"
          RefreshColor="Blue"> 
          <ScrollView
          HorizontalOptions="FillAndExpand"
          VerticalOptions="FillAndExpand">
            <StackLayout
                  HorizontalOptions="FillAndExpand"
                  VerticalOptions="FillAndExpand">
                <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue"/>
                <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Red"/>
                <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Yellow"/>
                <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Purple"/>
                <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Maroon"/>
                <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue"/>
                <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Red"/>
                <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Yellow"/>
                <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Purple"/>
                <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Maroon"/>
            </StackLayout>
          </ScrollView>
   </controls:PullToRefreshLayout>
</ContentPage>

Officially Supported Views:

  • ListView
  • ScrollView

Unofficial Supported Views

  • UICollectionView (iOS)
  • RecyclerView (Android)
  • GridView (Android)
  • Potentially all Android Views without a scroll, but it acts a bit odd on some
  • ^^You should probably use a ScrollView^^

License

The MIT License (MIT)

Copyright (c) 2015 Refractored LLC & James Montemagno

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

xamarin.forms-pulltorefreshlayout's People

Contributors

jamesmontemagno avatar miiite avatar r2d2rigo avatar

Stargazers

Media Explorer avatar

Watchers

James Cloos avatar Shane Neuville avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.