Skip to content

Commit fd0995d

Browse files
authored
Merge pull request #657 from rotorgames/AccessibilityUpgrade585
Accessibility upgrade
2 parents bce50e8 + 4c0a56d commit fd0995d

File tree

7 files changed

+221
-155
lines changed

7 files changed

+221
-155
lines changed

Rg.Plugins.Popup/Pages/PopupPage.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
22
using System.Threading.Tasks;
33
using System.Windows.Input;
4+
45
using Rg.Plugins.Popup.Animations;
56
using Rg.Plugins.Popup.Enums;
67
using Rg.Plugins.Popup.Interfaces.Animations;
78
using Rg.Plugins.Popup.Services;
9+
810
using Xamarin.Forms;
911

1012
namespace Rg.Plugins.Popup.Pages
@@ -119,12 +121,12 @@ public double KeyboardOffset
119121
get { return (double)GetValue(KeyboardOffsetProperty); }
120122
private set { SetValue(KeyboardOffsetProperty, value); }
121123
}
122-
124+
123125
public static readonly BindableProperty BackgroundClickedCommandProperty = BindableProperty.Create(nameof(BackgroundClickedCommand), typeof(ICommand), typeof(PopupPage));
124126

125127
public ICommand BackgroundClickedCommand
126128
{
127-
get => (ICommand) GetValue(BackgroundClickedCommandProperty);
129+
get => (ICommand)GetValue(BackgroundClickedCommandProperty);
128130
set => SetValue(BackgroundClickedCommandProperty, value);
129131
}
130132

@@ -136,6 +138,14 @@ public object BackgroundClickedCommandParameter
136138
set => SetValue(BackgroundClickedCommandParameterProperty, value);
137139
}
138140

141+
public static readonly BindableProperty AndroidTalkbackAccessibilityWorkaroundProperty = BindableProperty.Create(nameof(AndroidTalkbackAccessibilityWorkaround), typeof(bool), typeof(PopupPage), false);
142+
143+
public bool AndroidTalkbackAccessibilityWorkaround
144+
{
145+
get => (bool)GetValue(AndroidTalkbackAccessibilityWorkaroundProperty);
146+
set => SetValue(AndroidTalkbackAccessibilityWorkaroundProperty, value);
147+
}
148+
139149
#endregion
140150

141151
#region Main Methods
@@ -155,14 +165,14 @@ protected override void OnPropertyChanged(string? propertyName = null)
155165
case nameof(HasKeyboardOffset):
156166
case nameof(SystemPaddingSides):
157167
case nameof(SystemPadding):
158-
ForceLayout();
159-
break;
168+
ForceLayout();
169+
break;
160170
case nameof(IsAnimating):
161-
IsAnimationEnabled = IsAnimating;
162-
break;
171+
IsAnimationEnabled = IsAnimating;
172+
break;
163173
case nameof(IsAnimationEnabled):
164-
IsAnimating = IsAnimationEnabled;
165-
break;
174+
IsAnimating = IsAnimationEnabled;
175+
break;
166176
}
167177
}
168178

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
using System;
2+
using System.Text;
23
using System.Threading.Tasks;
34

45
using Android.App;
6+
using Android.Content;
57
using Android.OS;
68
using Android.Provider;
79
using Android.Runtime;
10+
using Android.Views;
11+
using Android.Views.Accessibility;
812
using Android.Widget;
913

1014
using Rg.Plugins.Popup.Contracts;
@@ -40,10 +44,14 @@ public Task AddAsync(PopupPage page)
4044
{
4145
var decoreView = DecoreView;
4246

47+
if (page.AndroidTalkbackAccessibilityWorkaround)
48+
{
49+
RecursivelyChangeAccessibilityOfViewChildren(XApplication.Current.MainPage.GetOrCreateRenderer().View, ImportantForAccessibility.No);
50+
}
51+
4352
page.Parent = XApplication.Current.MainPage;
4453

4554
var renderer = page.GetOrCreateRenderer();
46-
4755
decoreView?.AddView(renderer.View);
4856

4957
return PostAsync(renderer.View);
@@ -57,6 +65,12 @@ public Task RemoveAsync(PopupPage page)
5765
var renderer = page.GetOrCreateRenderer();
5866
if (renderer != null)
5967
{
68+
if (page.AndroidTalkbackAccessibilityWorkaround)
69+
{
70+
RecursivelyChangeAccessibilityOfViewChildren(XApplication.Current.MainPage.GetOrCreateRenderer().View, ImportantForAccessibility.Auto);
71+
}
72+
73+
page.Parent = XApplication.Current.MainPage;
6074
var element = renderer.Element;
6175

6276
DecoreView?.RemoveView(renderer.View);
@@ -115,6 +129,19 @@ private static Task PostAsync(Android.Views.View nativeView)
115129
return tcs.Task;
116130
}
117131

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+
}
118145
#endregion
119146
}
120147
}

Rg.Plugins.Popup/Platforms/Mac/Extensions/PlatformExtension.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
using System.Linq;
2+
23
using AppKit;
4+
35
using Rg.Plugins.Popup.MacOS.Renderers;
6+
47
using Xamarin.Forms;
58
using Xamarin.Forms.Platform.MacOS;
9+
610
using XFPlatform = Xamarin.Forms.Platform.MacOS.Platform;
711

812
namespace Rg.Plugins.Popup.MacOS.Extensions
@@ -54,6 +58,8 @@ public static void UpdateSize(this PopupPageRenderer renderer)
5458
var superviewFrame = renderer.View.Superview.Frame;
5559
var applactionFrame = NSScreen.MainScreen.Frame;
5660

61+
62+
5763
var systemPadding = new Thickness
5864
{
5965
Left = applactionFrame.Left,

Samples/Demo.Droid/MainActivity.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Android.App;
22
using Android.Content.PM;
33
using Android.OS;
4+
45
using Debug = System.Diagnostics.Debug;
56

67
namespace Demo.Droid
@@ -12,7 +13,7 @@ protected override void OnCreate(Bundle bundle)
1213
{
1314
base.OnCreate(bundle);
1415

15-
Rg.Plugins.Popup.Popup.Init(this, bundle);
16+
Rg.Plugins.Popup.Popup.Init(this);
1617
global::Xamarin.Forms.Forms.Init(this, bundle);
1718
LoadApplication(new App());
1819
}
Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,54 @@
11
<?xml version="1.0" encoding="utf-8" ?>
2-
<rg:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4-
xmlns:rg="http://rotorgames.com"
5-
x:Class="Demo.Pages.FirstPopupPage">
6-
<rg:PopupPage.Animation>
7-
<rg:ScaleAnimation
8-
PositionIn="Center"
9-
PositionOut="Center"
10-
ScaleIn="1.2"
11-
ScaleOut="0.8"
12-
DurationIn="400"
13-
DurationOut="300"
14-
EasingIn="SinOut"
15-
EasingOut="SinIn"
16-
HasBackgroundAnimation="True"/>
17-
</rg:PopupPage.Animation>
18-
<StackLayout VerticalOptions="Center" HorizontalOptions="FillAndExpand" Padding="20, 20, 20, 20">
19-
<StackLayout BackgroundColor="White" Padding="0, 10, 0, 0">
20-
<Label Text="First Popup Page" TextColor="Gray" FontSize="20" HorizontalOptions="Center"></Label>
21-
<ScrollView>
22-
<StackLayout>
23-
<StackLayout Orientation="Horizontal">
24-
<Entry Placeholder="Test Entry"
25-
HorizontalOptions="FillAndExpand"
26-
BindingContext="{x:Reference Switch}"
27-
IsEnabled="{Binding Path=IsToggled}"
28-
PlaceholderColor="Silver"
29-
Keyboard="Email"
30-
TextColor="Gray"></Entry>
31-
<Switch IsToggled="True" x:Name="Switch"></Switch>
32-
</StackLayout>
33-
<ActivityIndicator Color="Gray" IsRunning="True"></ActivityIndicator>
34-
<Slider Value="0.4" x:Name="Slider"></Slider>
35-
<ProgressBar BindingContext="{x:Reference Slider}" Progress="{Binding Path=Value}"></ProgressBar>
36-
<Button Text="Close" TextColor="#A9D1DE" Clicked="OnClose"></Button>
2+
<rg:PopupPage
3+
x:Class="Demo.Pages.FirstPopupPage"
4+
xmlns="http://xamarin.com/schemas/2014/forms"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:rg="http://rotorgames.com"
7+
HasSystemPadding="False">
8+
<rg:PopupPage.Animation>
9+
<rg:ScaleAnimation
10+
DurationIn="400"
11+
DurationOut="300"
12+
EasingIn="SinOut"
13+
EasingOut="SinIn"
14+
HasBackgroundAnimation="True"
15+
PositionIn="Center"
16+
PositionOut="Center"
17+
ScaleIn="1.2"
18+
ScaleOut="0.8" />
19+
</rg:PopupPage.Animation>
20+
<StackLayout
21+
Padding="20,20,20,20"
22+
HorizontalOptions="FillAndExpand"
23+
VerticalOptions="Center">
24+
<StackLayout Padding="0,10,0,0" BackgroundColor="White">
25+
<Label
26+
FontSize="20"
27+
HorizontalOptions="Center"
28+
Text="First Popup Page"
29+
TextColor="Gray" />
30+
<ScrollView>
31+
<StackLayout>
32+
<StackLayout Orientation="Horizontal">
33+
<Entry
34+
BindingContext="{x:Reference Switch}"
35+
HorizontalOptions="FillAndExpand"
36+
IsEnabled="{Binding Path=IsToggled}"
37+
Keyboard="Email"
38+
Placeholder="Test Entry"
39+
PlaceholderColor="Silver"
40+
TextColor="Gray" />
41+
<Switch x:Name="Switch" IsToggled="True" />
42+
</StackLayout>
43+
<ActivityIndicator IsRunning="True" Color="Gray" />
44+
<Slider x:Name="Slider" Value="0.4" />
45+
<ProgressBar BindingContext="{x:Reference Slider}" Progress="{Binding Path=Value}" />
46+
<Button
47+
Clicked="OnClose"
48+
Text="Close"
49+
TextColor="#A9D1DE" />
50+
</StackLayout>
51+
</ScrollView>
3752
</StackLayout>
38-
</ScrollView>
3953
</StackLayout>
40-
</StackLayout>
4154
</rg:PopupPage>
Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
<?xml version="1.0" encoding="utf-8" ?>
2-
<rg:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4-
xmlns:rg="http://rotorgames.com"
5-
x:Class="Demo.Pages.ListViewPage">
6-
<StackLayout VerticalOptions="Center" HorizontalOptions="FillAndExpand" Padding="20, 20, 20, 20">
7-
<StackLayout BackgroundColor="White">
8-
<ListView x:Name="listView">
9-
<ListView.ItemTemplate>
10-
<DataTemplate>
11-
<TextCell TextColor="Black" Text="{Binding .}"></TextCell>
12-
</DataTemplate>
13-
</ListView.ItemTemplate>
14-
</ListView>
2+
<rg:PopupPage
3+
x:Class="Demo.Pages.ListViewPage"
4+
xmlns="http://xamarin.com/schemas/2014/forms"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:rg="http://rotorgames.com">
7+
<StackLayout
8+
Padding="20,20,20,20"
9+
HorizontalOptions="FillAndExpand"
10+
VerticalOptions="Center">
11+
<StackLayout BackgroundColor="White">
12+
<ListView x:Name="listView">
13+
<ListView.ItemTemplate>
14+
<DataTemplate>
15+
<TextCell Text="{Binding .}" TextColor="Black" />
16+
</DataTemplate>
17+
</ListView.ItemTemplate>
18+
</ListView>
19+
</StackLayout>
20+
<Button
21+
Clicked="OnClose"
22+
Text="Close"
23+
TextColor="#A9D1DE" />
1524
</StackLayout>
16-
<Button Text="Close" TextColor="#A9D1DE" Clicked="OnClose"></Button>
17-
</StackLayout>
1825
</rg:PopupPage>

0 commit comments

Comments
 (0)