From d6a6604bac1410046e2530b1273e789d63b31fde Mon Sep 17 00:00:00 2001 From: Jean-Marie Alfonsi Date: Sat, 18 Mar 2023 17:20:56 +0100 Subject: [PATCH] MAUI Support (#29) * MAUI support * updated gitignore * change package name for nuget * updated readme * trying to create package --- .gitignore | 3 +- Maui.Skeleton/Maui.Skeleton.csproj | 83 +++++++++++++++++++ README.md | 12 ++- .../Animations/AnimationTypes.cs | 6 +- .../Animations/BaseAnimation.cs | 4 + .../Animations/BeatAnimation.cs | 6 +- .../Animations/FadeAnimation.cs | 6 +- .../Animations/HorizontalShakeAnimation.cs | 6 +- .../Animations/IAnimation.cs | 6 +- .../Animations/VerticalShakeAnimation.cs | 7 +- .../Extensions/DefaultAnimationExtension.cs | 10 +++ .../Extensions/ViewExtensions.cs | 11 ++- Xamarin.Forms.Skeleton/Skeleton.cs | 36 ++++++-- 13 files changed, 174 insertions(+), 22 deletions(-) create mode 100644 Maui.Skeleton/Maui.Skeleton.csproj diff --git a/.gitignore b/.gitignore index 4ebbc0b..b846f6d 100644 --- a/.gitignore +++ b/.gitignore @@ -268,4 +268,5 @@ FakesAssemblies/ *.plg # Visual Studio 6 workspace options file -*.opt \ No newline at end of file +*.opt +.DS_Store diff --git a/Maui.Skeleton/Maui.Skeleton.csproj b/Maui.Skeleton/Maui.Skeleton.csproj new file mode 100644 index 0000000..cff1d12 --- /dev/null +++ b/Maui.Skeleton/Maui.Skeleton.csproj @@ -0,0 +1,83 @@ + + + + net6.0 + enable + enable + true + + Sharpnado.HorusSkeleton.Maui + Maui.Skeleton + $(AssemblyName) ($(TargetFramework)) + 2.0.0.0 + 2.0.0.0 + 2.0.0.0 + true + en + false + latest + + https://github.com/roubachof/Maui.Skeleton/tree/master + https://github.com/roubachof/Maui.Skeleton/tree/master + https://raw.githubusercontent.com/HorusSoftwareUY/Xamarin.Forms.Skeleton/master/icon.png + maui, .net maui, xamarin, ios, android, xamarin.forms, plugin, component, skeleton, loader, loading, indicator, activity, activityindicator, horus + First .Net MAUI (.net 6) release \o/ + Skeleton component for .Net MAUI + Skeleton component for .Net MAUI + The new loading approach for cool apps in .Net MAUI + AgustinBonillaHorus, Jean-Marie Alfonsi + Horus, Jean-Marie Alfonsi + Copyright 2023 Horus and Sharpnado + true + MIT + true + true + true + snupkg + + + + + pdbonly + true + + + + + + + + + Animations\AnimationTypes.cs + + + Animations\BaseAnimation.cs + + + Animations\BeatAnimation.cs + + + Animations\FadeAnimation.cs + + + Animations\HorizontalShakeAnimation.cs + + + Animations\IAnimation.cs + + + Animations\VerticalShakeAnimation.cs + + + Extensions\DefaultAnimationExtension.cs + + + Extensions\ViewExtensions.cs + + + Skeleton.cs + + + + + diff --git a/README.md b/README.md index cac3636..1323d79 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,13 @@ -# Xamarin.Forms.Skeleton +# Sharpnado.HorusSkeleton.Maui && Xamarin.Forms.Skeleton -The latest trend for loading approaches in Xamarin Forms apps. Skeleton can be easily implemented on each view contained in your Xaml. +The latest trend for loading approaches in MAUI and Xamarin Forms apps. Skeleton can be easily implemented on each view contained in your Xaml. ## Sample ## Setup +* Available on NuGet: [Sharpnado.HorusSkeleton.Maui](https://www.nuget.org/packages/Sharpnado.HorusSkeleton.Maui/) [![NuGet](https://img.shields.io/nuget/v/Sharpnado.HorusSkeleton.Maui.svg?label=NuGet)](https://www.nuget.org/packages/Sharpnado.HorusSkeleton.Maui/) * Available on NuGet: [Xamarin.Forms.Skeleton](https://www.nuget.org/packages/Xamarin.Forms.Skeleton/) [![NuGet](https://img.shields.io/nuget/v/Xamarin.Forms.Skeleton.svg?label=NuGet)](https://www.nuget.org/packages/Xamarin.Forms.Skeleton/) * Install into your Core and Client projects. @@ -17,6 +18,7 @@ The latest trend for loading approaches in Xamarin Forms apps. Skeleton can be e |Xamarin.iOS|iOS 8+| |Xamarin.Android|API 16+| |Xamarin.Forms|>= 4.0.0.425677| +|.net6 MAUI|ALL| ## API Usage @@ -119,6 +121,12 @@ Add the following properties to set a loading animation with a specific backgrou ## Demo + +Warning: The sample app hasn't been ported to maui. +If you want to see and example of skeleton implementation, checkout retronado.maui: +https://github.com/roubachof/Sharpnado.TaskLoaderView + +Else, for xamarin.forms: https://github.com/HorusSoftwareUY/Xamarin.Forms.Skeleton/tree/master/SkeletonExample ## Roadmap diff --git a/Xamarin.Forms.Skeleton/Animations/AnimationTypes.cs b/Xamarin.Forms.Skeleton/Animations/AnimationTypes.cs index c2ea1c7..f77018e 100644 --- a/Xamarin.Forms.Skeleton/Animations/AnimationTypes.cs +++ b/Xamarin.Forms.Skeleton/Animations/AnimationTypes.cs @@ -1,4 +1,8 @@ -namespace Xamarin.Forms.Skeleton.Animations +#if NET6_0_OR_GREATER +namespace Maui.Skeleton.Animations +#else +namespace Xamarin.Forms.Skeleton.Animations +#endif { public enum AnimationTypes { diff --git a/Xamarin.Forms.Skeleton/Animations/BaseAnimation.cs b/Xamarin.Forms.Skeleton/Animations/BaseAnimation.cs index 53aff67..98e4b8c 100644 --- a/Xamarin.Forms.Skeleton/Animations/BaseAnimation.cs +++ b/Xamarin.Forms.Skeleton/Animations/BaseAnimation.cs @@ -1,6 +1,10 @@ using System.Threading.Tasks; +#if NET6_0_OR_GREATER +namespace Maui.Skeleton.Animations +#else namespace Xamarin.Forms.Skeleton.Animations +#endif { public abstract class BaseAnimation : IAnimation { diff --git a/Xamarin.Forms.Skeleton/Animations/BeatAnimation.cs b/Xamarin.Forms.Skeleton/Animations/BeatAnimation.cs index 77af152..1585b23 100644 --- a/Xamarin.Forms.Skeleton/Animations/BeatAnimation.cs +++ b/Xamarin.Forms.Skeleton/Animations/BeatAnimation.cs @@ -1,6 +1,8 @@ -using System.Threading.Tasks; - +#if NET6_0_OR_GREATER +namespace Maui.Skeleton.Animations +#else namespace Xamarin.Forms.Skeleton.Animations +#endif { public class BeatAnimation : BaseAnimation { diff --git a/Xamarin.Forms.Skeleton/Animations/FadeAnimation.cs b/Xamarin.Forms.Skeleton/Animations/FadeAnimation.cs index 1aa42ef..1107c13 100644 --- a/Xamarin.Forms.Skeleton/Animations/FadeAnimation.cs +++ b/Xamarin.Forms.Skeleton/Animations/FadeAnimation.cs @@ -1,6 +1,8 @@ -using System.Threading.Tasks; - +#if NET6_0_OR_GREATER +namespace Maui.Skeleton.Animations +#else namespace Xamarin.Forms.Skeleton.Animations +#endif { public class FadeAnimation : BaseAnimation { diff --git a/Xamarin.Forms.Skeleton/Animations/HorizontalShakeAnimation.cs b/Xamarin.Forms.Skeleton/Animations/HorizontalShakeAnimation.cs index 3e83acd..6ac2593 100644 --- a/Xamarin.Forms.Skeleton/Animations/HorizontalShakeAnimation.cs +++ b/Xamarin.Forms.Skeleton/Animations/HorizontalShakeAnimation.cs @@ -1,6 +1,8 @@ -using System.Threading.Tasks; - +#if NET6_0_OR_GREATER +namespace Maui.Skeleton.Animations +#else namespace Xamarin.Forms.Skeleton.Animations +#endif { public class HorizontalShakeAnimation : BaseAnimation { diff --git a/Xamarin.Forms.Skeleton/Animations/IAnimation.cs b/Xamarin.Forms.Skeleton/Animations/IAnimation.cs index 971e571..7495b41 100644 --- a/Xamarin.Forms.Skeleton/Animations/IAnimation.cs +++ b/Xamarin.Forms.Skeleton/Animations/IAnimation.cs @@ -1,4 +1,8 @@ -namespace Xamarin.Forms.Skeleton.Animations +#if NET6_0_OR_GREATER +namespace Maui.Skeleton.Animations +#else +namespace Xamarin.Forms.Skeleton.Animations +#endif { public interface IAnimation { diff --git a/Xamarin.Forms.Skeleton/Animations/VerticalShakeAnimation.cs b/Xamarin.Forms.Skeleton/Animations/VerticalShakeAnimation.cs index 5533bdb..063a81f 100644 --- a/Xamarin.Forms.Skeleton/Animations/VerticalShakeAnimation.cs +++ b/Xamarin.Forms.Skeleton/Animations/VerticalShakeAnimation.cs @@ -1,7 +1,8 @@ -using System; -using System.Threading.Tasks; - +#if NET6_0_OR_GREATER +namespace Maui.Skeleton.Animations +#else namespace Xamarin.Forms.Skeleton.Animations +#endif { public class VerticalShakeAnimation : BaseAnimation { diff --git a/Xamarin.Forms.Skeleton/Extensions/DefaultAnimationExtension.cs b/Xamarin.Forms.Skeleton/Extensions/DefaultAnimationExtension.cs index e9431f7..190cc4f 100644 --- a/Xamarin.Forms.Skeleton/Extensions/DefaultAnimationExtension.cs +++ b/Xamarin.Forms.Skeleton/Extensions/DefaultAnimationExtension.cs @@ -1,8 +1,18 @@ using System; + +#if NET6_0_OR_GREATER +using Maui.Skeleton.Animations; +#else using Xamarin.Forms.Skeleton.Animations; using Xamarin.Forms.Xaml; +#endif + +#if NET6_0_OR_GREATER +namespace Maui.Skeleton +#else namespace Xamarin.Forms.Skeleton +#endif { [ContentProperty(nameof(Source))] public sealed class DefaultAnimationExtension : IMarkupExtension diff --git a/Xamarin.Forms.Skeleton/Extensions/ViewExtensions.cs b/Xamarin.Forms.Skeleton/Extensions/ViewExtensions.cs index 305c89f..4a88df7 100644 --- a/Xamarin.Forms.Skeleton/Extensions/ViewExtensions.cs +++ b/Xamarin.Forms.Skeleton/Extensions/ViewExtensions.cs @@ -1,8 +1,15 @@ -using System.Collections.Generic; -using System.Linq; + +#if NET6_0_OR_GREATER +using Microsoft.Maui.Controls.Internals; +#else using Xamarin.Forms.Internals; +#endif +#if NET6_0_OR_GREATER +namespace Maui.Skeleton.Extensions +#else namespace Xamarin.Forms.Skeleton.Extensions +#endif { internal static class ViewExtensions { diff --git a/Xamarin.Forms.Skeleton/Skeleton.cs b/Xamarin.Forms.Skeleton/Skeleton.cs index 43e73d0..fd00784 100644 --- a/Xamarin.Forms.Skeleton/Skeleton.cs +++ b/Xamarin.Forms.Skeleton/Skeleton.cs @@ -1,9 +1,19 @@ using System; using System.Linq; +#if NET6_0_OR_GREATER +using Maui.Skeleton.Animations; +using Maui.Skeleton.Extensions; +#else using Xamarin.Forms.Skeleton.Animations; using Xamarin.Forms.Skeleton.Extensions; +#endif + +#if NET6_0_OR_GREATER +namespace Maui.Skeleton +#else namespace Xamarin.Forms.Skeleton +#endif { public static class Skeleton { @@ -95,10 +105,13 @@ private static void OnIsBusyChanged(BindableObject bindable, bool newValue) } } - static void HandleIsBusyChanged(BindableObject bindable, bool isBusyNewValue)
 {
 if (!(bindable is View)) + static void HandleIsBusyChanged(BindableObject bindable, bool isBusyNewValue) + { + if (!(bindable is View)) return; - var view = (View)bindable;
 if (isBusyNewValue) + var view = (View)bindable; + if (isBusyNewValue) { if (GetHide(bindable)) { @@ -118,7 +131,9 @@ private static void OnIsBusyChanged(BindableObject bindable, bool newValue) SetBackgroundColor(view); RunAnimation(view); - }
 }
 else + } + } + else { if (GetHide(bindable)) { @@ -139,13 +154,14 @@ private static void OnIsBusyChanged(BindableObject bindable, bool newValue) RestoreTextColor(view); } } - }
 } + } + } private static void SetLayoutChilds(Layout layout) { if (layout.Children != null && layout.Children.Count > 0) { - layout.Children.ToList().ForEach(x => x.SetValue(VisualElement.OpacityProperty, 0)); + layout.Children.ToList().ForEach(x => ((View)x).SetValue(VisualElement.OpacityProperty, 0)); } } @@ -153,7 +169,7 @@ private static void RestoreLayoutChilds(Layout layout) { if (layout.Children != null && layout.Children.Count > 0) { - layout.Children.ToList().ForEach(x => x.SetValue(VisualElement.OpacityProperty, 1)); + layout.Children.ToList().ForEach(x => ((View)x).SetValue(VisualElement.OpacityProperty, 1)); } } @@ -193,13 +209,21 @@ private static void SetTextColor(View view) { hasDynamic = hasDynamic || label.HasDynamicColorOnProperty(Label.TextColorProperty); SetOriginalTextColor(label, label.TextColor); +#if NET6_0_OR_GREATER + label.TextColor = Colors.Transparent; +#else label.TextColor = Color.Transparent; +#endif } else if (view is Button button) { hasDynamic = hasDynamic || button.HasDynamicColorOnProperty(Button.TextColorProperty); SetOriginalTextColor(button, button.TextColor); +#if NET6_0_OR_GREATER + button.TextColor = Colors.Transparent; +#else button.TextColor = Color.Transparent; +#endif } SetUseDynamicTextColor(view, hasDynamic);