Skip to content

Commit

Permalink
Merge pull request #3 from IeuanWalker/Accessability
Browse files Browse the repository at this point in the history
Accessibility
  • Loading branch information
IeuanWalker authored Jul 1, 2021
2 parents ee336a3 + 27d10b1 commit 0c14996
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
8 changes: 3 additions & 5 deletions Demo/App/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
<!-- Events -->
<Label FontSize="Large" Text="Events" />
<Label FontSize="Medium" Text="Clicked" />
<stateButton:StateButton AutomationProperties.HelpText="Button"
AutomationProperties.IsInAccessibleTree="True"
<stateButton:StateButton AutomationProperties.IsInAccessibleTree="True"
AutomationProperties.Name="Test"
Clicked="StateButton_OnClicked"
HorizontalOptions="Center">
Expand Down Expand Up @@ -90,7 +89,6 @@
BackgroundColor="LightGray"
HeightRequest="1"
HorizontalOptions="Fill" />

<!-- Commands -->
<Label FontSize="Large" Text="Commands" />
<Label FontSize="Medium" Text="Clicked" />
Expand Down Expand Up @@ -195,7 +193,6 @@
BackgroundColor="LightGray"
HeightRequest="1"
HorizontalOptions="Fill" />

<!-- Complex -->
<Label FontSize="Large" Text="Complex" />
<stateButton:StateButton Clicked="Card_OnClicked" HorizontalOptions="Fill">
Expand Down Expand Up @@ -233,12 +230,14 @@
<Image Source="https://instabug.com/blog/wp-content/uploads/2018/10/Oct_Articles_01_Xamarin.png" />
<Label x:Name="Description"
Margin="20,0"
AutomationProperties.IsInAccessibleTree="True"
FontSize="Default"
HorizontalOptions="Center"
LineBreakMode="TailTruncation"
MaxLines="3"
Text="I'm baby vape jean shorts hammock air plant gluten-free thundercats, DIY kale chips master cleanse kickstarter vinyl cronut iceland. Coloring book cold-pressed cray authentic seitan. Snackwave bicycle rights ramps hoodie shaman readymade. Kitsch venmo hella pug, chillwave squid four dollar toast hashtag." />
<Label Margin="20,0,20,10"
AutomationProperties.IsInAccessibleTree="True"
HorizontalOptions="End"
HorizontalTextAlignment="End"
Text="See more..."
Expand Down Expand Up @@ -286,7 +285,6 @@
BackgroundColor="LightGray"
HeightRequest="1"
HorizontalOptions="Fill" />

<!-- Experiment -->
<Label FontSize="Large" Text="Experiment" />
<stateButton:StateButton HorizontalOptions="Fill">
Expand Down
15 changes: 14 additions & 1 deletion Scr/StateButton.Android/StateButtonRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using System.Linq;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using View = Xamarin.Forms.View;
using Android.Views.Accessibility;
using AndroidView = Android.Views;

[assembly: ExportRenderer(typeof(StateButton.StateButton), typeof(StateButtonRenderer))]

Expand All @@ -14,6 +15,7 @@ public class StateButtonRenderer : FrameRenderer
{
public StateButtonRenderer(Context context) : base(context)
{
SetAccessibilityDelegate(new MyAccessibilityDelegate());
}

protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
Expand Down Expand Up @@ -65,5 +67,16 @@ protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
}
};
}

private class MyAccessibilityDelegate : AccessibilityDelegate
{
public override void OnInitializeAccessibilityNodeInfo(AndroidView.View host, AccessibilityNodeInfo info)
{
base.OnInitializeAccessibilityNodeInfo(host, info);
info.ClassName = "android.widget.Button";
info.Clickable = true;
}
}

}
}
2 changes: 2 additions & 0 deletions Scr/StateButton.iOS/StateButtonRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
{
base.OnElementChanged(e);

AccessibilityTraits = UIAccessibilityTrait.Button;

if (e.OldElement != null) return;

if (!e.NewElement.GestureRecognizers.Any())
Expand Down
5 changes: 3 additions & 2 deletions Scr/StateButton/StateButton.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard1.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>

<LangVersion>8.0</LangVersion>
<!-- Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand Down

0 comments on commit 0c14996

Please sign in to comment.