# MarketAlly.TouchEffect.Maui [![NuGet](https://img.shields.io/nuget/v/MarketAlly.TouchEffect.Maui.svg)](https://www.nuget.org/packages/MarketAlly.TouchEffect.Maui) [![NuGet Downloads](https://img.shields.io/nuget/dt/MarketAlly.TouchEffect.Maui.svg)](https://www.nuget.org/packages/MarketAlly.TouchEffect.Maui) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![.NET 10](https://img.shields.io/badge/.NET-10.0-blue.svg)](https://dotnet.microsoft.com/) A comprehensive touch effect library for .NET MAUI applications by **MarketAlly**, providing rich interaction feedback and animations across all platforms. MarketAlly.TouchEffect.Maui brings advanced touch handling, hover states, long press detection, and smooth animations to any MAUI view. ## What's New in v2.0.0 - **.NET 10 Support** - Updated to target .NET 10 with latest MAUI - **TouchBehavior** - New Behavior-based API as modern alternative to Effects - **Thread-Safe Architecture** - Complete thread-safety overhaul with proper synchronization - **Enhanced Logging** - Integrated logging throughout with `ITouchEffectLogger` interface - **Improved Code Organization** - TouchEffect split into partial classes for maintainability - **Bug Fixes** - Fixed `ForceUpdateStateWithoutAnimation` to actually disable animations - **Performance** - Replaced LINQ with for-loops in hot paths to reduce allocations ## Features ### Core Capabilities - **Universal Touch Feedback** - Consistent touch interactions across iOS, Android, and Windows - **50+ Customizable Properties** - Fine-grained control over every aspect of the touch experience - **Hardware-Accelerated Animations** - Smooth, performant transitions using platform-native acceleration - **Accessibility First** - Full keyboard, screen reader, and assistive technology support - **Memory Efficient** - WeakEventManager pattern prevents memory leaks - **Thread-Safe** - Proper synchronization for animation state management ### Visual Effects - **Opacity Animations** - Fade effects on touch with customizable values - **Scale Transformations** - Grow or shrink elements during interaction - **Color Transitions** - Dynamic background color changes for different states - **Translation & Rotation** - Move and rotate elements during touch - **Native Platform Effects** - Android ripple effects and iOS haptic feedback ### Advanced Features - **Long Press Detection** - Configurable duration with separate command binding - **Hover Support** - Mouse and stylus hover states on supported platforms - **Toggle Behavior** - Switch-like functionality with persistent state - **Gesture Threshold** - Configurable movement tolerance before cancellation - **Command Pattern** - MVVM-friendly with ICommand support ## Platform Support | Platform | Version | Features | |-------------|------------|---------------------------------------------------| | iOS | 13.0+ | Full support with haptic feedback | | Android | API 24+ | Full support with native ripple effects | | Windows | 10.0.17763+ | Full support with WinUI 3 animations | | Mac Catalyst| - | Not currently supported | | Tizen | - | Not currently supported | ## Installation ### Package Manager ```bash Install-Package MarketAlly.TouchEffect.Maui -Version 2.0.0 ``` ### .NET CLI ```bash dotnet add package MarketAlly.TouchEffect.Maui --version 2.0.0 ``` ### PackageReference ```xml ``` ## Quick Start ### 1. Configure Your App In your `MauiProgram.cs`: ```csharp using MarketAlly.TouchEffect.Maui.Hosting; public static class MauiProgram { public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .UseMauiApp() .UseMauiTouchEffect() // Add this line .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); }); return builder.Build(); } } ``` ### 2. Add Touch Effects to Your Views #### XAML Approach (Attached Properties) ```xml ``` #### NEW: TouchBehavior Approach (v2.0.0) ```xml ``` #### Fluent Builder Approach ```csharp using MarketAlly.TouchEffect.Maui; // Configure a button with fluent API var button = new Frame { Content = new Label { Text = "Click Me" } } .ConfigureTouchEffect() .AsButton() .WithCommand(viewModel.TapCommand) .Build(); // Create a card with hover effect var card = new Frame { Content = contentView } .ConfigureTouchEffect() .AsCard() .WithCommand(viewModel.SelectCommand) .Build(); // Apply a preset var listItem = new StackLayout() .WithListItemPreset(); ``` #### Using Presets ```csharp // Apply common UI patterns instantly TouchEffectPresets.Button.ApplyPrimary(myButton); TouchEffectPresets.Card.ApplyElevated(myCard); TouchEffectPresets.ListItem.Apply(myListItem); TouchEffectPresets.IconButton.ApplyFloatingAction(myFab); // Or use extension methods myButton.WithButtonPreset(); myCard.WithCardPreset(); myListItem.WithListItemPreset(); ``` ## Logging Configuration Configure logging to debug touch effect issues: ```csharp // Use the default console logger TouchEffect.SetLogger(new DefaultTouchEffectLogger()); // Or implement custom logging public class MyLogger : ITouchEffectLogger { public void LogError(Exception ex, string context, string? info = null) { // Log to your preferred service (App Center, Sentry, etc.) } public void LogWarning(string message, string context) { Debug.WriteLine($"[TouchEffect Warning] {context}: {message}"); } public void LogInfo(string message, string context) { // Optional info logging } } // Configure in your app startup TouchEffect.SetLogger(new MyLogger()); ``` ## Common Use Cases ### Interactive Cards ```xml ``` ### Toggle Buttons ```xml