From fe4e9a3d073262dd3227fdca16608c723061aaf9 Mon Sep 17 00:00:00 2001 From: Oleksandr Liakhevych Date: Wed, 12 Apr 2023 01:52:06 +0300 Subject: [PATCH] Fix RefreshView indicator hiding immediately (#118) --- .../Elements/RefreshView.cs | 12 +++++-- .../Elements/RefreshViewTests.razor | 33 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 src/BlazorBindings.UnitTests/Elements/RefreshViewTests.razor diff --git a/src/BlazorBindings.Maui/Elements/RefreshView.cs b/src/BlazorBindings.Maui/Elements/RefreshView.cs index 1eed72bb..0a8308fa 100644 --- a/src/BlazorBindings.Maui/Elements/RefreshView.cs +++ b/src/BlazorBindings.Maui/Elements/RefreshView.cs @@ -13,10 +13,16 @@ protected override bool HandleAdditionalParameter(string name, object value) { if (!Equals(OnRefreshing, value)) { - void NativeControlRefreshing(object sender, EventArgs e) + async void NativeControlRefreshing(object sender, EventArgs e) { - InvokeEventCallback(OnRefreshing); - NativeControl.IsRefreshing = false; + try + { + await InvokeEventCallbackAsync(OnRefreshing); + } + finally + { + NativeControl.IsRefreshing = false; + } } OnRefreshing = (EventCallback)value; diff --git a/src/BlazorBindings.UnitTests/Elements/RefreshViewTests.razor b/src/BlazorBindings.UnitTests/Elements/RefreshViewTests.razor new file mode 100644 index 00000000..44e930f7 --- /dev/null +++ b/src/BlazorBindings.UnitTests/Elements/RefreshViewTests.razor @@ -0,0 +1,33 @@ +@inherits ElementTestBase + +@code { + [Test] + public async Task InvokeOnRefreshingCallback() + { + int refreshCount = 0; + bool refreshInvokeStarted = false; + var refreshAction = async () => { refreshInvokeStarted = true; await Task.Delay(20); refreshCount++; }; + Label labelRef = null; + + var refreshView = await Render( + @ + + + + + + + ); + + refreshView.IsRefreshing = true; + + await Task.Delay(5); + Assert.That(refreshInvokeStarted, Is.True); + Assert.That(refreshView.IsRefreshing, Is.True); + + await Task.Delay(20); + Assert.That(refreshCount, Is.EqualTo(1)); + Assert.That(refreshView.IsRefreshing, Is.False); + Assert.That(labelRef.NativeControl.Text, Is.EqualTo("1")); + } +}