Skip to content

Commit

Permalink
Merge pull request #95 from IeuanWalker/master
Browse files Browse the repository at this point in the history
Accessibility
  • Loading branch information
robinmanuelthiel authored Jul 5, 2021
2 parents 21c1beb + 565d30d commit e532b11
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 11 deletions.
13 changes: 13 additions & 0 deletions Flex.Android/CustomRenderers/GestureFrameRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Flex.Controls;
using AndroidView = Android.Views;
using Android.Views.Accessibility;

[assembly: ExportRenderer(typeof(GestureFrame), typeof(GestureFrameRenderer))]
namespace Flex.Android.CustomRenderers
Expand All @@ -14,6 +16,17 @@ public class GestureFrameRenderer : Xamarin.Forms.Platform.Android.AppCompat.Fra
{
public GestureFrameRenderer(Context context) : base(context)
{
SetAccessibilityDelegate(new GestureFrameRendererAccessibilityDelegate());
}

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

protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
Expand Down
3 changes: 2 additions & 1 deletion Flex.Demo.iOS/Flex.Demo.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@
<ProjectReference Include="..\Flex.iOS\Flex.iOS.csproj">
<Project>{43DD689A-3918-43EB-B654-8E1C54F23C72}</Project>
<Name>Flex.iOS</Name>
<IsAppExtension>false</IsAppExtension>
<IsWatchApp>false</IsWatchApp>
</ProjectReference>
<ProjectReference Include="..\Flex\Flex.csproj">
<Project>{4FBE2794-BD54-4C5E-B95A-46B2D5606C5F}</Project>
Expand All @@ -153,7 +155,6 @@
<BundleResource Include="Resources\right.png" />
<BundleResource Include="Resources\right%402x.png" />
<BundleResource Include="Resources\right%403x.png" />
<BundleResource Include="Resources\arrow.svg" />
<BundleResource Include="Resources\lightbulb.png" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 0 additions & 6 deletions Flex.Demo/Flex.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,4 @@
<ItemGroup>
<ProjectReference Include="..\Flex\Flex.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="lightbulb.png" />
</ItemGroup>
<ItemGroup>
<Content Include="lightbulb.png" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion Flex.Demo/FlexDemoPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
IconPadding="0"
CornerRadius="38"
Icon="lightbulb.png"
AccessibleName="Light bulb"
ForegroundColor="#ffffff"
HighlightForegroundColor="#49516F"
BackgroundColor="#6279B8"
Expand All @@ -72,7 +73,7 @@
<!-- Small Buttons -->
<Label Text="Small Buttons" HorizontalTextAlignment="Center" HorizontalOptions="Center"/>
<StackLayout Orientation="Horizontal" HorizontalOptions="Center" VerticalOptions="Start">
<flex:FlexButton
<flex:FlexButton
WidthRequest="40"
HeightRequest="40"
CornerRadius="20"
Expand Down
3 changes: 3 additions & 0 deletions Flex.UWP/CutomRenderers/GestureFrameRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Xamarin.Forms;
using Xamarin.Forms.Platform.UWP;
using Flex.Controls;
using Windows.UI.Xaml.Automation.Peers;

[assembly: ExportRenderer(typeof(GestureFrame), typeof(GestureFrameRenderer))]
namespace Flex.UWP.CustomRenderers
Expand All @@ -33,6 +34,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.F
{
base.OnElementChanged(e);

Control.SetAutomationPropertiesAccessibilityView(e.NewElement, AccessibilityView.Control);

if (e.OldElement == null)
{
FixFormsBackgroundColor(e.NewElement);
Expand Down
2 changes: 2 additions & 0 deletions Flex.iOS/CustomRenderers/GestureFrameRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
{
base.OnElementChanged(e);

AccessibilityTraits = UIAccessibilityTrait.Button;

if (e.OldElement == null)
{
// Fix Xamarin.Forms Frame BackgroundColor Bug (https://github.com/xamarin/Xamarin.Forms/issues/2218)
Expand Down
12 changes: 11 additions & 1 deletion Flex/Controls/FlexButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ public bool HasShadow
set => SetValue(HasShadowProperty, value);
}

public static readonly BindableProperty AccessibleNameProperty = BindableProperty.Create(nameof(AccessibleName), typeof(string), typeof(FlexButton), null);
public string AccessibleName
{
get => (string)GetValue(AccessibleNameProperty);
set => SetValue(AccessibleNameProperty, value);
}


#endregion

#region Commands
Expand Down Expand Up @@ -249,7 +257,6 @@ protected override void OnBindingContextChanged()

protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var test = 0f;
if (propertyName == PaddingProperty.PropertyName)
{
userChangedPadding = true;
Expand Down Expand Up @@ -358,6 +365,9 @@ void SetButtonMode()
mode = ButtonMode.TextOnly;
}

// Set Accessibility Name
AutomationProperties.SetName(Border, AccessibleName ?? Text);

if (ButtonIcon == null || ButtonText == null)
return;

Expand Down
4 changes: 2 additions & 2 deletions Nuget/Forms.Controls.FlexButton.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata minClientVersion="">
<id>Forms.Controls.FlexButton</id>
<version>0.13.0</version>
<version>0.14.0</version>
<title>FlexButton for Xamarin.Forms</title>
<authors>Robin-Manuel Thiel</authors>
<owners>Robin-Manuel Thiel</owners>
Expand All @@ -12,7 +12,7 @@
<icon>images/Logo-150.png</icon>
<description>Flexible button control for Xamarin.Forms</description>
<summary>Flexible button control for Xamarin.Forms</summary>
<releaseNotes>Update to Xamarin.Forms 4.8</releaseNotes>
<releaseNotes>Add Accessiblity Options</releaseNotes>
<copyright></copyright>
<language></language>
<tags>flex xamarin.forms control button flexbutton xamarin flexible pill</tags>
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Take a look a the [Demo Project](/Flex.Demo) in this repository for a full sampl
| `IconTintEnabled` | `true` | Enables tinting of the icon (Set to false, if your icon is colorized) |
| `HasShadow` | `false` | Enables Xamarin.Forms Frame's Shadow around the button |
| `MaxLines` | `1` | Maximum number of lines for test. Set it to `-1` for flexible amount of lines |
| `AccessibleName` | `string.Empty` | Accessibility Name for Automation |

| Event | Description |
|------------------|---------|
Expand Down

0 comments on commit e532b11

Please sign in to comment.