Skip to content

Commit

Permalink
Merge pull request #11 from taublast/Dev
Browse files Browse the repository at this point in the history
1.9.3.1
  • Loading branch information
taublast authored Dec 31, 2024
2 parents 71d1eaa + 0b121ec commit 8af5942
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 38 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Library for .NET MAUI to handle gestures. Can be consumed in Xaml and code-behin

This library is used by [DrawnUI for .NET MAUI](https://github.com/taublast/DrawnUi.Maui).

## What's New - 1.9.2.5
## What's New - 1.9.3.1

* Fixed crash on iOS targeting less than v18.
* Compiled for .NET 8
* Velocity calculation optimized
* Compiled for both .NET 8 and 9.

## Features

Expand Down
2 changes: 1 addition & 1 deletion dev/github_uploadnugets.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ REM Define the source directory for the packages
set "source_dir=E:\Nugets"

REM Define the list of file masks for the packages
set "mask[1]=AppoMobi.Maui.Gestures.1.9.1.1*.*nupkg"
set "mask[1]=AppoMobi.Maui.Gestures.1.9.2.5*.*nupkg"
set "mask_count=1"

REM Loop through each file mask
Expand Down
13 changes: 9 additions & 4 deletions src/AppoMobi.Maui.Gestures.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,28 @@
net8.0-android34.0;
net8.0-ios17.0;
net8.0-maccatalyst17.0;
net9.0;
net9.0-android;
net9.0-ios;
net9.0-maccatalyst;
</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0;</TargetFrameworks>
<UseMaui>true</UseMaui>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0;net9.0-windows10.0.19041.0;</TargetFrameworks>

<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

</PropertyGroup>

<PropertyGroup>
<!--<PackageReleaseNotes>Under construction</PackageReleaseNotes>-->
<Version>1.9.2.5</Version>
<Version>1.9.3.1</Version>
<Title>AppoMobi.Maui.Gestures</Title>
<Description>Gestures effect and helpers for .NET MAUI</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
4 changes: 2 additions & 2 deletions src/Platforms/Windows/TouchEffect.Windows.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Maui.Controls.Platform;
using System.ComponentModel;
using Microsoft.Maui.Controls.Platform;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
using System.ComponentModel;

namespace AppoMobi.Maui.Gestures
{
Expand Down
44 changes: 16 additions & 28 deletions src/TouchActionEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,35 @@ public static PointF GetVelocity(TouchActionEventArgs current, TouchActionEventA
if (current.Distance.Delta.X == 0 && current.Distance.Delta.Y == 0 && (current.Type == TouchActionType.Released
|| current.Type == TouchActionType.Cancelled || current.Type == TouchActionType.Exited))
{
//we gonna recalc velocity based on this event time, usually this is the case of finger released
// maybe finger released
var prevDeltaSecondsX = previous.Distance.Velocity.X != 0 ? previous.Distance.Delta.X / previous.Distance.Velocity.X : 0;
var prevDeltaSecondsY = previous.Distance.Velocity.Y != 0 ? previous.Distance.Delta.Y / previous.Distance.Velocity.Y : 0;

var prevDeltaSeconds = 0.0f;
var prevDeltaSecondsX = previous.Distance.Delta.X / previous.Distance.Velocity.X;
var prevDeltaSecondsY = previous.Distance.Delta.Y / previous.Distance.Velocity.Y;
var prevDeltaSeconds = !double.IsNaN(prevDeltaSecondsX) ? prevDeltaSecondsX : prevDeltaSecondsY;

if (!double.IsNaN(prevDeltaSecondsX))
{
prevDeltaSeconds = prevDeltaSecondsX;
}
else
if (!double.IsNaN(prevDeltaSecondsY))
deltaDistance = new(previous.Distance.Delta.X, previous.Distance.Delta.Y);
deltaSeconds = (float)((current.Timestamp - previous.Timestamp).TotalSeconds + prevDeltaSeconds);
if (deltaSeconds > 0)
{
prevDeltaSeconds = prevDeltaSecondsY;
velocity = new PointF(deltaDistance.X / deltaSeconds, deltaDistance.Y / deltaSeconds);
}
deltaDistance = new(previous.Distance.Delta.X, previous.Distance.Delta.Y);
deltaSeconds = (float)((current.Time - previous.Time).TotalMilliseconds / 1000.0f + prevDeltaSeconds);
velocity = new PointF(deltaDistance.X / deltaSeconds, deltaDistance.Y / deltaSeconds);

//Debug.WriteLine($"[V-LAST] {current.Type} distance {deltaDistance.Y:0.0} time {deltaSeconds:0.000} => {velocity.Y}");
}
else
{
deltaDistance = new(current.Distance.Delta.X, current.Distance.Delta.Y);
deltaSeconds = (float)((current.Time - previous.Time).TotalMilliseconds / 1000.0f);
velocity = new PointF(deltaDistance.X / deltaSeconds, deltaDistance.Y / deltaSeconds);
deltaSeconds = (float)((current.Timestamp - previous.Timestamp).TotalSeconds);
if (deltaSeconds > 0)
{
velocity = new PointF(deltaDistance.X / deltaSeconds, deltaDistance.Y / deltaSeconds);
}
}
}

//Trace.WriteLine(previous != null ? $"[G] {velocity.Y} {previous.Type}" : $"[G] {velocity.Y} NULL");

return velocity;
}

/// <summary>
/// Using Distance.Delta and Time of previous args
/// </summary>
Expand All @@ -106,28 +104,18 @@ public TouchActionEventArgs(long id, TouchActionType type,
object elementBindingContext)
{
Id = id;
Time = DateTime.Now;
Type = type;
Location = location;
Context = elementBindingContext;
Distance = new DistanceInfo();
}

public DateTime Time { get; private set; }

public TouchActionEventArgs()
{
Time = DateTime.Now;
Distance = new DistanceInfo();
}



public PointF GetScaledLocation(float scale)
{
return new PointF(Location.X * scale, Location.Y * scale);
}

public long Id { private set; get; }

/// <summary>
Expand Down

0 comments on commit 8af5942

Please sign in to comment.