Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[All] Rename Accessibility -> AutomationProperties #912

Merged
merged 4 commits into from May 10, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -37,15 +37,15 @@ protected override void Init()
Placeholder = "Username"
};

username.SetValue(Accessibility.LabeledByProperty, instructions1);
username.SetValue(AutomationProperties.LabeledByProperty, instructions1);

var password = new Entry
{
Placeholder = "Password",
IsPassword = true
};

password.SetValue(Accessibility.LabeledByProperty, instructions2);
password.SetValue(AutomationProperties.LabeledByProperty, instructions2);

var button = new Button { Text = "Submit", IsEnabled = false };

Expand Down
@@ -1,19 +1,19 @@

namespace Xamarin.Forms.Controls
{
public class AccessibilityGallery : ContentPage
public class AutomationPropertiesGallery : ContentPage
{
public AccessibilityGallery()
public AutomationPropertiesGallery()
{
// https://developer.xamarin.com/guides/android/advanced_topics/accessibility/
// https://developer.xamarin.com/guides/ios/advanced_topics/accessibility/
// https://msdn.microsoft.com/en-us/windows/uwp/accessibility/basic-accessibility-information

const string EntryPlaceholder = "Your name.";
const string EntryHint = "Type your name.";
const string EntryHelpText = "Type your name.";
const string ImageName = "Roof";
const string ImageHint = "Tap to show an alert.";
const string BoxHint = "Shows a purple box.";
const string ImageHelpText = "Tap to show an alert.";
const string BoxHelpText = "Shows a purple box.";
const string BoxName = "Box";

string screenReader = "";
Expand All @@ -30,38 +30,38 @@ public AccessibilityGallery()
scrollFingers = "three fingers";
explore = "Use two fingers to swipe up or down the screen to read all of the elements on this page.";
labeledByInstructions = $"The following Entry should read aloud \"{EntryPlaceholder}.\", plus native instructions on how to use an Entry element. This text comes from the placeholder.";
imageInstructions = $"The following Image should read aloud \"{ImageName}. {ImageHint}\". You should be able to tap the image and hear an alert box.";
boxInstructions = $"The following Box should read aloud \"{BoxName}. {BoxHint}\". You should be able to tap the box and hear an alert box.";
imageInstructions = $"The following Image should read aloud \"{ImageName}. {ImageHelpText}\". You should be able to tap the image and hear an alert box.";
boxInstructions = $"The following Box should read aloud \"{BoxName}. {BoxHelpText}\". You should be able to tap the box and hear an alert box.";
break;
case Device.Android:
screenReader = "TalkBack";
scrollFingers = "two fingers";
explore = "Drag one finger across the screen to read each element on the page.";
labeledByInstructions = $"The following Entry should read aloud \"EditBox {EntryPlaceholder} for {EntryHint}.\", plus native instructions on how to use an Entry element. This text comes from the Entry placeholder and text of the Label.";
imageInstructions = $"The following Image should read aloud \"{ImageName}. {ImageHint}\". You should be able to tap the image and hear an alert box.";
boxInstructions = $"The following Box should read aloud \"{BoxName}. {BoxHint}\". You should be able to tap the box and hear an alert box.";
labeledByInstructions = $"The following Entry should read aloud \"EditBox {EntryPlaceholder} for {EntryHelpText}.\", plus native instructions on how to use an Entry element. This text comes from the Entry placeholder and text of the Label.";
imageInstructions = $"The following Image should read aloud \"{ImageName}. {ImageHelpText}\". You should be able to tap the image and hear an alert box.";
boxInstructions = $"The following Box should read aloud \"{BoxName}. {BoxHelpText}\". You should be able to tap the box and hear an alert box.";
break;
case Device.WinRT:
case Device.UWP:
case Device.WinPhone:
screenReader = "Narrator";
scrollFingers = "two fingers";
explore = "Use three fingers to swipe up the screen to read all of the elements on this page.";
labeledByInstructions = $"The following Entry should read aloud \"{EntryHint}\", plus native instructions on how to use an Entry element. This text comes from the text of the label.";
imageInstructions = $"The following Image should read aloud \"{ImageName}. {ImageHint}\". Windows does not currently support TapGestures while the Narrator is active.";
boxInstructions = $"The following Box should read aloud \"{BoxName}. {BoxHint}\". Windows does not currently support TapGestures while the Narrator is active.";
labeledByInstructions = $"The following Entry should read aloud \"{EntryHelpText}\", plus native instructions on how to use an Entry element. This text comes from the text of the label.";
imageInstructions = $"The following Image should read aloud \"{ImageName}. {ImageHelpText}\". Windows does not currently support TapGestures while the Narrator is active.";
boxInstructions = $"The following Box should read aloud \"{BoxName}. {BoxHelpText}\". Windows does not currently support TapGestures while the Narrator is active.";
break;
default:
screenReader = "the native screen reader";
break;
}

var instructions = new Label { Text = $"Please enable {screenReader}. {explore} Use {scrollFingers} to scroll the view. Tap an element once to hear the name and description and native instructions. Double tap anywhere on the screen to activate the selected element. Swipe left or right with one finger to switch to the previous or next element." };
var instructions = new Label { Text = $"Please enable {screenReader}. {explore} Use {scrollFingers} to scroll the view. Tap an element once to hear the name and HelpText and native instructions. Double tap anywhere on the screen to activate the selected element. Swipe left or right with one finger to switch to the previous or next element." };

var instructions2 = new Label { Text = labeledByInstructions };
var entryLabel = new Label { Text = EntryHint, VerticalOptions = LayoutOptions.Center };
var entryLabel = new Label { Text = EntryHelpText, VerticalOptions = LayoutOptions.Center };
var entry = new Entry { Placeholder = EntryPlaceholder };
entry.SetAccessibilityLabeledBy(entryLabel);
entry.SetAutomationPropertiesLabeledBy(entryLabel);

var entryGroup = new Grid();
entryGroup.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) });
Expand All @@ -72,41 +72,41 @@ public AccessibilityGallery()


var activityIndicator = new ActivityIndicator();
activityIndicator.SetAccessibilityName("Progress indicator");
activityIndicator.SetAutomationPropertiesName("Progress indicator");


const string ButtonText = "Update progress";
const string ButtonHint = "Tap to start/stop the activity indicator.";
const string ButtonHelpText = "Tap to start/stop the activity indicator.";
var instructions3 = new Label { Text = $"The following Button should read aloud \"{ButtonText}.\", plus native instructions on how to use a button." };
var button = new Button { Text = ButtonText };
button.SetAccessibilityHint(ButtonHint);
button.SetAutomationPropertiesHelpText(ButtonHelpText);
button.Clicked += (sender, e) =>
{
activityIndicator.IsRunning = !activityIndicator.IsRunning;
activityIndicator.SetAccessibilityHint(activityIndicator.IsRunning ? "Running." : "Not running");
activityIndicator.SetAutomationPropertiesHelpText(activityIndicator.IsRunning ? "Running." : "Not running");
};


var instructions4 = new Label { Text = imageInstructions };
var image = new Image { Source = "photo.jpg" };
// The tap gesture will NOT work on Win
image.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(() => DisplayAlert("Success", "You tapped the image", "OK")) });
image.SetAccessibilityName(ImageName);
image.SetAccessibilityHint(ImageHint);
image.SetAutomationPropertiesName(ImageName);
image.SetAutomationPropertiesHelpText(ImageHelpText);
// Images are ignored by default on iOS (at least, Forms Images are);
// make accessible in order to enable the gesture and narration
image.SetIsInAccessibleTree(true);
image.SetAutomationPropertiesIsInAccessibleTree(true);


var instructions6 = new Label { Text = boxInstructions };
var boxView = new BoxView { Color = Color.Purple };
// The tap gesture will NOT work on Win
boxView.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(() => DisplayAlert("Success", "You tapped the box", "OK")) });
boxView.SetAccessibilityName(BoxName);
boxView.SetAccessibilityHint(BoxHint);
boxView.SetAutomationPropertiesName(BoxName);
boxView.SetAutomationPropertiesHelpText(BoxHelpText);
// BoxViews are ignored by default on iOS and Win;
// make accessible in order to enable the gesture and narration
boxView.SetIsInAccessibleTree(true);
boxView.SetAutomationPropertiesIsInAccessibleTree(true);


var stack = new StackLayout
Expand All @@ -130,46 +130,46 @@ public AccessibilityGallery()
}
}

public static class AccessibilityExtensions
public static class AutomationPropertiesExtensions
{
public static void SetAccessibilityName(this VisualElement element, string name)
public static void SetAutomationPropertiesName(this VisualElement element, string name)
{
element.SetValue(Accessibility.NameProperty, name);
element.SetValue(AutomationProperties.NameProperty, name);
}

public static string GetAccessibilityName(this VisualElement element)
public static string GetAutomationPropertiesName(this VisualElement element)
{
return (string)element.GetValue(Accessibility.NameProperty);
return (string)element.GetValue(AutomationProperties.NameProperty);
}

public static void SetAccessibilityHint(this VisualElement element, string hint)
public static void SetAutomationPropertiesHelpText(this VisualElement element, string HelpText)
{
element.SetValue(Accessibility.HintProperty, hint);
element.SetValue(AutomationProperties.HelpTextProperty, HelpText);
}

public static string GetAccessibilityHint(this VisualElement element)
public static string GetAutomationPropertiesHelpText(this VisualElement element)
{
return (string)element.GetValue(Accessibility.HintProperty);
return (string)element.GetValue(AutomationProperties.HelpTextProperty);
}

public static void SetIsInAccessibleTree(this VisualElement element, bool value)
public static void SetAutomationPropertiesIsInAccessibleTree(this VisualElement element, bool value)
{
element.SetValue(Accessibility.IsInAccessibleTreeProperty, value);
element.SetValue(AutomationProperties.IsInAccessibleTreeProperty, value);
}

public static bool GetIsInAccessibleTree(this VisualElement element)
public static bool GetAutomationPropertiesIsInAccessibleTree(this VisualElement element)
{
return (bool)element.GetValue(Accessibility.IsInAccessibleTreeProperty);
return (bool)element.GetValue(AutomationProperties.IsInAccessibleTreeProperty);
}

public static void SetAccessibilityLabeledBy(this VisualElement element, Element value)
public static void SetAutomationPropertiesLabeledBy(this VisualElement element, Element value)
{
element.SetValue(Accessibility.LabeledByProperty, value);
element.SetValue(AutomationProperties.LabeledByProperty, value);
}

public static Element GetAccessibilityLabeledBy(this VisualElement element)
public static Element GetAutomationPropertiesLabeledBy(this VisualElement element)
{
return (Element)element.GetValue(Accessibility.LabeledByProperty);
return (Element)element.GetValue(AutomationProperties.LabeledByProperty);
}
}
}
6 changes: 3 additions & 3 deletions Xamarin.Forms.Controls/CoreGallery.cs
Expand Up @@ -212,7 +212,7 @@ public CoreRootView ()
}
};
#endif
SetValue(Accessibility.NameProperty, "SwapRoot");
SetValue(AutomationProperties.NameProperty, "SwapRoot");
}
}

Expand Down Expand Up @@ -245,7 +245,7 @@ public override string ToString()
}

List<GalleryPageFactory> _pages = new List<GalleryPageFactory> {
new GalleryPageFactory(() => new AccessibilityGallery(), "Accessibility"),
new GalleryPageFactory(() => new AutomationPropertiesGallery(), "Accessibility"),
new GalleryPageFactory(() => new PlatformSpecificsGallery(), "Platform Specifics"),
new GalleryPageFactory(() => new NativeBindingGalleryPage(), "Native Binding Controls Gallery"),
new GalleryPageFactory(() => new XamlNativeViews(), "Xaml Native Views Gallery"),
Expand Down Expand Up @@ -377,7 +377,7 @@ public CorePageView (Page rootPage, NavigationBehavior navigationBehavior = Navi
SelectedItem = null;
};

SetValue(Accessibility.NameProperty, "Core Pages");
SetValue(AutomationProperties.NameProperty, "Core Pages");
}

NavigationBehavior navigationBehavior;
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj
Expand Up @@ -85,7 +85,7 @@
<Compile Include="App.cs" />
<Compile Include="AppLifeCycle.cs" />
<Compile Include="Bugzilla44596SplashPage.cs" />
<Compile Include="ControlGalleryPages\AccessibilityGallery.cs" />
<Compile Include="ControlGalleryPages\AutomationPropertiesGallery.cs" />
<Compile Include="ControlGalleryPages\CellForceUpdateSizeGalleryPage.cs" />
<Compile Include="ControlGalleryPages\LayoutAddPerformance.xaml.cs">
<DependentUpon>LayoutAddPerformance.xaml</DependentUpon>
Expand Down
@@ -1,19 +1,19 @@

namespace Xamarin.Forms
{
public class Accessibility
public class AutomationProperties
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when was this released first ? isn't this a breaking change ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StephaneDelcroix 2.3.5-pre1 is when this class first appeared in a NuGet release.

{
public static readonly BindableProperty HintProperty = BindableProperty.Create("Hint", typeof(string), typeof(Element), default(string));
public static readonly BindableProperty HelpTextProperty = BindableProperty.Create("HelpText", typeof(string), typeof(Element), default(string));

public static readonly BindableProperty IsInAccessibleTreeProperty = BindableProperty.Create("IsInAccessibleTree", typeof(bool?), typeof(Element), null);

public static readonly BindableProperty LabeledByProperty = BindableProperty.Create("LabeledBy", typeof(VisualElement), typeof(Element), default(VisualElement));

public static readonly BindableProperty NameProperty = BindableProperty.Create("Name", typeof(string), typeof(Element), default(string));

public static string GetHint(BindableObject bindable)
public static string GetHelpText(BindableObject bindable)
{
return (string)bindable.GetValue(HintProperty);
return (string)bindable.GetValue(HelpTextProperty);
}

public static bool? GetIsInAccessibleTree(BindableObject bindable)
Expand All @@ -31,9 +31,9 @@ public static string GetName(BindableObject bindable)
return (string)bindable.GetValue(NameProperty);
}

public static void SetHint(BindableObject bindable, string value)
public static void SetHelpText(BindableObject bindable, string value)
{
bindable.SetValue(HintProperty, value);
bindable.SetValue(HelpTextProperty, value);
}

public static void SetIsInAccessibleTree(BindableObject bindable, bool? value)
Expand Down
8 changes: 3 additions & 5 deletions Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
Expand Up @@ -50,7 +50,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="AbsoluteLayoutFlags.cs" />
<Compile Include="Accessibility.cs" />
<Compile Include="AutomationProperties.cs" />
<Compile Include="ActionSheetArguments.cs" />
<Compile Include="AlertArguments.cs" />
<Compile Include="AnimatableKey.cs" />
Expand Down Expand Up @@ -477,7 +477,5 @@
</PropertyGroup>
<ItemGroup />
<ItemGroup />
<ItemGroup>
<Folder Include="Xaml\" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry is this not needed ?

</ItemGroup>
</Project>
<ItemGroup />
</Project>
Expand Up @@ -4,7 +4,7 @@

namespace Xamarin.Forms.Platform.Android.FastRenderers
{
internal class AccessibilityProvider : IDisposable
internal class AutomationPropertiesProvider : IDisposable
{
const string GetFromElement = "GetValueFromElement";
string _defaultContentDescription;
Expand All @@ -14,7 +14,7 @@ internal class AccessibilityProvider : IDisposable

IVisualElementRenderer _renderer;

public AccessibilityProvider(IVisualElementRenderer renderer)
public AutomationPropertiesProvider(IVisualElementRenderer renderer)
{
_renderer = renderer;
_renderer.ElementPropertyChanged += OnElementPropertyChanged;
Expand Down Expand Up @@ -88,8 +88,8 @@ void SetContentDescription(string contentDescription = GetFromElement)
string value = contentDescription;
if (value == GetFromElement)
{
value = string.Join(" ", (string)Element.GetValue(Accessibility.NameProperty),
(string)Element.GetValue(Accessibility.HintProperty));
value = string.Join(" ", (string)Element.GetValue(AutomationProperties.NameProperty),
(string)Element.GetValue(AutomationProperties.HelpTextProperty));
}

if (!string.IsNullOrWhiteSpace(value))
Expand All @@ -115,7 +115,7 @@ void SetFocusable(bool? value = null)
}

Control.Focusable =
(bool)(value ?? (bool?)Element.GetValue(Accessibility.IsInAccessibleTreeProperty) ?? _defaultFocusable);
(bool)(value ?? (bool?)Element.GetValue(AutomationProperties.IsInAccessibleTreeProperty) ?? _defaultFocusable);
}

bool SetHint(string hint = GetFromElement)
Expand Down Expand Up @@ -145,8 +145,8 @@ bool SetHint(string hint = GetFromElement)
string value = hint;
if (value == GetFromElement)
{
value = string.Join(". ", (string)Element.GetValue(Accessibility.NameProperty),
(string)Element.GetValue(Accessibility.HintProperty));
value = string.Join(". ", (string)Element.GetValue(AutomationProperties.NameProperty),
(string)Element.GetValue(AutomationProperties.HelpTextProperty));
}

textView.Hint = !string.IsNullOrWhiteSpace(value) ? value : _defaultHint;
Expand All @@ -159,7 +159,7 @@ void SetLabeledBy()
if (Element == null || Control == null)
return;

var elemValue = (VisualElement)Element.GetValue(Accessibility.LabeledByProperty);
var elemValue = (VisualElement)Element.GetValue(AutomationProperties.LabeledByProperty);

if (elemValue != null)
{
Expand Down Expand Up @@ -193,19 +193,19 @@ void OnElementChanged(object sender, VisualElementChangedEventArgs e)

void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == Accessibility.HintProperty.PropertyName)
if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName)
{
SetContentDescription();
}
else if (e.PropertyName == Accessibility.NameProperty.PropertyName)
else if (e.PropertyName == AutomationProperties.NameProperty.PropertyName)
{
SetContentDescription();
}
else if (e.PropertyName == Accessibility.IsInAccessibleTreeProperty.PropertyName)
else if (e.PropertyName == AutomationProperties.IsInAccessibleTreeProperty.PropertyName)
{
SetFocusable();
}
else if (e.PropertyName == Accessibility.LabeledByProperty.PropertyName)
else if (e.PropertyName == AutomationProperties.LabeledByProperty.PropertyName)
{
SetLabeledBy();
}
Expand Down