Skip to content

Commit

Permalink
Fix RefreshView indicator hiding immediately (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamescaper authored Apr 11, 2023
1 parent 78fb00d commit fe4e9a3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/BlazorBindings.Maui/Elements/RefreshView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions src/BlazorBindings.UnitTests/Elements/RefreshViewTests.razor
Original file line number Diff line number Diff line change
@@ -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<MC.RefreshView>(
@<RefreshView OnRefreshing="refreshAction">
<ScrollView>
<VerticalStackLayout>
<Label @ref="labelRef">@refreshCount</Label>
</VerticalStackLayout>
</ScrollView>
</RefreshView>
);

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"));
}
}

0 comments on commit fe4e9a3

Please sign in to comment.