Skip to content

Commit 7929cae

Browse files
committed
Update to add accessibility option
1 parent 0702447 commit 7929cae

File tree

4 files changed

+80
-39
lines changed

4 files changed

+80
-39
lines changed

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

Lines changed: 22 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,11 @@ public Task AddAsync(PopupPage page)
4044
{
4145
var decoreView = DecoreView;
4246

47+
RecursivelyChangeAccessibilityOfViewChildren(XApplication.Current.MainPage.GetOrCreateRenderer().View, ImportantForAccessibility.No);
48+
4349
page.Parent = XApplication.Current.MainPage;
4450

4551
var renderer = page.GetOrCreateRenderer();
46-
4752
decoreView?.AddView(renderer.View);
4853

4954
return PostAsync(renderer.View);
@@ -57,6 +62,9 @@ public Task RemoveAsync(PopupPage page)
5762
var renderer = page.GetOrCreateRenderer();
5863
if (renderer != null)
5964
{
65+
RecursivelyChangeAccessibilityOfViewChildren(XApplication.Current.MainPage.GetOrCreateRenderer().View, ImportantForAccessibility.Auto);
66+
67+
page.Parent = XApplication.Current.MainPage;
6068
var element = renderer.Element;
6169

6270
DecoreView?.RemoveView(renderer.View);
@@ -115,6 +123,19 @@ private static Task PostAsync(Android.Views.View nativeView)
115123
return tcs.Task;
116124
}
117125

126+
private void RecursivelyChangeAccessibilityOfViewChildren(Android.Views.View view, ImportantForAccessibility important)
127+
{
128+
if (view is ViewGroup vGroup)
129+
{
130+
for (int i = 0; i < vGroup.ChildCount; i++)
131+
{
132+
Android.Views.View vChild = vGroup.GetChildAt(i);
133+
vChild.ImportantForAccessibility = important;
134+
vChild.ClearFocus();
135+
RecursivelyChangeAccessibilityOfViewChildren(vChild, important);
136+
}
137+
}
138+
}
118139
#endregion
119140
}
120141
}

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>

0 commit comments

Comments
 (0)