Skip to content

Commit

Permalink
[Android/iOS] RefreshView (xamarin#7214)
Browse files Browse the repository at this point in the history
* Swipe To Refresh

* pull in pull to refresh

* api changes

* Added RefreshView CoreGallery and Gallery Samples (using ScrollView, ListView, CollectionView, etc.)

* Code refactoring in RefreshViewRenderer (iOS)

* Updated RefreshView Android Renderer

* Fixed RefreshView Android samples in Core Gallery

* Added initial RefreshView UWP implementation

* Added another UWP RefreshView renderer using WinUI NuGet controls (RefreshContainer)

* - additional linker settings

* - uwp fixes

* - disable SkipMicrosoftUIXamlCheckTargetPlatformVersion check

* Update .nuspec/Xamarin.Forms.targets

* Limited RefreshView in Android to support only content using scroll.
Small changes in RefreshView iOS renderer.
Updated Core Gallery RefreshView samples.

* Fixed Visualizer colors in UWP RefreshView

* Added UWP RefreshPullDirection Platform Specific

* Small changes in code syntax in iOS renderer.

* Removed some unnecessary curly braces .

* Register effect provider in iOS RefreshView

* Changes in RefreshView UWP Dispose

* Added conditional code to manage the refresh control differently if it is iOS 10 or higher.

* Fixed error in Android Core Gallery (Linker)
Code refactoring and small changes (PR Feedback)

* Changes disposing the Android renderer

* - fix SkipMicrosoftUIXamlCheckTargetPlatformVersion so it can be turned off

* Removed UWP RefreshView renderer and Platform Specific

* - remove winui from nuspec

* - remove skip checks from targets

* - remove XamlControlsResources

* - remove skip check on UAP platform

* Revert changes in Android Core Gallery manifiest

* Revert unnecessary space in UAP Platform csproj

* Removed unnecessary new line in UWP Resources

* Simplified RefreshView iOS Renderer.
fixes xamarin#5882
  • Loading branch information
PureWeen authored and felipebaltazar committed Oct 16, 2019
1 parent 540a700 commit f224edf
Show file tree
Hide file tree
Showing 26 changed files with 1,098 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Stubs/Xamarin.Forms.Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ internal class _PageRenderer { }
[RenderWith (typeof (PhoneMasterDetailRenderer))]
#endif
internal class _MasterDetailPageRenderer { }
#if !TIZEN4_0
[RenderWith(typeof(RefreshViewRenderer))]
#endif
internal class _RefreshViewRenderer { }
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<AppxBundle>Always</AppxBundle>
<RuntimeIdentifiers>win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot</RuntimeIdentifiers>
<GenerateAppxPackageOnBuild>False</GenerateAppxPackageOnBuild>
<SkipMicrosoftUIXamlCheckTargetPlatformVersion>true</SkipMicrosoftUIXamlCheckTargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<DebugSymbols>true</DebugSymbols>
Expand Down
3 changes: 3 additions & 0 deletions Xamarin.Forms.Controls/CoreGallery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
using Xamarin.Forms.Controls.GalleryPages.VisualStateManagerGalleries;
using Xamarin.Forms.Controls.Issues;
using Xamarin.Forms.Controls.GalleryPages.RefreshViewGalleries;

namespace Xamarin.Forms.Controls
{
Expand Down Expand Up @@ -337,6 +338,8 @@ public override string ToString()
new GalleryPageFactory(() => new ProgressBarCoreGalleryPage(), "ProgressBar Gallery"),
new GalleryPageFactory(() => new MaterialProgressBarGallery(), "ProgressBar & Slider Gallery (Material)"),
new GalleryPageFactory(() => new MaterialActivityIndicatorGallery(), "ActivityIndicator Gallery (Material)"),
new GalleryPageFactory(() => new RefreshViewGallery(), "RefreshView Gallery"),
new GalleryPageFactory(() => new RefreshViewCoreGalleryPage(), "RefreshView Core Gallery"),
new GalleryPageFactory(() => new ScrollGallery(), "ScrollView Gallery"),
new GalleryPageFactory(() => new ScrollGallery(ScrollOrientation.Horizontal), "ScrollView Gallery Horizontal"),
new GalleryPageFactory(() => new ScrollGallery(ScrollOrientation.Both), "ScrollView Gallery 2D"),
Expand Down
14 changes: 13 additions & 1 deletion Xamarin.Forms.Controls/CoreGalleryPages/CoreGalleryPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ internal CoreGalleryPage()

Build(Layout);

Content = new ScrollView { AutomationId = "GalleryScrollView", Content = Layout };
if (SupportsScroll)
Content = new ScrollView { AutomationId = "GalleryScrollView", Content = Layout };
else
{
var content = new Grid { AutomationId = "GalleryScrollView" };
content.Children.Add(Layout);
Content = content;
}
}

protected virtual void InitializeElement(T element) { }
Expand Down Expand Up @@ -229,6 +236,11 @@ protected virtual bool SupportsFocus
get { return true; }
}

protected virtual bool SupportsScroll
{
get { return true; }
}

protected void Add(ViewContainer<T> viewContainer)
{
_viewContainers.Add(viewContainer);
Expand Down
120 changes: 120 additions & 0 deletions Xamarin.Forms.Controls/CoreGalleryPages/RefreshViewCoreGalleyPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System;
using System.Windows.Input;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls
{
[Preserve(AllMembers = true)]
internal class RefreshViewCoreGalleryPage : CoreGalleryPage<RefreshView>
{
protected override bool SupportsFocus
{
get { return false; }
}

protected override bool SupportsScroll
{
get { return false; }
}

protected override void InitializeElement(RefreshView element)
{
base.InitializeElement(element);

BindingContext = new RefreshCoreGalleryViewModel();

element.Content = CreateContent();
element.SetBinding(RefreshView.CommandProperty, "RefreshCommand");
element.SetBinding(RefreshView.IsRefreshingProperty, "IsRefreshing");
}

protected override void Build(StackLayout stackLayout)
{
base.Build(stackLayout);

var refreshColorContainer = new ViewContainer<RefreshView>(Test.RefreshView.RefreshColor, new RefreshView
{
Content = CreateContent(),
RefreshColor = Color.Red
});

refreshColorContainer.View.SetBinding(RefreshView.CommandProperty, "RefreshCommand");
refreshColorContainer.View.SetBinding(RefreshView.IsRefreshingProperty, "IsRefreshing");

Add(refreshColorContainer);
}

ScrollView CreateContent()
{
var scrollView = new ScrollView
{
BackgroundColor = Color.Green,
HeightRequest = 250
};

var content = new Grid();

var refreshLabel = new Label
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
TextColor = Color.White
};

refreshLabel.SetBinding(Label.TextProperty, "Info");
content.Children.Add(refreshLabel);
scrollView.Content = content;

return scrollView;
}
}

[Preserve(AllMembers = true)]
public class RefreshCoreGalleryViewModel : BindableObject
{
const int RefreshDuration = 1;

private bool _isRefresing;
private string _info;

public RefreshCoreGalleryViewModel()
{
Info = "RefreshView (Pull To Refresh)";
}

public bool IsRefreshing
{
get { return _isRefresing; }
set
{
_isRefresing = value;
OnPropertyChanged();
}
}

public string Info
{
get { return _info; }
set
{
_info = value;
OnPropertyChanged();
}
}

public ICommand RefreshCommand => new Command(ExecuteRefresh);

private void ExecuteRefresh()
{
IsRefreshing = true;

Device.StartTimer(TimeSpan.FromSeconds(RefreshDuration), () =>
{
IsRefreshing = false;
Info = "Refreshed (Pull To Refresh again)";
return false;
});
}
}
}
2 changes: 1 addition & 1 deletion Xamarin.Forms.Controls/GalleryPages/GalleryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class GalleryBuilder
public static Button NavButton(string galleryName, Func<ContentPage> gallery, INavigation nav)
{
var automationId = System.Text.RegularExpressions.Regex.Replace(galleryName, " |\\(|\\)", string.Empty);
var button = new Button { Text = $"{galleryName}", AutomationId = automationId, FontSize = 10, HeightRequest = 30 };
var button = new Button { Text = $"{galleryName}", AutomationId = automationId, FontSize = 10, HeightRequest = Device.RuntimePlatform == Device.Android ? 40 : 30 };
button.Clicked += (sender, args) => { nav.PushAsync(gallery()); };
return button;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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="Xamarin.Forms.Controls.GalleryPages.RefreshViewGalleries.RefreshCollectionViewGallery"
Title="CollectionView (Pull To Refresh)">
<ContentPage.Content>
<RefreshView
IsRefreshing="{Binding IsRefreshing}"
RefreshColor="Pink"
Command="{Binding RefreshCommand}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<CollectionView
ItemsSource="{Binding Items}">
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="48" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<BoxView
Grid.Column="0"
Color="{Binding Color}"
HeightRequest="48"/>
<Label
Grid.Column="1"
Text="{Binding Name}"/>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</RefreshView>
</ContentPage.Content>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls.GalleryPages.RefreshViewGalleries
{
[Preserve(AllMembers = true)]
public partial class RefreshCollectionViewGallery : ContentPage
{
public RefreshCollectionViewGallery()
{
InitializeComponent();
BindingContext = new RefreshViewModel();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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="Xamarin.Forms.Controls.GalleryPages.RefreshViewGalleries.RefreshLayoutGallery"
Title="Layout (Pull To Refresh)">
<ContentPage.Resources>
<ResourceDictionary>

<DataTemplate x:Key="RefreshItemTemplate">
<Grid
HeightRequest="100"
WidthRequest="100">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<BoxView
Grid.Row="0"
Color="{Binding Color}"/>
<Label
Grid.Row="1"
Text="{Binding Name}"/>
</Grid>
</DataTemplate>

</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<RefreshView
IsRefreshing="{Binding IsRefreshing}"
RefreshColor="Red"
Command="{Binding RefreshCommand}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<StackLayout
Padding="6">
<Label
FontSize="Medium"
FontAttributes="Bold"
Text="The Content of a RefreshView must be a scrollable control, such as ScrollView, CollectionView, ListView, etc."/>
<Label
FontSize="Small"
Text="Setting the Content to a control like Grid will result in undefined behavior."/>
</StackLayout>
</RefreshView>
</ContentPage.Content>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls.GalleryPages.RefreshViewGalleries
{
[Preserve(AllMembers = true)]
public partial class RefreshLayoutGallery : ContentPage
{
public RefreshLayoutGallery()
{
InitializeComponent();
BindingContext = new RefreshViewModel();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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="Xamarin.Forms.Controls.GalleryPages.RefreshViewGalleries.RefreshListViewGallery"
Title="ListView (Pull To Refresh)">
<ContentPage.Content>
<StackLayout>
<Button
Text="Trigger Refresh"
Command="{Binding RefreshCommand}"/>
<RefreshView
IsRefreshing="{Binding IsRefreshing}"
BackgroundColor="Red"
RefreshColor="Yellow"
Command="{Binding RefreshCommand}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<ListView
ItemsSource="{Binding Items}"
Header = "Header"
Footer = "Footer"
HasUnevenRows="True"
SeparatorVisibility="None">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="48" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<BoxView
Grid.Column="0"
Color="{Binding Color}"
HeightRequest="48"/>
<Label
Grid.Column="1"
Text="{Binding Name}"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</RefreshView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls.GalleryPages.RefreshViewGalleries
{
[Preserve(AllMembers = true)]
public partial class RefreshListViewGallery : ContentPage
{
public RefreshListViewGallery()
{
InitializeComponent();
BindingContext = new RefreshViewModel();
}
}
}
Loading

0 comments on commit f224edf

Please sign in to comment.