bitwarden-android/src/App/Pages/BaseContentPage.cs

59 lines
1.7 KiB
C#
Raw Normal View History

using System;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Bit.App.Pages
{
public class BaseContentPage : ContentPage
{
2019-05-01 22:29:57 +03:00
protected int AndroidShowModalAnimationDelay = 400;
2019-05-02 19:46:08 +03:00
protected int AndroidShowPageAnimationDelay = 100;
2019-05-01 22:29:57 +03:00
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)
{
2019-05-01 17:20:05 +03:00
async Task DoWorkAsync()
{
await workFunction.Invoke();
if(viewToSet != null)
{
Content = viewToSet;
}
}
2019-05-02 19:46:08 +03:00
if(Device.RuntimePlatform == Device.iOS)
{
2019-05-01 17:20:05 +03:00
await DoWorkAsync();
return;
}
await Task.Run(async () =>
{
2019-05-02 19:46:08 +03:00
await Task.Delay(fromModal ? AndroidShowModalAnimationDelay : AndroidShowPageAnimationDelay);
2019-05-01 17:20:05 +03:00
Device.BeginInvokeOnMainThread(async () => await DoWorkAsync());
});
}
2019-05-01 22:29:57 +03:00
protected void RequestFocus(Entry entry)
{
if(Device.RuntimePlatform == Device.iOS)
{
entry.Focus();
return;
}
Task.Run(async () =>
{
await Task.Delay(AndroidShowModalAnimationDelay);
Device.BeginInvokeOnMainThread(() => entry.Focus());
});
}
}
}