From 9c10d1adb64994e572aa06bb979d95e3b0783a2e Mon Sep 17 00:00:00 2001 From: Gerald Versluis Date: Tue, 14 Feb 2023 16:52:36 +0100 Subject: [PATCH] Obsolete some of the AutomationProperties (#13104) * Obsolete some of the AutomationProperties * Update SemanticProperties.cs --- .../AutomationPropertiesProvider.cs | 2 ++ .../Core/src/Windows/AccessibilityExtensions.cs | 4 ++++ src/Controls/src/Core/AutomationProperties.cs | 17 +++++++++++++++++ .../Handlers/ListView/iOS/CellRenderer.cs | 3 +++ .../NavigationPage/iOS/NavigationRenderer.cs | 4 ++++ .../Handlers/VisualElementRenderer.cs | 2 ++ .../iOS/Extensions/AccessibilityExtensions.cs | 8 ++++++++ .../iOS/Extensions/ToolbarItemExtensions.cs | 4 ++++ .../Android/AutomationPropertiesProvider.cs | 6 ++++++ .../Extensions/AccessibilityExtensions.cs | 13 ++++++++++--- src/Controls/src/Core/SemanticProperties.cs | 2 ++ 11 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/Compatibility/Core/src/Android/FastRenderers/AutomationPropertiesProvider.cs b/src/Compatibility/Core/src/Android/FastRenderers/AutomationPropertiesProvider.cs index c3a0c2c5f05a..d5db18c31acb 100644 --- a/src/Compatibility/Core/src/Android/FastRenderers/AutomationPropertiesProvider.cs +++ b/src/Compatibility/Core/src/Android/FastRenderers/AutomationPropertiesProvider.cs @@ -92,6 +92,7 @@ void OnElementChanged(object sender, VisualElementChangedEventArgs e) void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { +#pragma warning disable CS0618 // Type or member is obsolete if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName) { SetContentDescription(); @@ -108,6 +109,7 @@ void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { SetLabeledBy(); } +#pragma warning restore CS0618 // Type or member is obsolete } } } diff --git a/src/Compatibility/Core/src/Windows/AccessibilityExtensions.cs b/src/Compatibility/Core/src/Windows/AccessibilityExtensions.cs index 32b334ac86ab..dbabe5c488a7 100644 --- a/src/Compatibility/Core/src/Windows/AccessibilityExtensions.cs +++ b/src/Compatibility/Core/src/Windows/AccessibilityExtensions.cs @@ -22,9 +22,13 @@ static string ConcatenateNameAndHint(Element Element) { string separator; +#pragma warning disable CS0618 // Type or member is obsolete var name = (string)Element.GetValue(AutomationProperties.NameProperty); +#pragma warning restore CS0618 // Type or member is obsolete +#pragma warning disable CS0618 // Type or member is obsolete var hint = (string)Element.GetValue(AutomationProperties.HelpTextProperty); +#pragma warning restore CS0618 // Type or member is obsolete if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(hint)) diff --git a/src/Controls/src/Core/AutomationProperties.cs b/src/Controls/src/Core/AutomationProperties.cs index 91e66ed2135c..33dbebcf8d45 100644 --- a/src/Controls/src/Core/AutomationProperties.cs +++ b/src/Controls/src/Core/AutomationProperties.cs @@ -1,10 +1,13 @@ #nullable disable +using System; + namespace Microsoft.Maui.Controls { /// public class AutomationProperties { /// + [Obsolete("Use SemanticProperties.Hint instead. See the conceptual docs about accessibility for more information.")] public static readonly BindableProperty HelpTextProperty = BindableProperty.Create("HelpText", typeof(string), typeof(AutomationProperties), default(string)); /// @@ -13,15 +16,19 @@ public class AutomationProperties public static readonly BindableProperty ExcludedWithChildrenProperty = BindableProperty.Create("ExcludedWithChildren", typeof(bool?), typeof(AutomationProperties), null); /// + [Obsolete("Use a SemanticProperties.Description binding instead. See the conceptual docs about accessibility for more information.")] public static readonly BindableProperty LabeledByProperty = BindableProperty.Create("LabeledBy", typeof(VisualElement), typeof(AutomationProperties), default(VisualElement)); /// + [Obsolete("Use SemanticProperties.Description instead. See the conceptual docs about accessibility for more information.")] public static readonly BindableProperty NameProperty = BindableProperty.Create("Name", typeof(string), typeof(AutomationProperties), default(string)); /// public static string GetHelpText(BindableObject bindable) { +#pragma warning disable CS0618 // Type or member is obsolete return (string)bindable.GetValue(HelpTextProperty); +#pragma warning restore CS0618 // Type or member is obsolete } /// @@ -39,19 +46,25 @@ public static string GetHelpText(BindableObject bindable) [System.ComponentModel.TypeConverter(typeof(ReferenceTypeConverter))] public static VisualElement GetLabeledBy(BindableObject bindable) { +#pragma warning disable CS0618 // Type or member is obsolete return (VisualElement)bindable.GetValue(LabeledByProperty); +#pragma warning restore CS0618 // Type or member is obsolete } /// public static string GetName(BindableObject bindable) { +#pragma warning disable CS0618 // Type or member is obsolete return (string)bindable.GetValue(NameProperty); +#pragma warning restore CS0618 // Type or member is obsolete } /// public static void SetHelpText(BindableObject bindable, string value) { +#pragma warning disable CS0618 // Type or member is obsolete bindable.SetValue(HelpTextProperty, value); +#pragma warning restore CS0618 // Type or member is obsolete } /// @@ -68,13 +81,17 @@ public static void SetExcludedWithChildren(BindableObject bindable, bool? value) /// public static void SetLabeledBy(BindableObject bindable, VisualElement value) { +#pragma warning disable CS0618 // Type or member is obsolete bindable.SetValue(LabeledByProperty, value); +#pragma warning restore CS0618 // Type or member is obsolete } /// public static void SetName(BindableObject bindable, string value) { +#pragma warning disable CS0618 // Type or member is obsolete bindable.SetValue(NameProperty, value); +#pragma warning restore CS0618 // Type or member is obsolete } } } diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellRenderer.cs index 0b96b2f9cd67..a0e390947e65 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellRenderer.cs @@ -76,6 +76,7 @@ public virtual void SetAccessibility(UITableViewCell tableViewCell, Cell cell) else tableViewCell.AccessibilityElementsHidden = false; +#pragma warning disable CS0618 // Type or member is obsolete if (cell.IsSet(AutomationProperties.NameProperty)) tableViewCell.AccessibilityLabel = cell.GetValue(AutomationProperties.NameProperty).ToString(); else @@ -85,6 +86,8 @@ public virtual void SetAccessibility(UITableViewCell tableViewCell, Cell cell) tableViewCell.AccessibilityHint = cell.GetValue(AutomationProperties.HelpTextProperty).ToString(); else tableViewCell.AccessibilityHint = null; +#pragma warning restore CS0618 // Type or member is obsolete + } public virtual void SetBackgroundColor(UITableViewCell tableViewCell, Cell cell, UIColor color) diff --git a/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs index 970f7c1cbe40..789d88e6d0a6 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs @@ -861,7 +861,9 @@ static void SetAccessibilityHint(UIBarButtonItem uIBarButtonItem, Element elemen if (_defaultAccessibilityHint == null) _defaultAccessibilityHint = uIBarButtonItem.AccessibilityHint; +#pragma warning disable CS0618 // Type or member is obsolete uIBarButtonItem.AccessibilityHint = (string)element.GetValue(AutomationProperties.HelpTextProperty) ?? _defaultAccessibilityHint; +#pragma warning restore CS0618 // Type or member is obsolete } static void SetAccessibilityLabel(UIBarButtonItem uIBarButtonItem, Element element) @@ -872,7 +874,9 @@ static void SetAccessibilityLabel(UIBarButtonItem uIBarButtonItem, Element eleme if (_defaultAccessibilityLabel == null) _defaultAccessibilityLabel = uIBarButtonItem.AccessibilityLabel; +#pragma warning disable CS0618 // Type or member is obsolete uIBarButtonItem.AccessibilityLabel = (string)element.GetValue(AutomationProperties.NameProperty) ?? _defaultAccessibilityLabel; +#pragma warning restore CS0618 // Type or member is obsolete } static void SetIsAccessibilityElement(UIBarButtonItem uIBarButtonItem, Element element) diff --git a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs index abd8a233bd24..b343709c5ff6 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs @@ -35,9 +35,11 @@ public abstract partial class VisualElementRenderer : IPlatformViewHan [nameof(VisualElement.BackgroundColor)] = MapBackgroundColor, [AutomationProperties.IsInAccessibleTreeProperty.PropertyName] = MapAutomationPropertiesIsInAccessibleTree, #if WINDOWS +#pragma warning disable CS0618 // Type or member is obsolete [AutomationProperties.NameProperty.PropertyName] = MapAutomationPropertiesName, [AutomationProperties.HelpTextProperty.PropertyName] = MapAutomationPropertiesHelpText, [AutomationProperties.LabeledByProperty.PropertyName] = MapAutomationPropertiesLabeledBy, +#pragma warning restore CS0618 // Type or member is obsolete #endif }; diff --git a/src/Controls/src/Core/Compatibility/iOS/Extensions/AccessibilityExtensions.cs b/src/Controls/src/Core/Compatibility/iOS/Extensions/AccessibilityExtensions.cs index 5aa3777918b5..1929392becfb 100644 --- a/src/Controls/src/Core/Compatibility/iOS/Extensions/AccessibilityExtensions.cs +++ b/src/Controls/src/Core/Compatibility/iOS/Extensions/AccessibilityExtensions.cs @@ -33,7 +33,9 @@ public static string SetAccessibilityHint(this NativeView Control, Element Eleme if (_defaultAccessibilityHint == null) _defaultAccessibilityHint = Control.AccessibilityHint; +#pragma warning disable CS0618 // Type or member is obsolete Control.AccessibilityHint = (string)Element.GetValue(AutomationProperties.HelpTextProperty) ?? _defaultAccessibilityHint; +#pragma warning restore CS0618 // Type or member is obsolete #else if (_defaultAccessibilityHint == null) _defaultAccessibilityHint = Control.AccessibilityTitle; @@ -52,7 +54,9 @@ public static string SetAccessibilityLabel(this NativeView Control, Element Elem if (_defaultAccessibilityLabel == null) _defaultAccessibilityLabel = Control.AccessibilityLabel; +#pragma warning disable CS0618 // Type or member is obsolete Control.AccessibilityLabel = (string)Element.GetValue(AutomationProperties.NameProperty) ?? _defaultAccessibilityLabel; +#pragma warning restore CS0618 // Type or member is obsolete return _defaultAccessibilityLabel; } @@ -66,7 +70,9 @@ public static string SetAccessibilityHint(this UIBarItem Control, Element Elemen if (_defaultAccessibilityHint == null) _defaultAccessibilityHint = Control.AccessibilityHint; +#pragma warning disable CS0618 // Type or member is obsolete Control.AccessibilityHint = (string)Element.GetValue(AutomationProperties.HelpTextProperty) ?? _defaultAccessibilityHint; +#pragma warning restore CS0618 // Type or member is obsolete return _defaultAccessibilityHint; @@ -80,7 +86,9 @@ public static string SetAccessibilityLabel(this UIBarItem Control, Element Eleme if (_defaultAccessibilityLabel == null) _defaultAccessibilityLabel = Control.AccessibilityLabel; +#pragma warning disable CS0618 // Type or member is obsolete Control.AccessibilityLabel = (string)Element.GetValue(AutomationProperties.NameProperty) ?? _defaultAccessibilityLabel; +#pragma warning restore CS0618 // Type or member is obsolete return _defaultAccessibilityLabel; } diff --git a/src/Controls/src/Core/Compatibility/iOS/Extensions/ToolbarItemExtensions.cs b/src/Controls/src/Core/Compatibility/iOS/Extensions/ToolbarItemExtensions.cs index 0a27731f2c4f..8a099bd2d06f 100644 --- a/src/Controls/src/Core/Compatibility/iOS/Extensions/ToolbarItemExtensions.cs +++ b/src/Controls/src/Core/Compatibility/iOS/Extensions/ToolbarItemExtensions.cs @@ -75,10 +75,12 @@ void OnPropertyChanged(object sender, PropertyChangedEventArgs e) UpdateTextAndStyle(); } } +#pragma warning disable CS0618 // Type or member is obsolete else if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName) this.SetAccessibilityHint(_item); else if (e.PropertyName == AutomationProperties.NameProperty.PropertyName) this.SetAccessibilityLabel(_item); +#pragma warning restore CS0618 // Type or member is obsolete } void UpdateIconAndStyle() @@ -149,9 +151,11 @@ void OnPropertyChanged(object sender, PropertyChangedEventArgs e) UpdateIcon(); else if (e.PropertyName == MenuItem.IsEnabledProperty.PropertyName) UpdateIsEnabled(); +#pragma warning disable CS0618 // Type or member is obsolete else if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName) this.SetAccessibilityHint(_item); else if (e.PropertyName == AutomationProperties.NameProperty.PropertyName) +#pragma warning restore CS0618 // Type or member is obsolete this.SetAccessibilityLabel(_item); } diff --git a/src/Controls/src/Core/Platform/Android/AutomationPropertiesProvider.cs b/src/Controls/src/Core/Platform/Android/AutomationPropertiesProvider.cs index f70ccabd523a..77b4c8a6a00b 100644 --- a/src/Controls/src/Core/Platform/Android/AutomationPropertiesProvider.cs +++ b/src/Controls/src/Core/Platform/Android/AutomationPropertiesProvider.cs @@ -79,8 +79,10 @@ static string ConcatenateNameAndHint(Element Element) { string separator; +#pragma warning disable CS0618 // Type or member is obsolete var name = (string)Element.GetValue(AutomationProperties.NameProperty); var hint = (string)Element.GetValue(AutomationProperties.HelpTextProperty); +#pragma warning restore CS0618 // Type or member is obsolete if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(hint)) separator = ""; @@ -166,7 +168,9 @@ internal static void SetLabeledBy(AView control, Element element) if (element == null || control == null) return; +#pragma warning disable CS0618 // Type or member is obsolete var elemValue = (VisualElement)element.GetValue(AutomationProperties.LabeledByProperty); +#pragma warning restore CS0618 // Type or member is obsolete if (elemValue != null) { @@ -232,8 +236,10 @@ internal static void AccessibilitySettingsChanged(AView control, Element element internal static string ConcatenateNameAndHelpText(BindableObject Element) { +#pragma warning disable CS0618 // Type or member is obsolete var name = (string)Element.GetValue(AutomationProperties.NameProperty); var helpText = (string)Element.GetValue(AutomationProperties.HelpTextProperty); +#pragma warning restore CS0618 // Type or member is obsolete if (string.IsNullOrWhiteSpace(name)) return helpText; diff --git a/src/Controls/src/Core/Platform/Windows/Extensions/AccessibilityExtensions.cs b/src/Controls/src/Core/Platform/Windows/Extensions/AccessibilityExtensions.cs index d787696e2596..41ea4aa7073d 100644 --- a/src/Controls/src/Core/Platform/Windows/Extensions/AccessibilityExtensions.cs +++ b/src/Controls/src/Core/Platform/Windows/Extensions/AccessibilityExtensions.cs @@ -20,7 +20,9 @@ public static string SetAutomationPropertiesName(this FrameworkElement Control, if (_defaultAutomationPropertiesName == null) _defaultAutomationPropertiesName = (string)Control.GetValue(NativeAutomationProperties.NameProperty); +#pragma warning disable CS0618 // Type or member is obsolete var elemValue = (string)Element.GetValue(AutomationProperties.NameProperty); +#pragma warning restore CS0618 // Type or member is obsolete if (!string.IsNullOrWhiteSpace(elemValue)) Control.SetValue(NativeAutomationProperties.NameProperty, elemValue); @@ -60,7 +62,9 @@ public static string SetAutomationPropertiesHelpText(this FrameworkElement Contr if (_defaultAutomationPropertiesHelpText == null) _defaultAutomationPropertiesHelpText = (string)Control.GetValue(NativeAutomationProperties.HelpTextProperty); +#pragma warning disable CS0618 // Type or member is obsolete var elemValue = (string)Element.GetValue(AutomationProperties.HelpTextProperty); +#pragma warning restore CS0618 // Type or member is obsolete if (!string.IsNullOrWhiteSpace(elemValue)) Control.SetValue(NativeAutomationProperties.HelpTextProperty, elemValue); @@ -85,16 +89,18 @@ public static UIElement SetAutomationPropertiesLabeledBy( if (_defaultAutomationPropertiesLabeledBy == null) _defaultAutomationPropertiesLabeledBy = (UIElement)Control.GetValue(NativeAutomationProperties.LabeledByProperty); - +#pragma warning disable CS0618 // Type or member is obsolete var elemValue = (VisualElement)Element.GetValue(AutomationProperties.LabeledByProperty); - +#pragma warning restore CS0618 // Type or member is obsolete FrameworkElement nativeElement = null; if (mauiContext != null) nativeElement = (elemValue as IView)?.ToHandler(mauiContext)?.PlatformView as FrameworkElement; if (nativeElement != null) +#pragma warning disable CS0618 // Type or member is obsolete Control.SetValue(AutomationProperties.LabeledByProperty, nativeElement); +#pragma warning restore CS0618 // Type or member is obsolete else Control.SetValue(NativeAutomationProperties.LabeledByProperty, _defaultAutomationPropertiesLabeledBy); @@ -117,10 +123,11 @@ static string ConcatenateNameAndHint(Element Element) { string separator; +#pragma warning disable CS0618 // Type or member is obsolete var name = (string)Element.GetValue(AutomationProperties.NameProperty); var hint = (string)Element.GetValue(AutomationProperties.HelpTextProperty); - +#pragma warning restore CS0618 // Type or member is obsolete if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(hint)) separator = ""; diff --git a/src/Controls/src/Core/SemanticProperties.cs b/src/Controls/src/Core/SemanticProperties.cs index 0a3cbd96e806..6cbd6e3050c6 100644 --- a/src/Controls/src/Core/SemanticProperties.cs +++ b/src/Controls/src/Core/SemanticProperties.cs @@ -47,9 +47,11 @@ public static void SetHeadingLevel(BindableObject bindable, SemanticHeadingLevel SemanticProperties.DescriptionProperty, SemanticProperties.HintProperty, SemanticProperties.HeadingLevelProperty, +#pragma warning disable CS0618 // Type or member is obsolete AutomationProperties.NameProperty, AutomationProperties.LabeledByProperty, AutomationProperties.HelpTextProperty, +#pragma warning restore CS0618 // Type or member is obsolete AutomationProperties.IsInAccessibleTreeProperty, };