diff --git a/Demo/App/App.csproj b/Demo/App/App.csproj index 46aced7..78f485d 100644 --- a/Demo/App/App.csproj +++ b/Demo/App/App.csproj @@ -33,6 +33,7 @@ Apple Development: Ieuan Walker (R4SVVV33HW) VS: WildCard Development + manual @@ -73,9 +74,8 @@ BackButton.xaml - - DisableSupportedSwitch.xaml - Code + + IsEnabledTestPage.xaml @@ -119,6 +119,9 @@ MSBuild:Compile + + MSBuild:Compile + MSBuild:Compile @@ -131,10 +134,6 @@ MSBuild:Compile - - Designer - MSBuild:Compile - diff --git a/Demo/App/Controls/CustomSwitchExamples/DisableSupportedSwitch.xaml b/Demo/App/Controls/CustomSwitchExamples/DisableSupportedSwitch.xaml deleted file mode 100644 index 53510c9..0000000 --- a/Demo/App/Controls/CustomSwitchExamples/DisableSupportedSwitch.xaml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Demo/App/Controls/CustomSwitchExamples/DisableSupportedSwitch.xaml.cs b/Demo/App/Controls/CustomSwitchExamples/DisableSupportedSwitch.xaml.cs deleted file mode 100644 index 17a5dee..0000000 --- a/Demo/App/Controls/CustomSwitchExamples/DisableSupportedSwitch.xaml.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System.Windows.Input; -using IeuanWalker.Maui.Switch; -using IeuanWalker.Maui.Switch.Events; -using IeuanWalker.Maui.Switch.Helpers; -using Microsoft.Maui.Controls.Shapes; - -namespace App.Controls.CustomSwitchExamples; - -[XamlCompilation(XamlCompilationOptions.Compile)] -public partial class DisableSupportedSwitch : ContentView -{ - public DisableSupportedSwitch() - { - InitializeComponent(); - } - - public event EventHandler? Toggled = null; - - public static readonly BindableProperty IsToggledProperty = BindableProperty.Create(nameof(IsToggled), typeof(bool), typeof(DisableSupportedSwitch), false, BindingMode.TwoWay); - - public bool IsToggled - { - get => (bool)GetValue(IsToggledProperty); - set => SetValue(IsToggledProperty, value); - } - - public static readonly BindableProperty ToggledCommandProperty = BindableProperty.Create(nameof(ToggledCommand), typeof(ICommand), typeof(DisableSupportedSwitch)); - - public ICommand ToggledCommand - { - get => (ICommand)GetValue(ToggledCommandProperty); - set => SetValue(ToggledCommandProperty, value); - } - - void CustomSwitch_SwitchPanUpdate(CustomSwitch customSwitch, SwitchPanUpdatedEventArgs e) - { - KnobContent.TranslationX = -(e.TranslateX + e.XRef); - - double t = e.Percentage * 0.01; - - if (IsEnabled) - { - Color fromColorLight = e.IsToggled ? Color.FromArgb("#cdf4cc") : Color.FromArgb("#f7cccc"); - Color toColorLight = e.IsToggled ? Color.FromArgb("#f7cccc") : Color.FromArgb("#cdf4cc"); - - Color fromColorDark = e.IsToggled ? Color.FromArgb("#46d744") : Color.FromArgb("#dd2424"); - Color toColorDark = e.IsToggled ? Color.FromArgb("#dd2424") : Color.FromArgb("#46d744"); - - customSwitch.KnobBackgroundColor = ColorAnimationUtil.ColorAnimation(fromColorLight, toColorLight, t); - customSwitch.KnobStroke = ColorAnimationUtil.ColorAnimation(fromColorDark, toColorDark, t); - OffKnobLabel.TextColor = Color.FromArgb("#dd2424"); - OnKnobLabel.TextColor = Color.FromArgb("#46d744"); - } - else - { - customSwitch.KnobBackgroundColor = Color.FromArgb("#A9A9A9"); - customSwitch.KnobStroke = Color.FromArgb("#808080"); - OffKnobLabel.TextColor = Color.FromArgb("#808080"); - OnKnobLabel.TextColor = Color.FromArgb("#808080"); - } - - double zeroToFive = Calculate(0, 5, t); - double fiveToZero = Calculate(5, 0, t); - - customSwitch.KnobStrokeShape = new RoundRectangle - { - CornerRadius = e.IsToggled ? - new CornerRadius(zeroToFive, fiveToZero, zeroToFive, fiveToZero) : - new CornerRadius(fiveToZero, zeroToFive, fiveToZero, zeroToFive) - }; - - } - - void CustomSwitch_Toggled(object sender, ToggledEventArgs e) - { - Toggled?.Invoke(sender, e); - } - - public static double Calculate(double from, double to, double percentage) - { - return from + ((to - from) * percentage); - } -} \ No newline at end of file diff --git a/Demo/App/Controls/CustomSwitchExamples/IosSwitch.xaml b/Demo/App/Controls/CustomSwitchExamples/IosSwitch.xaml index ecbb17a..ca614df 100644 --- a/Demo/App/Controls/CustomSwitchExamples/IosSwitch.xaml +++ b/Demo/App/Controls/CustomSwitchExamples/IosSwitch.xaml @@ -5,16 +5,25 @@ xmlns:switch="clr-namespace:IeuanWalker.Maui.Switch;assembly=IeuanWalker.Maui.Switch"> + + + + + diff --git a/Demo/App/MainPage.xaml b/Demo/App/MainPage.xaml index a1a0c6d..44a7014 100644 --- a/Demo/App/MainPage.xaml +++ b/Demo/App/MainPage.xaml @@ -9,6 +9,7 @@ + diff --git a/Demo/App/MainPage.xaml.cs b/Demo/App/MainPage.xaml.cs index 1437ce2..e711150 100644 --- a/Demo/App/MainPage.xaml.cs +++ b/Demo/App/MainPage.xaml.cs @@ -24,6 +24,11 @@ async void AccessibilityBtn_Clicked(object sender, EventArgs e) await Navigation.PushAsync(new AccessiblityTestPage()); } + async void IsEnabledBtn_Clicked(object sender, EventArgs e) + { + await Navigation.PushAsync(new IsEnabledTestPage()); + } + async void PanGestureBtn_Clicked(object sender, EventArgs e) { await Navigation.PushAsync(new PanGestureTestPage()); diff --git a/Demo/App/Pages/CustomSwitchPage.xaml b/Demo/App/Pages/CustomSwitchPage.xaml index a8ff51b..379ec63 100644 --- a/Demo/App/Pages/CustomSwitchPage.xaml +++ b/Demo/App/Pages/CustomSwitchPage.xaml @@ -99,17 +99,6 @@ - - - \ No newline at end of file diff --git a/Demo/App/Pages/IsEnabledTestPage.xaml b/Demo/App/Pages/IsEnabledTestPage.xaml new file mode 100644 index 0000000..f72d2e5 --- /dev/null +++ b/Demo/App/Pages/IsEnabledTestPage.xaml @@ -0,0 +1,27 @@ + + + + + + + + + \ No newline at end of file diff --git a/Demo/App/Pages/IsEnabledTestPage.xaml.cs b/Demo/App/Pages/IsEnabledTestPage.xaml.cs new file mode 100644 index 0000000..39fd68b --- /dev/null +++ b/Demo/App/Pages/IsEnabledTestPage.xaml.cs @@ -0,0 +1,9 @@ +namespace App.Pages; + +public partial class IsEnabledTestPage : ContentPage +{ + public IsEnabledTestPage() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/Scr/Switch/Interfaces/ISwitchView.cs b/Scr/Switch/Interfaces/ISwitchView.cs index a5f118b..f292cdb 100644 --- a/Scr/Switch/Interfaces/ISwitchView.cs +++ b/Scr/Switch/Interfaces/ISwitchView.cs @@ -2,7 +2,7 @@ namespace IeuanWalker.Maui.Switch.Interfaces; -public interface ISwitchView +public interface ISwitchView : IContentView { bool IsToggled { get; set; } ICommand ToggledCommand { get; set; } diff --git a/Scr/Switch/Platform/CustomContentView.ios.cs b/Scr/Switch/Platform/CustomContentView.ios.cs index d92f3f3..c4539b5 100644 --- a/Scr/Switch/Platform/CustomContentView.ios.cs +++ b/Scr/Switch/Platform/CustomContentView.ios.cs @@ -10,11 +10,14 @@ public class CustomContentView : ContentView public CustomContentView(IContentView virtualView) { _switchView = (ISwitchView)virtualView; + _switchUIAccessibilityTrait = new UISwitch().AccessibilityTraits; IsAccessibilityElement = true; } + public override bool UserInteractionEnabled { get => _switchView.IsEnabled; } + public override string? AccessibilityValue { get => _switchView.IsToggled ? "1" : "0";