Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on Windows with latest VS #99

Merged
merged 7 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 68 additions & 72 deletions src/Engine/Controls/Carousel/SkiaCarousel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using DrawnUi.Maui.Draw;
using DrawnUi.Maui.Draw;
using DrawnUi.Maui.Draw;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Numerics;
using System.Numerics;
using SkiaControl = DrawnUi.Maui.Draw.SkiaControl;

namespace DrawnUi.Maui.Controls;
Expand Down Expand Up @@ -212,11 +207,12 @@ protected override int RenderViewsList(IEnumerable<SkiaControl> skiaControls, Sk
progress = CurrentPosition.X;
}

LastScrollProgress = ScrollProgress;
ScrollProgress = progress / progressMax;

if (ScrollProgress != LastScrollProgress)
{
LastScrollProgress = ScrollProgress;

TransitionDirection = ScrollProgress > LastScrollProgress ?
LinearDirectionType.Forward
: LinearDirectionType.Backward;
Expand Down Expand Up @@ -348,7 +344,7 @@ public double ScrollProgress
}
}

protected double LastScrollProgress { get; set; }
protected double LastScrollProgress { get; set; } = double.NegativeInfinity;

public double TransitionProgress
{
Expand Down Expand Up @@ -1278,95 +1274,95 @@ void ResetPan()

switch (args.Type)
{
case TouchActionResult.Down:
case TouchActionResult.Down:

// if (!IsUserFocused) //first finger down
if (args.Event.NumberOfTouches == 1) //first finger down
{
ResetPan();
}
// if (!IsUserFocused) //first finger down
if (args.Event.NumberOfTouches == 1) //first finger down
{
ResetPan();
}

consumed = this;
consumed = this;

break;
break;

case TouchActionResult.Panning when args.Event.NumberOfTouches == 1:
case TouchActionResult.Panning when args.Event.NumberOfTouches == 1:

if (!IsUserPanning)
{
//first pan
if (args.Event.Distance.Total.X == 0 || Math.Abs(args.Event.Distance.Total.Y) > Math.Abs(args.Event.Distance.Total.X) || Math.Abs(args.Event.Distance.Total.X) < 2)
{
return null;
}
}
if (!IsUserPanning)
{
//first pan
if (args.Event.Distance.Total.X == 0 || Math.Abs(args.Event.Distance.Total.Y) > Math.Abs(args.Event.Distance.Total.X) || Math.Abs(args.Event.Distance.Total.X) < 2)
{
return null;
}
}

if (!IsUserFocused)
{
ResetPan();
}
if (!IsUserFocused)
{
ResetPan();
}

//todo add direction
//this.IgnoreWrongDirection
//todo add direction
//this.IgnoreWrongDirection

IsUserPanning = true;
IsUserPanning = true;

var x = _panningOffset.X + args.Event.Distance.Delta.X / RenderingScale;
var y = _panningOffset.Y + args.Event.Distance.Delta.Y / RenderingScale;
var x = _panningOffset.X + args.Event.Distance.Delta.X / RenderingScale;
var y = _panningOffset.Y + args.Event.Distance.Delta.Y / RenderingScale;

Vector2 velocity;
float useVelocity = 0;
if (!IsVertical)
{
useVelocity = (float)(args.Event.Distance.Velocity.X / RenderingScale);
velocity = new(useVelocity, 0);
}
else
{
useVelocity = (float)(args.Event.Distance.Velocity.Y / RenderingScale);
velocity = new(0, useVelocity);
}
Vector2 velocity;
float useVelocity = 0;
if (!IsVertical)
{
useVelocity = (float)(args.Event.Distance.Velocity.X / RenderingScale);
velocity = new(useVelocity, 0);
}
else
{
useVelocity = (float)(args.Event.Distance.Velocity.Y / RenderingScale);
velocity = new(0, useVelocity);
}

//record velocity
VelocityAccumulator.CaptureVelocity(velocity);
//record velocity
VelocityAccumulator.CaptureVelocity(velocity);

//saving non clamped
_panningOffset.X = x;
_panningOffset.Y = y;
//saving non clamped
_panningOffset.X = x;
_panningOffset.Y = y;


var clamped = ClampOffset((float)x, (float)y, Bounces);
var clamped = ClampOffset((float)x, (float)y, Bounces);

//Debug.WriteLine($"[CAROUSEL] Panning: {_panningOffset:0} / {clamped:0}");
ApplyPosition(clamped);
//Debug.WriteLine($"[CAROUSEL] Panning: {_panningOffset:0} / {clamped:0}");
ApplyPosition(clamped);

consumed = this;
break;
consumed = this;
break;

case TouchActionResult.Up:
//Debug.WriteLine($"[Carousel] {args.Type} {IsUserFocused} {IsUserPanning} {InTransition}");
case TouchActionResult.Up:
//Debug.WriteLine($"[Carousel] {args.Type} {IsUserFocused} {IsUserPanning} {InTransition}");

if (IsUserFocused)
{
if (IsUserFocused)
{

if (IsUserPanning || InTransition)
{
consumed = this;
if (IsUserPanning || InTransition)
{
consumed = this;

var final = VelocityAccumulator.CalculateFinalVelocity(500);
var final = VelocityAccumulator.CalculateFinalVelocity(500);

//animate
CurrentSnap = CurrentPosition;
//animate
CurrentSnap = CurrentPosition;

ScrollToNearestAnchor(CurrentSnap, final);
}
ScrollToNearestAnchor(CurrentSnap, final);
}

IsUserPanning = false;
IsUserFocused = false;
IsUserPanning = false;
IsUserFocused = false;

}
}

break;
break;
}

if (consumed != null || IsUserPanning)
Expand Down
Loading
Loading