Skip to content

Commit 0035e6f

Browse files
authored
Merge pull request #663 from rotorgames/AccessibilityUpgrade585
Accessibility Workaround Upgrade
2 parents f661daf + 1e943fd commit 0035e6f

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

Rg.Plugins.Popup/Platforms/Android/Impl/PopupPlatformDroid.cs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,23 @@ public Task AddAsync(PopupPage page)
4444
{
4545
var decoreView = DecoreView;
4646

47-
if (page.AndroidTalkbackAccessibilityWorkaround)
48-
{
49-
RecursivelyChangeAccessibilityOfViewChildren(XApplication.Current.MainPage.GetOrCreateRenderer().View, ImportantForAccessibility.No);
50-
}
47+
HandleAccessibilityWorkaround(page);
5148

5249
page.Parent = XApplication.Current.MainPage;
53-
5450
var renderer = page.GetOrCreateRenderer();
55-
decoreView?.AddView(renderer.View);
5651

52+
decoreView?.AddView(renderer.View);
5753
return PostAsync(renderer.View);
54+
55+
static void HandleAccessibilityWorkaround(PopupPage page)
56+
{
57+
if (page.AndroidTalkbackAccessibilityWorkaround)
58+
{
59+
var NavCount = XApplication.Current.MainPage.Navigation.NavigationStack.Count;
60+
Page currentPage = XApplication.Current.MainPage.Navigation.NavigationStack[NavCount - 1];
61+
currentPage.GetOrCreateRenderer().View.ImportantForAccessibility = ImportantForAccessibility.NoHideDescendants;
62+
}
63+
}
5864
}
5965

6066
public Task RemoveAsync(PopupPage page)
@@ -65,10 +71,7 @@ public Task RemoveAsync(PopupPage page)
6571
var renderer = page.GetOrCreateRenderer();
6672
if (renderer != null)
6773
{
68-
if (page.AndroidTalkbackAccessibilityWorkaround)
69-
{
70-
RecursivelyChangeAccessibilityOfViewChildren(XApplication.Current.MainPage.GetOrCreateRenderer().View, ImportantForAccessibility.Auto);
71-
}
74+
HandleAccessibilityWorkaround(page);
7275

7376
page.Parent = XApplication.Current.MainPage;
7477
var element = renderer.Element;
@@ -83,6 +86,16 @@ public Task RemoveAsync(PopupPage page)
8386
}
8487

8588
return Task.FromResult(true);
89+
90+
static void HandleAccessibilityWorkaround(PopupPage page)
91+
{
92+
if (page.AndroidTalkbackAccessibilityWorkaround)
93+
{
94+
var NavCount = XApplication.Current.MainPage.Navigation.NavigationStack.Count;
95+
Page currentPage = XApplication.Current.MainPage.Navigation.NavigationStack[NavCount - 1];
96+
currentPage.GetOrCreateRenderer().View.ImportantForAccessibility = ImportantForAccessibility.Auto;
97+
}
98+
}
8699
}
87100

88101
#region System Animation
@@ -128,20 +141,6 @@ private static Task PostAsync(Android.Views.View nativeView)
128141

129142
return tcs.Task;
130143
}
131-
132-
private void RecursivelyChangeAccessibilityOfViewChildren(Android.Views.View view, ImportantForAccessibility important)
133-
{
134-
if (view is ViewGroup vGroup)
135-
{
136-
for (int i = 0; i < vGroup.ChildCount; i++)
137-
{
138-
Android.Views.View vChild = vGroup.GetChildAt(i);
139-
vChild.ImportantForAccessibility = important;
140-
vChild.ClearFocus();
141-
RecursivelyChangeAccessibilityOfViewChildren(vChild, important);
142-
}
143-
}
144-
}
145144
#endregion
146145
}
147146
}

0 commit comments

Comments
 (0)