Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessibility upgrade #657

Merged
merged 2 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions Rg.Plugins.Popup/Pages/PopupPage.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Threading.Tasks;
using System.Windows.Input;

using Rg.Plugins.Popup.Animations;
using Rg.Plugins.Popup.Enums;
using Rg.Plugins.Popup.Interfaces.Animations;
using Rg.Plugins.Popup.Services;

using Xamarin.Forms;

namespace Rg.Plugins.Popup.Pages
Expand Down Expand Up @@ -119,12 +121,12 @@ public double KeyboardOffset
get { return (double)GetValue(KeyboardOffsetProperty); }
private set { SetValue(KeyboardOffsetProperty, value); }
}

public static readonly BindableProperty BackgroundClickedCommandProperty = BindableProperty.Create(nameof(BackgroundClickedCommand), typeof(ICommand), typeof(PopupPage));

public ICommand BackgroundClickedCommand
{
get => (ICommand) GetValue(BackgroundClickedCommandProperty);
get => (ICommand)GetValue(BackgroundClickedCommandProperty);
set => SetValue(BackgroundClickedCommandProperty, value);
}

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

public static readonly BindableProperty AndroidTalkbackAccessibilityWorkaroundProperty = BindableProperty.Create(nameof(AndroidTalkbackAccessibilityWorkaround), typeof(bool), typeof(PopupPage), false);

public bool AndroidTalkbackAccessibilityWorkaround
{
get => (bool)GetValue(AndroidTalkbackAccessibilityWorkaroundProperty);
set => SetValue(AndroidTalkbackAccessibilityWorkaroundProperty, value);
}

#endregion

#region Main Methods
Expand All @@ -155,14 +165,14 @@ protected override void OnPropertyChanged(string? propertyName = null)
case nameof(HasKeyboardOffset):
case nameof(SystemPaddingSides):
case nameof(SystemPadding):
ForceLayout();
break;
ForceLayout();
break;
case nameof(IsAnimating):
IsAnimationEnabled = IsAnimating;
break;
IsAnimationEnabled = IsAnimating;
break;
case nameof(IsAnimationEnabled):
IsAnimating = IsAnimationEnabled;
break;
IsAnimating = IsAnimationEnabled;
break;
}
}

Expand Down
29 changes: 28 additions & 1 deletion Rg.Plugins.Popup/Platforms/Android/Impl/PopupPlatformDroid.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System;
using System.Text;
using System.Threading.Tasks;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Provider;
using Android.Runtime;
using Android.Views;
using Android.Views.Accessibility;
using Android.Widget;

using Rg.Plugins.Popup.Contracts;
Expand Down Expand Up @@ -40,10 +44,14 @@ public Task AddAsync(PopupPage page)
{
var decoreView = DecoreView;

if (page.AndroidTalkbackAccessibilityWorkaround)
{
RecursivelyChangeAccessibilityOfViewChildren(XApplication.Current.MainPage.GetOrCreateRenderer().View, ImportantForAccessibility.No);
}

page.Parent = XApplication.Current.MainPage;

var renderer = page.GetOrCreateRenderer();

decoreView?.AddView(renderer.View);

return PostAsync(renderer.View);
Expand All @@ -57,6 +65,12 @@ public Task RemoveAsync(PopupPage page)
var renderer = page.GetOrCreateRenderer();
if (renderer != null)
{
if (page.AndroidTalkbackAccessibilityWorkaround)
{
RecursivelyChangeAccessibilityOfViewChildren(XApplication.Current.MainPage.GetOrCreateRenderer().View, ImportantForAccessibility.Auto);
}

page.Parent = XApplication.Current.MainPage;
var element = renderer.Element;

DecoreView?.RemoveView(renderer.View);
Expand Down Expand Up @@ -115,6 +129,19 @@ private static Task PostAsync(Android.Views.View nativeView)
return tcs.Task;
}

private void RecursivelyChangeAccessibilityOfViewChildren(Android.Views.View view, ImportantForAccessibility important)
{
if (view is ViewGroup vGroup)
{
for (int i = 0; i < vGroup.ChildCount; i++)
{
Android.Views.View vChild = vGroup.GetChildAt(i);
vChild.ImportantForAccessibility = important;
vChild.ClearFocus();
RecursivelyChangeAccessibilityOfViewChildren(vChild, important);
}
}
}
#endregion
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System.Linq;

using AppKit;

using Rg.Plugins.Popup.MacOS.Renderers;

using Xamarin.Forms;
using Xamarin.Forms.Platform.MacOS;

using XFPlatform = Xamarin.Forms.Platform.MacOS.Platform;

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



var systemPadding = new Thickness
{
Left = applactionFrame.Left,
Expand Down
3 changes: 2 additions & 1 deletion Samples/Demo.Droid/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Android.App;
using Android.Content.PM;
using Android.OS;

using Debug = System.Diagnostics.Debug;

namespace Demo.Droid
Expand All @@ -12,7 +13,7 @@ protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

Rg.Plugins.Popup.Popup.Init(this, bundle);
Rg.Plugins.Popup.Popup.Init(this);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
Expand Down
87 changes: 50 additions & 37 deletions Samples/Demo/Pages/FirstPopupPage.xaml
Original file line number Diff line number Diff line change
@@ -1,41 +1,54 @@
<?xml version="1.0" encoding="utf-8" ?>
<rg:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:rg="http://rotorgames.com"
x:Class="Demo.Pages.FirstPopupPage">
<rg:PopupPage.Animation>
<rg:ScaleAnimation
PositionIn="Center"
PositionOut="Center"
ScaleIn="1.2"
ScaleOut="0.8"
DurationIn="400"
DurationOut="300"
EasingIn="SinOut"
EasingOut="SinIn"
HasBackgroundAnimation="True"/>
</rg:PopupPage.Animation>
<StackLayout VerticalOptions="Center" HorizontalOptions="FillAndExpand" Padding="20, 20, 20, 20">
<StackLayout BackgroundColor="White" Padding="0, 10, 0, 0">
<Label Text="First Popup Page" TextColor="Gray" FontSize="20" HorizontalOptions="Center"></Label>
<ScrollView>
<StackLayout>
<StackLayout Orientation="Horizontal">
<Entry Placeholder="Test Entry"
HorizontalOptions="FillAndExpand"
BindingContext="{x:Reference Switch}"
IsEnabled="{Binding Path=IsToggled}"
PlaceholderColor="Silver"
Keyboard="Email"
TextColor="Gray"></Entry>
<Switch IsToggled="True" x:Name="Switch"></Switch>
</StackLayout>
<ActivityIndicator Color="Gray" IsRunning="True"></ActivityIndicator>
<Slider Value="0.4" x:Name="Slider"></Slider>
<ProgressBar BindingContext="{x:Reference Slider}" Progress="{Binding Path=Value}"></ProgressBar>
<Button Text="Close" TextColor="#A9D1DE" Clicked="OnClose"></Button>
<rg:PopupPage
x:Class="Demo.Pages.FirstPopupPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:rg="http://rotorgames.com"
HasSystemPadding="False">
<rg:PopupPage.Animation>
<rg:ScaleAnimation
DurationIn="400"
DurationOut="300"
EasingIn="SinOut"
EasingOut="SinIn"
HasBackgroundAnimation="True"
PositionIn="Center"
PositionOut="Center"
ScaleIn="1.2"
ScaleOut="0.8" />
</rg:PopupPage.Animation>
<StackLayout
Padding="20,20,20,20"
HorizontalOptions="FillAndExpand"
VerticalOptions="Center">
<StackLayout Padding="0,10,0,0" BackgroundColor="White">
<Label
FontSize="20"
HorizontalOptions="Center"
Text="First Popup Page"
TextColor="Gray" />
<ScrollView>
<StackLayout>
<StackLayout Orientation="Horizontal">
<Entry
BindingContext="{x:Reference Switch}"
HorizontalOptions="FillAndExpand"
IsEnabled="{Binding Path=IsToggled}"
Keyboard="Email"
Placeholder="Test Entry"
PlaceholderColor="Silver"
TextColor="Gray" />
<Switch x:Name="Switch" IsToggled="True" />
</StackLayout>
<ActivityIndicator IsRunning="True" Color="Gray" />
<Slider x:Name="Slider" Value="0.4" />
<ProgressBar BindingContext="{x:Reference Slider}" Progress="{Binding Path=Value}" />
<Button
Clicked="OnClose"
Text="Close"
TextColor="#A9D1DE" />
</StackLayout>
</ScrollView>
</StackLayout>
</ScrollView>
</StackLayout>
</StackLayout>
</rg:PopupPage>
37 changes: 22 additions & 15 deletions Samples/Demo/Pages/ListViewPage.xaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<rg:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:rg="http://rotorgames.com"
x:Class="Demo.Pages.ListViewPage">
<StackLayout VerticalOptions="Center" HorizontalOptions="FillAndExpand" Padding="20, 20, 20, 20">
<StackLayout BackgroundColor="White">
<ListView x:Name="listView">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell TextColor="Black" Text="{Binding .}"></TextCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<rg:PopupPage
x:Class="Demo.Pages.ListViewPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:rg="http://rotorgames.com">
<StackLayout
Padding="20,20,20,20"
HorizontalOptions="FillAndExpand"
VerticalOptions="Center">
<StackLayout BackgroundColor="White">
<ListView x:Name="listView">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding .}" TextColor="Black" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
<Button
Clicked="OnClose"
Text="Close"
TextColor="#A9D1DE" />
</StackLayout>
<Button Text="Close" TextColor="#A9D1DE" Clicked="OnClose"></Button>
</StackLayout>
</rg:PopupPage>
Loading