mirror of
https://github.com/bitwarden/mobile.git
synced 2024-12-17 15:27:43 +01:00
show activity indicator while still loading
This commit is contained in:
parent
9eeafcd027
commit
b4f4f24c24
41
src/App/Pages/BaseContentPage.cs
Normal file
41
src/App/Pages/BaseContentPage.cs
Normal 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());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage
|
||||
<pages:BaseContentPage
|
||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Bit.App.Pages.ViewPage"
|
||||
@ -27,7 +27,7 @@
|
||||
</ResourceDictionary>
|
||||
</ContentPage.Resources>
|
||||
|
||||
<ScrollView>
|
||||
<ScrollView x:Name="_scrollView">
|
||||
<StackLayout Spacing="20">
|
||||
<StackLayout StyleClass="box">
|
||||
<StackLayout StyleClass="box-row-header">
|
||||
@ -592,4 +592,4 @@
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
|
||||
</ContentPage>
|
||||
</pages:BaseContentPage>
|
||||
|
@ -1,16 +1,10 @@
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
namespace Bit.App.Pages
|
||||
{
|
||||
public partial class ViewPage : ContentPage
|
||||
public partial class ViewPage : BaseContentPage
|
||||
{
|
||||
private readonly IBroadcasterService _broadcasterService;
|
||||
private ViewPageViewModel _vm;
|
||||
@ -22,9 +16,10 @@ namespace Bit.App.Pages
|
||||
_vm = BindingContext as ViewPageViewModel;
|
||||
_vm.Page = this;
|
||||
_vm.CipherId = cipherId;
|
||||
SetActivityIndicator();
|
||||
}
|
||||
|
||||
protected async override void OnAppearing()
|
||||
protected override async void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
_broadcasterService.Subscribe(nameof(ViewPage), async (message) =>
|
||||
@ -42,7 +37,7 @@ namespace Bit.App.Pages
|
||||
}
|
||||
}
|
||||
});
|
||||
await _vm.LoadAsync();
|
||||
await LoadOnAppearedAsync(_scrollView, true, () => _vm.LoadAsync());
|
||||
}
|
||||
|
||||
protected override void OnDisappearing()
|
||||
|
Loading…
Reference in New Issue
Block a user