From b4f4f24c248a752d739ebdb6fa510ce301989106 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 1 May 2019 10:11:49 -0400 Subject: [PATCH] show activity indicator while still loading --- src/App/Pages/BaseContentPage.cs | 41 ++++++++++++++++++++++++++++ src/App/Pages/Vault/ViewPage.xaml | 6 ++-- src/App/Pages/Vault/ViewPage.xaml.cs | 13 +++------ 3 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 src/App/Pages/BaseContentPage.cs diff --git a/src/App/Pages/BaseContentPage.cs b/src/App/Pages/BaseContentPage.cs new file mode 100644 index 000000000..7db32ae72 --- /dev/null +++ b/src/App/Pages/BaseContentPage.cs @@ -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 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()); + }); + } + } +} diff --git a/src/App/Pages/Vault/ViewPage.xaml b/src/App/Pages/Vault/ViewPage.xaml index 3d8be522c..26bea6f75 100644 --- a/src/App/Pages/Vault/ViewPage.xaml +++ b/src/App/Pages/Vault/ViewPage.xaml @@ -1,5 +1,5 @@  - - + @@ -592,4 +592,4 @@ - + diff --git a/src/App/Pages/Vault/ViewPage.xaml.cs b/src/App/Pages/Vault/ViewPage.xaml.cs index 90b433ae7..c626da79b 100644 --- a/src/App/Pages/Vault/ViewPage.xaml.cs +++ b/src/App/Pages/Vault/ViewPage.xaml.cs @@ -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()