Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit bcf1d85

Browse files
PureWeensamhouts
authored andcommitted
[Android/iOS] RefreshView (#7214)
* 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 #5882
1 parent 50bce1d commit bcf1d85

26 files changed

+1098
-5
lines changed

Stubs/Xamarin.Forms.Platform.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ internal class _PageRenderer { }
154154
[RenderWith (typeof (PhoneMasterDetailRenderer))]
155155
#endif
156156
internal class _MasterDetailPageRenderer { }
157+
#if !TIZEN4_0
158+
[RenderWith(typeof(RefreshViewRenderer))]
159+
#endif
160+
internal class _RefreshViewRenderer { }
157161
}
158162

159163

Xamarin.Forms.ControlGallery.WindowsUniversal/Xamarin.Forms.ControlGallery.WindowsUniversal.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<AppxBundle>Always</AppxBundle>
2525
<RuntimeIdentifiers>win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot</RuntimeIdentifiers>
2626
<GenerateAppxPackageOnBuild>False</GenerateAppxPackageOnBuild>
27+
<SkipMicrosoftUIXamlCheckTargetPlatformVersion>true</SkipMicrosoftUIXamlCheckTargetPlatformVersion>
2728
</PropertyGroup>
2829
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
2930
<DebugSymbols>true</DebugSymbols>

Xamarin.Forms.Controls/CoreGallery.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
1212
using Xamarin.Forms.Controls.GalleryPages.VisualStateManagerGalleries;
1313
using Xamarin.Forms.Controls.Issues;
14+
using Xamarin.Forms.Controls.GalleryPages.RefreshViewGalleries;
1415

1516
namespace Xamarin.Forms.Controls
1617
{
@@ -337,6 +338,8 @@ public override string ToString()
337338
new GalleryPageFactory(() => new ProgressBarCoreGalleryPage(), "ProgressBar Gallery"),
338339
new GalleryPageFactory(() => new MaterialProgressBarGallery(), "ProgressBar & Slider Gallery (Material)"),
339340
new GalleryPageFactory(() => new MaterialActivityIndicatorGallery(), "ActivityIndicator Gallery (Material)"),
341+
new GalleryPageFactory(() => new RefreshViewGallery(), "RefreshView Gallery"),
342+
new GalleryPageFactory(() => new RefreshViewCoreGalleryPage(), "RefreshView Core Gallery"),
340343
new GalleryPageFactory(() => new ScrollGallery(), "ScrollView Gallery"),
341344
new GalleryPageFactory(() => new ScrollGallery(ScrollOrientation.Horizontal), "ScrollView Gallery Horizontal"),
342345
new GalleryPageFactory(() => new ScrollGallery(ScrollOrientation.Both), "ScrollView Gallery 2D"),

Xamarin.Forms.Controls/CoreGalleryPages/CoreGalleryPage.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ internal CoreGalleryPage()
4545

4646
Build(Layout);
4747

48-
Content = new ScrollView { AutomationId = "GalleryScrollView", Content = Layout };
48+
if (SupportsScroll)
49+
Content = new ScrollView { AutomationId = "GalleryScrollView", Content = Layout };
50+
else
51+
{
52+
var content = new Grid { AutomationId = "GalleryScrollView" };
53+
content.Children.Add(Layout);
54+
Content = content;
55+
}
4956
}
5057

5158
protected virtual void InitializeElement(T element) { }
@@ -229,6 +236,11 @@ protected virtual bool SupportsFocus
229236
get { return true; }
230237
}
231238

239+
protected virtual bool SupportsScroll
240+
{
241+
get { return true; }
242+
}
243+
232244
protected void Add(ViewContainer<T> viewContainer)
233245
{
234246
_viewContainers.Add(viewContainer);
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
using System;
2+
using System.Windows.Input;
3+
using Xamarin.Forms.CustomAttributes;
4+
using Xamarin.Forms.Internals;
5+
6+
namespace Xamarin.Forms.Controls
7+
{
8+
[Preserve(AllMembers = true)]
9+
internal class RefreshViewCoreGalleryPage : CoreGalleryPage<RefreshView>
10+
{
11+
protected override bool SupportsFocus
12+
{
13+
get { return false; }
14+
}
15+
16+
protected override bool SupportsScroll
17+
{
18+
get { return false; }
19+
}
20+
21+
protected override void InitializeElement(RefreshView element)
22+
{
23+
base.InitializeElement(element);
24+
25+
BindingContext = new RefreshCoreGalleryViewModel();
26+
27+
element.Content = CreateContent();
28+
element.SetBinding(RefreshView.CommandProperty, "RefreshCommand");
29+
element.SetBinding(RefreshView.IsRefreshingProperty, "IsRefreshing");
30+
}
31+
32+
protected override void Build(StackLayout stackLayout)
33+
{
34+
base.Build(stackLayout);
35+
36+
var refreshColorContainer = new ViewContainer<RefreshView>(Test.RefreshView.RefreshColor, new RefreshView
37+
{
38+
Content = CreateContent(),
39+
RefreshColor = Color.Red
40+
});
41+
42+
refreshColorContainer.View.SetBinding(RefreshView.CommandProperty, "RefreshCommand");
43+
refreshColorContainer.View.SetBinding(RefreshView.IsRefreshingProperty, "IsRefreshing");
44+
45+
Add(refreshColorContainer);
46+
}
47+
48+
ScrollView CreateContent()
49+
{
50+
var scrollView = new ScrollView
51+
{
52+
BackgroundColor = Color.Green,
53+
HeightRequest = 250
54+
};
55+
56+
var content = new Grid();
57+
58+
var refreshLabel = new Label
59+
{
60+
HorizontalOptions = LayoutOptions.Center,
61+
VerticalOptions = LayoutOptions.Center,
62+
TextColor = Color.White
63+
};
64+
65+
refreshLabel.SetBinding(Label.TextProperty, "Info");
66+
content.Children.Add(refreshLabel);
67+
scrollView.Content = content;
68+
69+
return scrollView;
70+
}
71+
}
72+
73+
[Preserve(AllMembers = true)]
74+
public class RefreshCoreGalleryViewModel : BindableObject
75+
{
76+
const int RefreshDuration = 1;
77+
78+
private bool _isRefresing;
79+
private string _info;
80+
81+
public RefreshCoreGalleryViewModel()
82+
{
83+
Info = "RefreshView (Pull To Refresh)";
84+
}
85+
86+
public bool IsRefreshing
87+
{
88+
get { return _isRefresing; }
89+
set
90+
{
91+
_isRefresing = value;
92+
OnPropertyChanged();
93+
}
94+
}
95+
96+
public string Info
97+
{
98+
get { return _info; }
99+
set
100+
{
101+
_info = value;
102+
OnPropertyChanged();
103+
}
104+
}
105+
106+
public ICommand RefreshCommand => new Command(ExecuteRefresh);
107+
108+
private void ExecuteRefresh()
109+
{
110+
IsRefreshing = true;
111+
112+
Device.StartTimer(TimeSpan.FromSeconds(RefreshDuration), () =>
113+
{
114+
IsRefreshing = false;
115+
Info = "Refreshed (Pull To Refresh again)";
116+
return false;
117+
});
118+
}
119+
}
120+
}

Xamarin.Forms.Controls/GalleryPages/GalleryBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class GalleryBuilder
77
public static Button NavButton(string galleryName, Func<ContentPage> gallery, INavigation nav)
88
{
99
var automationId = System.Text.RegularExpressions.Regex.Replace(galleryName, " |\\(|\\)", string.Empty);
10-
var button = new Button { Text = $"{galleryName}", AutomationId = automationId, FontSize = 10, HeightRequest = 30 };
10+
var button = new Button { Text = $"{galleryName}", AutomationId = automationId, FontSize = 10, HeightRequest = Device.RuntimePlatform == Device.Android ? 40 : 30 };
1111
button.Clicked += (sender, args) => { nav.PushAsync(gallery()); };
1212
return button;
1313
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<ContentPage
3+
xmlns="http://xamarin.com/schemas/2014/forms"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
5+
x:Class="Xamarin.Forms.Controls.GalleryPages.RefreshViewGalleries.RefreshCollectionViewGallery"
6+
Title="CollectionView (Pull To Refresh)">
7+
<ContentPage.Content>
8+
<RefreshView
9+
IsRefreshing="{Binding IsRefreshing}"
10+
RefreshColor="Pink"
11+
Command="{Binding RefreshCommand}"
12+
HorizontalOptions="FillAndExpand"
13+
VerticalOptions="FillAndExpand">
14+
<CollectionView
15+
ItemsSource="{Binding Items}">
16+
<CollectionView.ItemTemplate>
17+
<DataTemplate>
18+
<Grid>
19+
<Grid.ColumnDefinitions>
20+
<ColumnDefinition Width="48" />
21+
<ColumnDefinition Width="*" />
22+
</Grid.ColumnDefinitions>
23+
<BoxView
24+
Grid.Column="0"
25+
Color="{Binding Color}"
26+
HeightRequest="48"/>
27+
<Label
28+
Grid.Column="1"
29+
Text="{Binding Name}"/>
30+
</Grid>
31+
</DataTemplate>
32+
</CollectionView.ItemTemplate>
33+
</CollectionView>
34+
</RefreshView>
35+
</ContentPage.Content>
36+
</ContentPage>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Xamarin.Forms.Internals;
2+
3+
namespace Xamarin.Forms.Controls.GalleryPages.RefreshViewGalleries
4+
{
5+
[Preserve(AllMembers = true)]
6+
public partial class RefreshCollectionViewGallery : ContentPage
7+
{
8+
public RefreshCollectionViewGallery()
9+
{
10+
InitializeComponent();
11+
BindingContext = new RefreshViewModel();
12+
}
13+
}
14+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<ContentPage
3+
xmlns="http://xamarin.com/schemas/2014/forms"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
5+
x:Class="Xamarin.Forms.Controls.GalleryPages.RefreshViewGalleries.RefreshLayoutGallery"
6+
Title="Layout (Pull To Refresh)">
7+
<ContentPage.Resources>
8+
<ResourceDictionary>
9+
10+
<DataTemplate x:Key="RefreshItemTemplate">
11+
<Grid
12+
HeightRequest="100"
13+
WidthRequest="100">
14+
<Grid.RowDefinitions>
15+
<RowDefinition Height="*" />
16+
<RowDefinition Height="Auto" />
17+
</Grid.RowDefinitions>
18+
<BoxView
19+
Grid.Row="0"
20+
Color="{Binding Color}"/>
21+
<Label
22+
Grid.Row="1"
23+
Text="{Binding Name}"/>
24+
</Grid>
25+
</DataTemplate>
26+
27+
</ResourceDictionary>
28+
</ContentPage.Resources>
29+
<ContentPage.Content>
30+
<RefreshView
31+
IsRefreshing="{Binding IsRefreshing}"
32+
RefreshColor="Red"
33+
Command="{Binding RefreshCommand}"
34+
HorizontalOptions="FillAndExpand"
35+
VerticalOptions="FillAndExpand">
36+
<StackLayout
37+
Padding="6">
38+
<Label
39+
FontSize="Medium"
40+
FontAttributes="Bold"
41+
Text="The Content of a RefreshView must be a scrollable control, such as ScrollView, CollectionView, ListView, etc."/>
42+
<Label
43+
FontSize="Small"
44+
Text="Setting the Content to a control like Grid will result in undefined behavior."/>
45+
</StackLayout>
46+
</RefreshView>
47+
</ContentPage.Content>
48+
</ContentPage>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Xamarin.Forms.Internals;
2+
3+
namespace Xamarin.Forms.Controls.GalleryPages.RefreshViewGalleries
4+
{
5+
[Preserve(AllMembers = true)]
6+
public partial class RefreshLayoutGallery : ContentPage
7+
{
8+
public RefreshLayoutGallery()
9+
{
10+
InitializeComponent();
11+
BindingContext = new RefreshViewModel();
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)