Skip to content

Commit

Permalink
Fix logic for concatenating hints in Android (#1837)
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed Jul 28, 2021
1 parent 729b266 commit 05e97c8
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/Core/src/Handlers/View/ViewHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,13 @@ public void OnInitializeAccessibilityNodeInfo(NativeView? host, AccessibilityNod
if (!string.IsNullOrEmpty(desc))
{
// Edit Text fields won't read anything for the content description
if (host is EditText)
newText = $"{desc}, {((EditText)host).Text}";
if (host is EditText et)
{
if (!string.IsNullOrEmpty(et.Text))
newText = $"{desc}, {et.Text}";
else
newText = $"{desc}";
}
else
newContentDescription = desc;
}
Expand All @@ -150,11 +155,26 @@ public void OnInitializeAccessibilityNodeInfo(NativeView? host, AccessibilityNod
}
else
{
if (host is TextView tv)
if (host is EditText et)
{
newText = newText ?? tv.Text;
newText = newText ?? et.Text;
newText = $"{newText}, {hint}";
}
else if (host is TextView tv)
{
if (newContentDescription != null)
{
newText = $"{newContentDescription}, {hint}";
}
else if (!string.IsNullOrEmpty(tv.Text))
{
newText = $"{tv.Text}, {hint}";
}
else
{
newText = $"{hint}";
}
}
else
{
if (newContentDescription != null)
Expand All @@ -171,10 +191,10 @@ public void OnInitializeAccessibilityNodeInfo(NativeView? host, AccessibilityNod
}
}

if (!String.IsNullOrWhiteSpace(newContentDescription))
if (!string.IsNullOrWhiteSpace(newContentDescription))
info.ContentDescription = newContentDescription;

if (!String.IsNullOrWhiteSpace(newText))
if (!string.IsNullOrWhiteSpace(newText))
info.Text = newText;
}

Expand Down

0 comments on commit 05e97c8

Please sign in to comment.