Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ConcentricOnboardView pt4
public sealed class ConcentricOnboardView : SKCanvasView
{
private SKRect buttonRect = new SKRect();
private SKColor backgroundColor;
private SKColor buttonColor;
private SKSurface surface;
private SKImageInfo info;
private SKCanvas canvas;
public ConcentricOnboardView()
{
buttonColor = SKColorHelper.GetRandomColor(RandomMode.LightOnly);
backgroundColor = SKColorHelper.GetRandomColor(RandomMode.LightOnly);
EnableTouchEvents = true;
}
protected override void OnTouch(SKTouchEventArgs args)
{
var point = args.Location;
switch (args.ActionType)
{
case SKTouchAction.Pressed:
if (buttonRect.Contains(point))
ActionButtonClicked();
break;
case SKTouchAction.Moved:
case SKTouchAction.Released:
case SKTouchAction.Cancelled:
break;
}
base.OnTouch(args);
}
private void ActionButtonClicked()
{
if (IsBusy) return;
IsBusy = true;
buttonColor = SKColorHelper.GetRandomColor(RandomMode.LightOnly);
InvalidateSurface();
ExecuteAnimationAsync()
.SafeFireAndForget(onException: ex => Console.WriteLine(ex));
if (Command?.CanExecute(this) ?? false)
Command?.Execute(this);
}
private async Task ExecuteAnimationAsync()
{
OnAnimationStart?.Invoke(this, EventArgs.Empty);
while (CurrentProgress < 2 * limit)
{
CurrentProgress += step;
await Task.Delay((int)(timerStep * 1000));
InvalidateSurface();
}
var color = buttonColor;
var bgColor = backgroundColor;
backgroundColor = color;
buttonColor = bgColor;
CurrentProgress = 0;
IsBusy = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.