[UWP] Delay RequestRefresh until Loaded (#8190)

fixes #8186
This commit is contained in:
Shane Neuville 2019-10-28 18:41:14 -06:00 коммит произвёл Samantha Houts
Родитель bd82891e3e
Коммит 2f02371116
3 изменённых файлов: 103 добавлений и 3 удалений

Просмотреть файл

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 8186, "[UWP] Setting IsRefreshing from OnAppearing on RefreshView crashes UWP",
PlatformAffected.UWP)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.RefreshView)]
#endif
public class Issue8186 : TestNavigationPage
{
RefreshView _refreshView;
protected override void Init()
{
_refreshView = new RefreshView()
{
Content = new ScrollView()
{
Content = new StackLayout()
{
Children =
{
new Label()
{
Text = "If you are reading this and see a refresh circle test has succeeded",
AutomationId = "Success"
},
new Button()
{
Text = "Push Page then return to this page.",
Command = new Command(() =>
{
Navigation.PushAsync(new ContentPage()
{
Content = new Button()
{
Text = "Pop Page",
AutomationId = "PopPage",
Command = new Command(()=> Navigation.PopAsync())
}
});
}),
AutomationId = "PushPage"
}
}
}
}
};
var page = new ContentPage() { Content = _refreshView };
page.Appearing += (_, __) => _refreshView.IsRefreshing = true;
page.Disappearing += (_, __) => _refreshView.IsRefreshing = false;
PushAsync(page);
}
#if UITEST
[Test]
public void SetIsRefreshingToTrueInOnAppearingDoesntCrash()
{
RunningApp.WaitForElement("Success");
RunningApp.Tap("PushPage");
RunningApp.Tap("PopPage");
RunningApp.WaitForElement("Success");
}
#endif
}
}

Просмотреть файл

@ -19,6 +19,7 @@
<Compile Include="$(MSBuildThisFileDirectory)CollectionViewHeaderFooterTemplate.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CollectionViewHeaderFooterView.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CollectionViewItemsUpdatingScrollMode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8186.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue3475.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue5354.xaml.cs">
<SubType>Code</SubType>
@ -1596,4 +1597,4 @@
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
</Project>

Просмотреть файл

@ -2,6 +2,7 @@
using System.ComponentModel;
using Microsoft.UI.Xaml.Controls;
using Windows.Foundation;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Xamarin.Forms.PlatformConfiguration.WindowsSpecific;
@ -41,6 +42,7 @@ namespace Xamarin.Forms.Platform.UWP
base.Dispose(disposing);
}
bool _isLoaded = false;
protected override void OnElementChanged(ElementChangedEventArgs<RefreshView> e)
{
if (e.NewElement != null)
@ -53,13 +55,26 @@ namespace Xamarin.Forms.Platform.UWP
};
refreshControl.RefreshRequested += OnRefresh;
refreshControl.Loaded += OnLoaded;
// Telling the refresh to start before the control has been sized
// causes no refresh circle to show up
void OnLoaded(object sender, object args)
{
refreshControl.Loaded -= OnLoaded;
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
{
_isLoaded = true;
UpdateIsRefreshing();
});
}
// There's a bug with RefreshContainer where if you assign the Visualizer
// yourself on creation it will cause RefreshRequested to fire twice
// https://github.com/microsoft/microsoft-ui-xaml/issues/1282
long callbackToken = 0;
callbackToken = refreshControl.RegisterPropertyChangedCallback(RefreshContainer.VisualizerProperty,
(_,__) =>
(_, __) =>
{
if (refreshControl?.Visualizer == null)
return;
@ -73,13 +88,14 @@ namespace Xamarin.Forms.Platform.UWP
UpdateContent();
UpdateIsEnabled();
UpdateIsRefreshing();
UpdateRefreshPullDirection();
}
base.OnElementChanged(e);
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
@ -123,6 +139,9 @@ namespace Xamarin.Forms.Platform.UWP
void UpdateIsRefreshing()
{
if (!_isLoaded)
return;
if (!Element.IsRefreshing)
{
CompleteRefresh();