Skip to content

Instantly share code, notes, and snippets.

@roubachof
Created April 15, 2022 12:04
Show Gist options
  • Save roubachof/0ea5edca504d1fcf71cac41dfe0b0a3e to your computer and use it in GitHub Desktop.
Save roubachof/0ea5edca504d1fcf71cac41dfe0b0a3e to your computer and use it in GitHub Desktop.
using System;
using System.Threading.Tasks;
using Sharpnado.Tabs;
using Sharpnado.Tasks;
using Xamarin.Forms;
namespace Sharpnado.Presentation.CustomViews
{
public class DelayedView<TView> : LazyView<TView>
where TView : View, new()
{
public int DelayInMilliseconds { get; set; } = 200;
public override void LoadView()
{
TaskMonitor.Create(
async () =>
{
View? view = null;
if (Device.RuntimePlatform == Device.Android)
{
await Task.Run(
() =>
{
view = new TView
{
BindingContext = BindingContext,
};
});
}
else
{
view = new TView
{
BindingContext = BindingContext,
};
}
await Task.Delay(DelayInMilliseconds);
IsLoaded = true;
Content = view;
});
}
}
public class DelayedView : ALazyView
{
public static readonly BindableProperty ViewProperty = BindableProperty.Create(
nameof(View),
typeof(View),
typeof(DelayedView),
default(View));
public View View
{
get => (View)GetValue(ViewProperty);
set => SetValue(ViewProperty, value);
}
public int DelayInMilliseconds { get; set; } = 200;
public override void LoadView()
{
if (IsLoaded)
{
return;
}
TaskMonitor.Create(
async () =>
{
await Task.Delay(DelayInMilliseconds);
if (IsLoaded)
{
return;
}
IsLoaded = true;
Content = View;
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment