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

Commit

Permalink
[iOS] AutomationProperty support for cells (#3313) fixes #3296
Browse files Browse the repository at this point in the history
* [iOS] AutomationProperty support for cells

* Add test case to AutomationProperties gallery
  • Loading branch information
Pavel Yakovlev authored and rmarinho committed Aug 23, 2018
1 parent 0e92e54 commit 56d47a1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 8 deletions.
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

0 comments on commit 56d47a1

Please sign in to comment.