Skip to content

Instantly share code, notes, and snippets.

@felipebaltazar
Created November 4, 2019 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipebaltazar/979f2bfa48320074e4320403a2509742 to your computer and use it in GitHub Desktop.
Save felipebaltazar/979f2bfa48320074e4320403a2509742 to your computer and use it in GitHub Desktop.
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