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: Updated sample, fix touch manipulation & iOS rendering, fix key error + code cleanup and more #8

Merged
merged 30 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a08a017
fix: git status
FreakyAli Feb 27, 2023
64e982e
Update README.md
FreakyAli Feb 27, 2023
5a6c15a
feat: skeleton effect for maui
FreakyAli Mar 1, 2023
42f22cc
fix: code clean up and proj setup
FreakyAli Mar 1, 2023
860204c
Update README.md
FreakyAli Mar 2, 2023
7691d8e
Update README.md
FreakyAli Mar 2, 2023
5e528a4
Update README.md
FreakyAli Mar 2, 2023
543a554
fix: skeletoneffect for maui
FreakyAli Mar 2, 2023
6827a47
Update README.md
FreakyAli Mar 2, 2023
607a6d8
Update README.md
FreakyAli Mar 2, 2023
681f4ba
Update README.md
FreakyAli Mar 2, 2023
355c89c
fix: added some sample code
FreakyAli Mar 3, 2023
61b07ad
fix: skeleton ui design
FreakyAli Mar 7, 2023
d5e6bd0
fix: readme pulled
FreakyAli Mar 7, 2023
b649a39
fix: view extensions added
FreakyAli Mar 7, 2023
9af04f3
fix: skeletonview ui design in prog
FreakyAli Mar 8, 2023
5f4005a
skeleton design
FreakyAli Mar 10, 2023
2a4570c
fix: skeleton effect with sample is ready
FreakyAli Mar 12, 2023
d5b995a
fix: added touchtracking sample
FreakyAli Mar 14, 2023
67fe469
fix: added samples for touch tracking
FreakyAli Mar 14, 2023
39e31f3
Update README.md
FreakyAli Mar 14, 2023
12d2b79
fix: some fix
FreakyAli Mar 14, 2023
865b2e0
Updated sample, fix touch manipulation & iOS rendering, fix key error…
juliusdeblaaij Oct 6, 2023
1e32d99
fix: Bump packages and code clean up (#9)
FreakyAli Oct 6, 2023
6d6113a
Merge branch 'master' into develop
FreakyAli Oct 6, 2023
8d50953
fix: versioning updates
FreakyAli Oct 6, 2023
88b9427
fix: code clean up
FreakyAli Oct 6, 2023
cbb4460
fix: Codefactor fixes
FreakyAli Oct 6, 2023
ff6bcc8
fix: code clean up and codefactor
FreakyAli Oct 6, 2023
2db2809
fix: bumped samples
FreakyAli Oct 7, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<RootNamespace>Maui.FreakyEffects</RootNamespace>
<AssemblyVersion>0.1.0</AssemblyVersion>
<AssemblyFileVersion>0.1.0</AssemblyFileVersion>
<Version>0.1.0-pre</Version>
<Version>0.1.0</Version>
<NeutralLanguage>en</NeutralLanguage>
<!--Version of C# to use -->
<PackageId>FreakyEffects</PackageId>
Expand Down Expand Up @@ -38,6 +38,9 @@
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net7.0-ios|AnyCPU'">
<CreatePackage>false</CreatePackage>
</PropertyGroup>
<ItemGroup>
<None Remove="Platforms\Android\" />
<None Remove="Platforms\iOS\" />
Expand All @@ -52,6 +55,6 @@
<Folder Include="Shared\Skeleton\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SkiaSharp.Views.Maui.Controls" Version="2.88.3" />
<PackageReference Include="SkiaSharp.Views.Maui.Controls" Version="2.88.6" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ public static float ToPixels(this Context self, double dp)

return (float)Math.Round(dp * _displayDensity);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ protected override void OnAttached()
{
return;
}

_touchHandler = new TouchHandler();
_touchHandler.TouchAction += TouchHandlerOnTouch;
_touchHandler.Capture = _touchEffect.Capture;
_touchHandler.RegisterEvents(_view);

}

private void TouchHandlerOnTouch(object sender, TouchActionEventArgs args)
Expand All @@ -43,5 +41,4 @@ protected override void OnDetached()
_touchHandler.TouchAction -= TouchHandlerOnTouch;
_touchHandler.UnregisterEvents(_view);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,145 +81,144 @@
return screenPointerCoords;
}

private void OnTouch(object sender, View.TouchEventArgs args)
{
// Two object common to all the events
View senderView = sender as View;
MotionEvent motionEvent = args.Event;

// Get the pointer index
int pointerIndex = motionEvent.ActionIndex;

// Get the id that identifies a finger over the course of its progress
int id = motionEvent.GetPointerId(pointerIndex);

senderView.GetLocationOnScreen(_locationOnScreen);
TouchTrackingPoint screenPointerCoords =
GetScreenPointerCoordinates(_locationOnScreen, motionEvent, pointerIndex);


// Use ActionMasked here rather than Action to reduce the number of possibilities
switch (args.Event.ActionMasked)
{
case MotionEventActions.Down:
case MotionEventActions.PointerDown:
FireEvent(this, id, TouchActionType.Pressed, screenPointerCoords, true);

if (!_idToTouchHandlerDictionary.ContainsKey(id))
{
_idToTouchHandlerDictionary.Add(id, this);
}

_capture = Capture;

if (UseTouchSlop)
{
_lastX = args.Event.GetX();
_lastY = args.Event.GetY();
}
break;

case MotionEventActions.Move:
if (motionEvent.PointerCount == 1 && UseTouchSlop)
{
id = motionEvent.GetPointerId(0);
senderView.GetLocationOnScreen(_locationOnScreen);

if (!_moveInProgress)
{
var x = args.Event.GetX();
var y = args.Event.GetY();

var xDiff = Math.Abs(_lastX - x);
var yDiff = Math.Abs(_lastY - y);

if (xDiff > _slop || yDiff > _slop)
{
_moveInProgress = true;
}
}

if (_moveInProgress)
{
screenPointerCoords = GetScreenPointerCoordinates(_locationOnScreen, motionEvent, pointerIndex);
FireEvent(this, id, TouchActionType.Moved, screenPointerCoords, true);
}

break;
}

_moveInProgress = false;
_lastX = 0;
_lastY = 0;

// Multiple Move events are bundled, so handle them in a loop
for (pointerIndex = 0; pointerIndex < motionEvent.PointerCount; pointerIndex++)
{
id = motionEvent.GetPointerId(pointerIndex);

if (_capture)
{
senderView.GetLocationOnScreen(_locationOnScreen);

screenPointerCoords = GetScreenPointerCoordinates(_locationOnScreen, motionEvent, pointerIndex);
FireEvent(this, id, TouchActionType.Moved, screenPointerCoords, true);
}
else
{
CheckForBoundaryHop(id, screenPointerCoords);

if (_idToTouchHandlerDictionary[id] != null)
{
FireEvent(_idToTouchHandlerDictionary[id], id, TouchActionType.Moved, screenPointerCoords, true);
}
}
}
break;

case MotionEventActions.Up:
case MotionEventActions.Pointer1Up:
if (_capture)
{
FireEvent(this, id, TouchActionType.Released, screenPointerCoords, false);
}
else
{
CheckForBoundaryHop(id, screenPointerCoords);

if (_idToTouchHandlerDictionary[id] != null)
{
FireEvent(_idToTouchHandlerDictionary[id], id, TouchActionType.Released, screenPointerCoords, false);
}
}
_idToTouchHandlerDictionary.Remove(id);

_moveInProgress = false;
_lastX = 0;
_lastY = 0;
break;

case MotionEventActions.Cancel:
if (_capture)
{
FireEvent(this, id, TouchActionType.Cancelled, screenPointerCoords, false);
}
else
{
if (_idToTouchHandlerDictionary[id] != null)
{
FireEvent(_idToTouchHandlerDictionary[id], id, TouchActionType.Cancelled, screenPointerCoords, false);
}
}
_idToTouchHandlerDictionary.Remove(id);

_moveInProgress = false;
_lastX = 0;
_lastY = 0;
break;
}
}

private void CheckForBoundaryHop(int id, TouchTrackingPoint pointerLocation)

Check notice on line 221 in Maui.FreakyEffects/Maui.FreakyEffects/Platforms/Android/TouchHandler.cs

View check run for this annotation

codefactor.io / CodeFactor

Maui.FreakyEffects/Maui.FreakyEffects/Platforms/Android/TouchHandler.cs#L84-L221

Complex Method
{
TouchHandler touchEffectHit = null;

Expand Down Expand Up @@ -268,5 +267,4 @@
OnTouchAction(touchEffect._view,
new TouchActionEventArgs(id, actionType, point, isInContact));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ protected override void OnAttached()
_touchHandler.TouchAction += TouchHandlerOnTouch;
_touchHandler.Capture = _touchEffect.Capture;
_touchHandler.RegisterEvents(_view);

}

private void TouchHandlerOnTouch(object sender, TouchActionEventArgs args)
Expand All @@ -43,4 +42,4 @@ protected override void OnDetached()
_touchHandler.TouchAction -= TouchHandlerOnTouch;
_touchHandler.UnregisterEvents(_view);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public void Detach()
viewDictionary.Remove(_view);
}


// touches = touches of interest; evt = all touches of type UITouch
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
Expand Down Expand Up @@ -75,7 +74,6 @@ public override void TouchesMoved(NSSet touches, UIEvent evt)
public override void TouchesEnded(NSSet touches, UIEvent evt)
{
base.TouchesEnded(touches, evt);

foreach (UITouch touch in touches.Cast<UITouch>())
{
long id = touch.Handle.Handle.ToInt64();
Expand Down Expand Up @@ -120,8 +118,6 @@ public override void TouchesCancelled(NSSet touches, UIEvent evt)
void CheckForBoundaryHop(UITouch touch)
{
long id = touch.Handle.Handle.ToInt64();

// TODO: Might require converting to a List for multiple hits
TouchRecognizer recognizerHit = null;

foreach (UIView view in viewDictionary.Keys)
Expand Down
3 changes: 1 addition & 2 deletions Maui.FreakyEffects/Maui.FreakyEffects/Shared/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using PlatformTouchEffects = Maui.FreakyEffects.Platforms.iOS.TouchEffect;
#endif


namespace Maui.FreakyEffects;

public static class Extensions
Expand All @@ -18,4 +17,4 @@ public static void InitFreakyEffects(this IEffectsBuilder effects)
{
effects.Add<TouchEffect, PlatformTouchEffects>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ public enum AnimationTypes
Fade,
VerticalShake,
HorizontalShake
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public abstract class BaseAnimation : IAnimation
public double Parameter { get; set; }

protected abstract Task<bool> Animate(BindableObject bindable);

protected abstract Task StopAnimation(BindableObject bindable);

public void Start(BindableObject bindable)
Expand All @@ -35,5 +34,4 @@ private async Task<bool> Run(BindableObject bindable)
return await Run(bindable);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
/// <inheritdoc/>
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{

return null;
//var valueAsString = value?.ToString() ?? string.Empty;

Expand Down Expand Up @@ -58,5 +57,4 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
// var type = (AnimationTypes)Enum.Parse(typeof(AnimationTypes), value);
// return new DefaultAnimationExtension() { Source = type }.ProvideValue(null);
//}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ protected override async Task StopAnimation(BindableObject bindable)
var self = (View)bindable;
await self.ScaleTo(1, 100);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ protected override async Task StopAnimation(BindableObject bindable)
var self = (View)bindable;
await self.FadeTo(1, 100);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ protected override async Task StopAnimation(BindableObject bindable)
if (bindable is View self)
await self.TranslateTo(0, 0, 100);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ public interface IAnimation
{
void Start(BindableObject bindable);
void Stop(BindableObject bindable);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class VerticalShakeAnimation : BaseAnimation
public VerticalShakeAnimation(int interval, double? parameter)
{
this.Interval = (uint)interval;
this.Parameter = parameter.HasValue ? parameter.Value : 15;
this.Parameter = parameter ?? 15;
}

protected override async Task<bool> Animate(BindableObject bindable)
Expand All @@ -21,5 +21,4 @@ protected override async Task StopAnimation(BindableObject bindable)
if (bindable is View self)
await self.TranslateTo(0, 0, 100);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ public class SceneGestureResponder : ISceneGestureResponder
private readonly ISKScene _skScene;
private readonly ITouchGestureRecognizer _touchGestureRecognizer;

public TouchManipulationMode TouchManipulationMode { get; set; }
public bool EnableTwoFingersPanInIsotropicScaleMode { get; set; }
public float DoubleTapScaleFactor { get; set; } = 2f;

public SceneGestureResponder(ISKScene skScene, ITouchGestureRecognizer touchGestureRecognizer)
{
_skScene = skScene;
_touchGestureRecognizer = touchGestureRecognizer;
}

public TouchManipulationMode TouchManipulationMode { get; set; }
public bool EnableTwoFingersPanInIsotropicScaleMode { get; set; }
public float DoubleTapScaleFactor { get; set; } = 2f;

public void StartResponding()
{
_touchGestureRecognizer.OnPan += TouchGestureRecognizerOnPan;
Expand All @@ -31,7 +31,6 @@ public void StopResponding()
_touchGestureRecognizer.OnDoubleTap -= TouchGestureRecognizerOnDoubleTap;
}


protected virtual void TouchGestureRecognizerOnPinch(object sender, PinchEventArgs args)
{
if (args.TouchActionType != TouchActionType.Moved)
Expand Down Expand Up @@ -105,4 +104,4 @@ private float GetAngleBetweenVectors(SKPoint oldVector, SKPoint newVector)
float angle = newAngle - oldAngle;
return angle;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,23 @@ public void ProcessTouchEvent(long id, TouchActionType type, SKPoint location)
switch (type)
{
case TouchActionType.Pressed:
_touchDictionary.Add(id, new TouchManipulationInfo
// TODO: System.ArgumentException Message = An item with the same key has already been added.Key: 1 happens after a few pinches
var newTouchManipulation = new TouchManipulationInfo
{
PreviousPoint = location,
NewPoint = location,
MoveCounter = 0
});
};

if (_touchDictionary.ContainsKey(id))
{
_touchDictionary[id] = newTouchManipulation;
}
else
{
_touchDictionary.Add(id, newTouchManipulation);
}

break;

case TouchActionType.Moved:
Expand Down Expand Up @@ -125,4 +136,4 @@ private void DetectPinchAndPanGestures(TouchActionType touchActionType)
OnPinch?.Invoke(this, new PinchEventArgs(previousPoint, newPoint, pivotPoint, touchActionType));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public void MoveByVector(SKPoint vector)
return;
}
var resultPoint = invertedMatrix.MapVector(vector.X, vector.Y);
Matrix.PreConcat(SKMatrix.CreateTranslation(resultPoint.X, resultPoint.Y));

// TODO: Matrix.IsIdentity was true, even after multiple gestures, which means that the Matrix doesn't hold on to it's new values. Matrix = ... is the right syntax.
Matrix = Matrix.PreConcat(SKMatrix.CreateTranslation(resultPoint.X, resultPoint.Y));

if (CenterBoundary.IsEmpty)
{
return;
Expand All @@ -46,34 +49,34 @@ public void MoveByVector(SKPoint vector)
if (!CenterBoundary.Contains(center))
{
//rollback
Matrix.PreConcat(SKMatrix.CreateTranslation(-resultPoint.X, -resultPoint.Y));
Matrix = Matrix.PreConcat(SKMatrix.CreateTranslation(-resultPoint.X, -resultPoint.Y));
}
}

public void MoveToPoint(SKPoint point)
{
var center = GetCenter();
SKPoint diff = center - point;
Matrix.PreConcat(SKMatrix.CreateTranslation(diff.X, diff.Y));
Matrix = Matrix.PreConcat(SKMatrix.CreateTranslation(diff.X, diff.Y));
}

public void Rotate(SKPoint point, float radians)
{
var currentAngle = GetAngleInRadians();
var angleDiff = radians - currentAngle;
Matrix.PreConcat(SKMatrix.CreateRotation(angleDiff, point.X, point.Y));
Matrix = Matrix.PreConcat(SKMatrix.CreateRotation(angleDiff, point.X, point.Y));
}

public void RotateByRadiansDelta(SKPoint point, float radiansDelta)
{
Matrix.PreConcat(SKMatrix.CreateRotation(radiansDelta, point.X, point.Y));
Matrix = Matrix.PreConcat(SKMatrix.CreateRotation(radiansDelta, point.X, point.Y));
}

public void Zoom(SKPoint point, float scale)
{
var currentScale = GetScale();
var scaleFactor = scale / currentScale;
Matrix.PreConcat(SKMatrix.CreateScale(scaleFactor, scaleFactor, point.X, point.Y));
Matrix = Matrix.PreConcat(SKMatrix.CreateScale(scaleFactor, scaleFactor, point.X, point.Y));
}

public void ZoomByScaleFactor(SKPoint point, float scaleFactor)
Expand All @@ -92,15 +95,13 @@ public void ZoomByScaleFactor(SKPoint point, float scaleFactor)
return;
}
}
Matrix.PreConcat(SKMatrix.CreateScale(scaleFactor, scaleFactor, point.X, point.Y));
}

Matrix = Matrix.PreConcat(SKMatrix.CreateScale(scaleFactor, scaleFactor, point.X, point.Y));
}

public SKPoint GetCanvasPointFromViewPoint(SKPoint viewPoint)
{

SKMatrix invertedMatrix;
if (!Matrix.TryInvert(out invertedMatrix))
if (!Matrix.TryInvert(out SKMatrix invertedMatrix))
{
return SKPoint.Empty;
}
Expand Down Expand Up @@ -130,7 +131,7 @@ public float GetScale()
//https://stackoverflow.com/questions/4361242/extract-rotation-scale-values-from-2d-transformation-matrix
var scaleX = Matrix.ScaleX;
var skewY = Matrix.SkewY;
var result = Math.Sqrt(scaleX * scaleX + skewY * skewY);
var result = Math.Sqrt((scaleX * scaleX) + (skewY * skewY));
return (float)result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Maui.FreakyEffects.TouchTracking;

public class TouchActionEventArgs : EventArgs
{
public TouchActionEventArgs(long id, TouchActionType type, TouchTrackingPoint location, bool isInContact)
{
Id = id;
Type = type;
Location = location;
IsInContact = isInContact;
}

public long Id { private set; get; }
public TouchActionType Type { private set; get; }
public TouchTrackingPoint Location { private set; get; }
public bool IsInContact { private set; get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Maui.FreakyEffects.TouchTracking;

public enum TouchActionType
{
Entered = 0,
Pressed = 1,
Moved = 2,
Released = 3,
Cancelled = 4,
Exited = 5
}
Loading
Loading