Created
November 4, 2019 04:28
-
-
Save felipebaltazar/979f2bfa48320074e4320403a2509742 to your computer and use it in GitHub Desktop.
ConcentricOnboardView pt4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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