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

[iOS] AutomationProperty support for cells #3313

Merged
merged 2 commits into from
Aug 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,45 @@ public AutomationPropertiesGallery()
entryGroup.AddChild(entry, 1, 0);


var textCellA = new TextCell
{
Text = "A"
};
textCellA.SetAutomationPropertiesName("Option A");

var textCellB = new TextCell
{
Text = "B"
};
textCellB.SetAutomationPropertiesName("Option B");

var textCellC = new TextCell
{
Text = "C"
};
textCellC.SetAutomationPropertiesName("Option C");

var textCellD = new TextCell
{
Text = "D"
};
textCellD.SetAutomationPropertiesName("Option D");

TableView tbl = new TableView
{
Intent = TableIntent.Menu,
Root = new TableRoot
{
new TableSection("TableView")
{
textCellA,
textCellB,
textCellC,
textCellD,
}
}
};


var activityIndicator = new ActivityIndicator();
activityIndicator.SetAutomationPropertiesName("Progress indicator");
Expand Down Expand Up @@ -110,6 +149,7 @@ public AutomationPropertiesGallery()
instructions,
instructions2,
entryGroup,
tbl,
instructions3,
button,
activityIndicator,
Expand All @@ -126,42 +166,42 @@ public AutomationPropertiesGallery()

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

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

public static void SetAutomationPropertiesHelpText(this VisualElement element, string HelpText)
public static void SetAutomationPropertiesHelpText(this Element element, string HelpText)
{
element.SetValue(AutomationProperties.HelpTextProperty, HelpText);
}

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

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

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

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

public static Element GetAutomationPropertiesLabeledBy(this VisualElement element)
public static Element GetAutomationPropertiesLabeledBy(this Element element)
{
return (Element)element.GetValue(AutomationProperties.LabeledByProperty);
}
Expand Down
20 changes: 20 additions & 0 deletions Xamarin.Forms.Platform.iOS/Cells/CellRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,30 @@ public virtual UITableViewCell GetCell(Cell item, UITableViewCell reusableCell,

UpdateBackground(tvc, item);

SetAccessibility (tvc, item);

Performance.Stop(reference);
return tvc;
}

public virtual void SetAccessibility (UITableViewCell tableViewCell, Cell cell)
{
if (cell.IsSet (AutomationProperties.IsInAccessibleTreeProperty))
tableViewCell.IsAccessibilityElement = cell.GetValue (AutomationProperties.IsInAccessibleTreeProperty).Equals (true);
else
tableViewCell.IsAccessibilityElement = false;

if (cell.IsSet (AutomationProperties.NameProperty))
tableViewCell.AccessibilityLabel = cell.GetValue (AutomationProperties.NameProperty).ToString ();
else
tableViewCell.AccessibilityLabel = null;

if (cell.IsSet (AutomationProperties.HelpTextProperty))
tableViewCell.AccessibilityHint = cell.GetValue (AutomationProperties.HelpTextProperty).ToString ();
else
tableViewCell.AccessibilityHint = null;
}

public virtual void SetBackgroundColor(UITableViewCell tableViewCell, Cell cell, UIColor color)
{
tableViewCell.BackgroundColor = color;
Expand Down
2 changes: 2 additions & 0 deletions Xamarin.Forms.Platform.iOS/Cells/TextCellRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell,

UpdateBackground(tvc, item);

SetAccessibility(tvc, item);

return tvc;
}

Expand Down