1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-10 13:23:39 +00:00

show activity indicator while still loading

This commit is contained in:
Kyle Spearrin
2019-05-01 10:11:49 -04:00
parent 9eeafcd027
commit b4f4f24c24
3 changed files with 48 additions and 12 deletions

View File

@@ -0,0 +1,41 @@
using System;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Bit.App.Pages
{
public class BaseContentPage : ContentPage
{
protected void SetActivityIndicator()
{
Content = new ActivityIndicator
{
IsRunning = true,
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.Center
};
}
protected async Task LoadOnAppearedAsync(View viewToSet, bool fromModal, Func<Task> workFunction)
{
async Task LoadAsync()
{
await workFunction.Invoke();
if(viewToSet != null)
{
Content = viewToSet;
}
}
if(Device.RuntimePlatform == Device.iOS)
{
await LoadAsync();
return;
}
await Task.Run(async () =>
{
await Task.Delay(fromModal ? 400 : 200);
Device.BeginInvokeOnMainThread(async () => await LoadAsync());
});
}
}
}