Skip to content

Commit

Permalink
iOS accessibility fix
Browse files Browse the repository at this point in the history
  • Loading branch information
IeuanWalker committed May 7, 2024
1 parent c47a7f5 commit 2cd072b
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 175 deletions.
13 changes: 6 additions & 7 deletions Demo/App/App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<PropertyGroup Condition="'$(TargetFramework)'=='net7.0-ios'">
<CodesignKey>Apple Development: Ieuan Walker (R4SVVV33HW)</CodesignKey>
<CodesignProvision>VS: WildCard Development</CodesignProvision>
<ProvisioningType>manual</ProvisioningType>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -73,9 +74,8 @@
<Compile Update="Controls\BackButton.xaml.cs">
<DependentUpon>BackButton.xaml</DependentUpon>
</Compile>
<Compile Update="Controls\CustomSwitchExamples\DisableSupportedSwitch.xaml.cs">
<DependentUpon>DisableSupportedSwitch.xaml</DependentUpon>
<SubType>Code</SubType>
<Compile Update="Pages\IsEnabledTestPage.xaml.cs">
<DependentUpon>IsEnabledTestPage.xaml</DependentUpon>
</Compile>
</ItemGroup>

Expand Down Expand Up @@ -119,6 +119,9 @@
<MauiXaml Update="Controls\SwitchViewExamples\ImageSwitch.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Pages\IsEnabledTestPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Pages\AccessiblityTestPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
Expand All @@ -131,10 +134,6 @@
<MauiXaml Update="Pages\SwitchViewPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Controls\CustomSwitchExamples\DisableSupportedSwitch.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

</Project>
73 changes: 0 additions & 73 deletions Demo/App/Controls/CustomSwitchExamples/DisableSupportedSwitch.xaml

This file was deleted.

This file was deleted.

9 changes: 9 additions & 0 deletions Demo/App/Controls/CustomSwitchExamples/IosSwitch.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,25 @@
xmlns:switch="clr-namespace:IeuanWalker.Maui.Switch;assembly=IeuanWalker.Maui.Switch">
<switch:CustomSwitch HeightRequest="40"
HorizontalKnobMargin="1"
IsEnabled="{Binding IsEnabled, Source={RelativeSource AncestorType={x:Type ContentView}}}"
IsToggled="{Binding IsToggled, Source={RelativeSource AncestorType={x:Type ContentView}}}"
KnobBackgroundColor="White"
KnobHeight="36"
KnobLimit="Boundary"
KnobWidth="36"
Opacity="1"
SemanticProperties.Hint="{Binding AccessibilityHint, Source={RelativeSource AncestorType={x:Type ContentView}}}"
SwitchPanUpdate="CustomSwitch_SwitchPanUpdate"
Toggled="CustomSwitch_Toggled"
ToggledCommand="{Binding ToggledCommand, Source={RelativeSource AncestorType={x:Type ContentView}}}"
WidthRequest="70">
<switch:CustomSwitch.Triggers>
<DataTrigger Binding="{Binding IsEnabled, Source={RelativeSource AncestorType={x:Type ContentView}}}"
TargetType="switch:CustomSwitch"
Value="False">
<Setter Property="Opacity" Value="0.6" />
</DataTrigger>
</switch:CustomSwitch.Triggers>
<switch:CustomSwitch.StrokeShape>
<RoundRectangle CornerRadius="20" />
</switch:CustomSwitch.StrokeShape>
Expand Down
1 change: 1 addition & 0 deletions Demo/App/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<controls:CustomButton Clicked="CustomSwitchBtn_Clicked" Text="CustomSwitch examples" />
<controls:CustomButton Clicked="SwitchViewBtn_Clicked" Text="SwitchView examples" />
<controls:CustomButton Clicked="AccessibilityBtn_Clicked" Text="Accessiblity tests" />
<controls:CustomButton Clicked="IsEnabledBtn_Clicked" Text="IsEnabled tests" />
<controls:CustomButton Clicked="PanGestureBtn_Clicked" Text="PanGesture tests" />
</VerticalStackLayout>
</ContentPage.Content>
Expand Down
5 changes: 5 additions & 0 deletions Demo/App/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
11 changes: 0 additions & 11 deletions Demo/App/Pages/CustomSwitchPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,6 @@
<examples:Other5Switch IsToggled="True"
Toggled="Switch_OnToggled"
ToggledCommand="{Binding ToggledCommand}" />
<examples:DisableSupportedSwitch Margin="0,30,0,0"
Toggled="Switch_OnToggled"
ToggledCommand="{Binding ToggledCommand}" />
<examples:DisableSupportedSwitch IsEnabled="False"
IsToggled="False"
Toggled="Switch_OnToggled"
ToggledCommand="{Binding ToggledCommand}" />
<examples:DisableSupportedSwitch IsEnabled="False"
IsToggled="True"
Toggled="Switch_OnToggled"
ToggledCommand="{Binding ToggledCommand}" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>
27 changes: 27 additions & 0 deletions Demo/App/Pages/IsEnabledTestPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="App.Pages.IsEnabledTestPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:App.Controls;assembly=App"
xmlns:examples="clr-namespace:App.Controls.CustomSwitchExamples;assembly=App"
Title="IsEnabled Test Page">
<ScrollView Padding="{StaticResource PagePadding}">
<VerticalStackLayout BackgroundColor="Transparent" MinimumHeightRequest="1000">
<controls:BackButton />

<Label Style="{StaticResource sectionHeading}" Text="IsEnabled false on load" />
<examples:IosSwitch IsEnabled="False" IsToggled="False" />
<examples:IosSwitch IsEnabled="False" IsToggled="True" />

<Label Style="{StaticResource sectionHeading}" Text="Dynamit IsEnabled" />
<HorizontalStackLayout>
<Label Style="{StaticResource sectionHeading}" Text="Toggle IsEnabled: " />
<examples:AndroidSwitch x:Name="DynamicToggle" />
</HorizontalStackLayout>

<examples:IosSwitch IsEnabled="{Binding Source={x:Reference DynamicToggle}, Path=IsToggled}" IsToggled="False" />
<examples:IosSwitch IsEnabled="{Binding Source={x:Reference DynamicToggle}, Path=IsToggled}" IsToggled="True" />

</VerticalStackLayout>
</ScrollView>
</ContentPage>
9 changes: 9 additions & 0 deletions Demo/App/Pages/IsEnabledTestPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace App.Pages;

public partial class IsEnabledTestPage : ContentPage
{
public IsEnabledTestPage()
{
InitializeComponent();
}
}
2 changes: 1 addition & 1 deletion Scr/Switch/Interfaces/ISwitchView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace IeuanWalker.Maui.Switch.Interfaces;

public interface ISwitchView
public interface ISwitchView : IContentView
{
bool IsToggled { get; set; }
ICommand ToggledCommand { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions Scr/Switch/Platform/CustomContentView.ios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 2cd072b

Please sign in to comment.