Skip to content

Commit

Permalink
Add MAUI TouchEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheesebaron committed Feb 22, 2025
1 parent 5964bd4 commit b7fc497
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<PackageProjectUrl>https://github.com/Cheesebaron/SkiaScene</PackageProjectUrl>
<authors>Ondrej Kunc</authors>
<owners>Ondrej Kunc</owners>
<owners>Ondrej Kunc,Cheesebaron</owners>
<tags>skiascene,xamarin,graphics,ios,android,uwp,cross-platform,skiasharp</tags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
1 change: 1 addition & 0 deletions source/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<ItemGroup>
<PackageVersion Include="SkiaSharp" Version="3.116.0" />
<PackageVersion Include="NerdBank.GitVersioning" Version="3.7.115" />
<PackageVersion Include="Microsoft.Maui.Controls" Version="9.0.40" />
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions source/SkiaScene.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchTracking.iOS", "TouchT
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaScene", "SkiaScene\SkiaScene\SkiaScene.csproj", "{39D92863-4CFD-434D-91E9-80625E284813}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchTracking.MAUI", "TouchTracking\TouchTracking.MAUI\TouchTracking.MAUI.csproj", "{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0F654EA4-9F36-4366-88AD-C76F7FBA8774}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -109,6 +117,22 @@ Global
{39D92863-4CFD-434D-91E9-80625E284813}.Release|x64.Build.0 = Release|Any CPU
{39D92863-4CFD-434D-91E9-80625E284813}.Release|x86.ActiveCfg = Release|Any CPU
{39D92863-4CFD-434D-91E9-80625E284813}.Release|x86.Build.0 = Release|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Debug|ARM.ActiveCfg = Debug|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Debug|ARM.Build.0 = Debug|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Debug|x64.ActiveCfg = Debug|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Debug|x64.Build.0 = Debug|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Debug|x86.ActiveCfg = Debug|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Debug|x86.Build.0 = Debug|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Release|Any CPU.Build.0 = Release|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Release|ARM.ActiveCfg = Release|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Release|ARM.Build.0 = Release|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Release|x64.ActiveCfg = Release|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Release|x64.Build.0 = Release|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Release|x86.ActiveCfg = Release|Any CPU
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -119,6 +143,7 @@ Global
{0BE88B46-BC5F-4F31-97DF-5CE1FD8EB04B} = {5EAAF631-6151-4F9B-B022-344EACF47C8B}
{4DC6A992-335F-4016-9FDF-DB6A5CD55892} = {5EAAF631-6151-4F9B-B022-344EACF47C8B}
{39D92863-4CFD-434D-91E9-80625E284813} = {86604022-2CED-4F88-8A0B-B518738BBD5D}
{FB10DDDE-D255-43C6-AFBC-ADE51FEB5166} = {5EAAF631-6151-4F9B-B022-344EACF47C8B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0D1DB94F-B0A3-4696-ADF4-DAD4021008F6}
Expand Down
2 changes: 1 addition & 1 deletion source/TouchTracking/TouchTracking.Droid/TouchHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void OnTouch(object sender, View.TouchEventArgs args)

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

_capture = Capture;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using TouchTracking.Droid;

namespace TouchTracking.MAUI.Platforms.Android;

public class TouchEffect : Microsoft.Maui.Controls.Platform.PlatformEffect
{
private TouchHandler? _touchHandler;
private global::Android.Views.View? _view;
private TouchTracking.MAUI.TouchEffect? _touchEffect;

protected override void OnAttached()
{
_view = Control ?? Container;

_touchEffect =
(TouchTracking.MAUI.TouchEffect?)Element.Effects.FirstOrDefault(e => e is TouchTracking.MAUI.TouchEffect);

if (_touchEffect == null)
{
return;
}
_touchHandler = new TouchHandler();
_touchHandler.TouchAction += TouchHandlerOnTouch;
_touchHandler.Capture = _touchEffect.Capture;
_touchHandler.RegisterEvents(_view);
}

private void TouchHandlerOnTouch(object sender, TouchActionEventArgs args)
{
_touchEffect?.OnTouchAction(sender, args);
}

protected override void OnDetached()
{
if (_touchHandler == null)
{
return;
}

_touchHandler.TouchAction -= TouchHandlerOnTouch;
_touchHandler.UnregisterEvents(_view);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TouchTracking.MAUI;

// All the code in this file is only included on Windows.
public class PlatformClass1
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using TouchTracking.iOS;
using UIKit;

namespace TouchTracking.MAUI.Platforms.iOS;

public class TouchEffect : Microsoft.Maui.Controls.Platform.PlatformEffect
{
private TouchHandler? _touchHandler;
private UIView? _view;
private TouchTracking.MAUI.TouchEffect? _touchEffect;

protected override void OnAttached()
{
_view = Control ?? Container;

_touchEffect =
(TouchTracking.MAUI.TouchEffect?)Element.Effects.FirstOrDefault(e => e is TouchTracking.MAUI.TouchEffect);

if (_touchEffect == null)
{
return;
}

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

private void TouchHandlerOnTouch(object sender, TouchActionEventArgs args)
{
_touchEffect?.OnTouchAction(sender, args);
}

protected override void OnDetached()
{
if (_touchHandler == null)
{
return;
}
_touchHandler.TouchAction -= TouchHandlerOnTouch;
_touchHandler.UnregisterEvents(_view);
}
}
17 changes: 17 additions & 0 deletions source/TouchTracking/TouchTracking.MAUI/TouchEffect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace TouchTracking.MAUI;

public class TouchEffect : RoutingEffect
{
public event TouchActionEventHandler? TouchAction;

public TouchEffect() : base("TouchTracking.TouchEffect")
{
}

public bool Capture { set; get; }

public void OnTouchAction(object element, TouchActionEventArgs args)
{
TouchAction?.Invoke(element, args);
}
}
34 changes: 34 additions & 0 deletions source/TouchTracking/TouchTracking.MAUI/TouchTracking.MAUI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.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>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" />
<ProjectReference Include="..\TouchTracking\TouchTracking.csproj" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'" >
<ProjectReference Include="..\TouchTracking.Droid\TouchTracking.Droid.csproj" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'" >
<ProjectReference Include="..\TouchTracking.iOS\TouchTracking.iOS.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Platforms\MacCatalyst\" />
</ItemGroup>
</Project>

0 comments on commit b7fc497

Please sign in to comment.