Skip to content

Commit 4c0a56d

Browse files
committed
Added in an additional variable to switch on/off the talkback workaround within each page for android.
Added the example usage in LoginPopupPage
1 parent 7929cae commit 4c0a56d

File tree

4 files changed

+143
-118
lines changed

4 files changed

+143
-118
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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public Task AddAsync(PopupPage page)
4444
{
4545
var decoreView = DecoreView;
4646

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

4952
page.Parent = XApplication.Current.MainPage;
5053

@@ -62,7 +65,10 @@ public Task RemoveAsync(PopupPage page)
6265
var renderer = page.GetOrCreateRenderer();
6366
if (renderer != null)
6467
{
65-
RecursivelyChangeAccessibilityOfViewChildren(XApplication.Current.MainPage.GetOrCreateRenderer().View, ImportantForAccessibility.Auto);
68+
if (page.AndroidTalkbackAccessibilityWorkaround)
69+
{
70+
RecursivelyChangeAccessibilityOfViewChildren(XApplication.Current.MainPage.GetOrCreateRenderer().View, ImportantForAccessibility.Auto);
71+
}
6672

6773
page.Parent = XApplication.Current.MainPage;
6874
var element = renderer.Element;
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>
Lines changed: 95 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,97 @@
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.LoginPopupPage">
6-
<rg:PopupPage.Resources>
7-
<ResourceDictionary>
8-
<Style x:Key="EntryStyle" TargetType="Entry">
9-
<Setter Property="PlaceholderColor" Value="#9cdaf1"/>
10-
<Setter Property="TextColor" Value="#7dbbe6"/>
11-
</Style>
12-
</ResourceDictionary>
13-
</rg:PopupPage.Resources>
14-
<rg:PopupPage.Animation>
15-
<rg:ScaleAnimation
16-
PositionIn="Bottom"
17-
PositionOut="Center"
18-
ScaleIn="1"
19-
ScaleOut="0.7"
20-
DurationIn="700"
21-
EasingIn="BounceOut"/>
22-
</rg:PopupPage.Animation>
23-
<ScrollView
24-
HorizontalOptions="Center"
25-
VerticalOptions="Center">
26-
<AbsoluteLayout>
27-
<Frame
28-
x:Name="FrameContainer"
29-
Margin="15"
30-
HorizontalOptions="Center"
31-
BackgroundColor="White">
32-
<StackLayout
33-
IsClippedToBounds="True"
34-
Padding="10, 5"
35-
Spacing="3">
36-
<Image
37-
HorizontalOptions="Center"
38-
x:Name="OctocatImage"
39-
Margin="10"
40-
HeightRequest="150"
41-
WidthRequest="150">
42-
<Image.Source>
43-
<OnPlatform
44-
x:TypeArguments="ImageSource"
45-
Android="github_octocat.png"
46-
iOS="github_octocat.png"
47-
WinPhone="Assets/github_octocat.png"/>
48-
</Image.Source>
49-
</Image>
50-
<Entry
51-
HorizontalOptions="Center"
52-
x:Name="UsernameEntry"
53-
Style="{StaticResource EntryStyle}"
54-
Placeholder="Username" />
55-
<Entry
56-
HorizontalOptions="Center"
57-
x:Name="PasswordEntry"
58-
Style="{StaticResource EntryStyle}"
59-
Placeholder="Password"
60-
IsPassword="True"/>
61-
<Button
62-
Margin="10, 5"
63-
BackgroundColor="#7dbbe6"
64-
HorizontalOptions="Fill"
65-
Clicked="OnLogin"
66-
x:Name="LoginButton"
67-
Text="Login">
68-
<Button.HeightRequest>
69-
<OnPlatform x:TypeArguments="x:Double" Android="50" iOS="30" WinPhone="30"/>
70-
</Button.HeightRequest>
71-
</Button>
72-
</StackLayout>
73-
</Frame>
74-
<ContentView
75-
AbsoluteLayout.LayoutFlags="PositionProportional"
76-
AbsoluteLayout.LayoutBounds="1, 0, -1, -1">
77-
<ContentView.GestureRecognizers>
78-
<TapGestureRecognizer Tapped="OnCloseButtonTapped"/>
79-
</ContentView.GestureRecognizers>
80-
<Image
81-
x:Name="CloseImage"
82-
HeightRequest="30"
83-
WidthRequest="30">
84-
<Image.Source>
85-
<OnPlatform
86-
x:TypeArguments="ImageSource"
87-
Android="close_circle_button.png"
88-
iOS="close_circle_button.png"
89-
WinPhone="Assets/close_circle_button.png"/>
90-
</Image.Source>
91-
</Image>
92-
</ContentView>
93-
</AbsoluteLayout>
94-
</ScrollView>
2+
<rg:PopupPage
3+
x:Class="Demo.Pages.LoginPopupPage"
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+
AndroidTalkbackAccessibilityWorkaround="True">
8+
<rg:PopupPage.Resources>
9+
<ResourceDictionary>
10+
<Style x:Key="EntryStyle" TargetType="Entry">
11+
<Setter Property="PlaceholderColor" Value="#9cdaf1" />
12+
<Setter Property="TextColor" Value="#7dbbe6" />
13+
</Style>
14+
</ResourceDictionary>
15+
</rg:PopupPage.Resources>
16+
<rg:PopupPage.Animation>
17+
<rg:ScaleAnimation
18+
DurationIn="700"
19+
EasingIn="BounceOut"
20+
PositionIn="Bottom"
21+
PositionOut="Center"
22+
ScaleIn="1"
23+
ScaleOut="0.7" />
24+
</rg:PopupPage.Animation>
25+
<ScrollView HorizontalOptions="Center" VerticalOptions="Center">
26+
<AbsoluteLayout>
27+
<Frame
28+
x:Name="FrameContainer"
29+
Margin="15"
30+
BackgroundColor="White"
31+
HorizontalOptions="Center">
32+
<StackLayout
33+
Padding="10,5"
34+
IsClippedToBounds="True"
35+
Spacing="3">
36+
<Image
37+
x:Name="OctocatImage"
38+
Margin="10"
39+
HeightRequest="150"
40+
HorizontalOptions="Center"
41+
WidthRequest="150">
42+
<Image.Source>
43+
<OnPlatform
44+
x:TypeArguments="ImageSource"
45+
Android="github_octocat.png"
46+
WinPhone="Assets/github_octocat.png"
47+
iOS="github_octocat.png" />
48+
</Image.Source>
49+
</Image>
50+
<Entry
51+
x:Name="UsernameEntry"
52+
HorizontalOptions="Center"
53+
Placeholder="Username"
54+
Style="{StaticResource EntryStyle}" />
55+
<Entry
56+
x:Name="PasswordEntry"
57+
HorizontalOptions="Center"
58+
IsPassword="True"
59+
Placeholder="Password"
60+
Style="{StaticResource EntryStyle}" />
61+
<Button
62+
x:Name="LoginButton"
63+
Margin="10,5"
64+
BackgroundColor="#7dbbe6"
65+
Clicked="OnLogin"
66+
HorizontalOptions="Fill"
67+
Text="Login">
68+
<Button.HeightRequest>
69+
<OnPlatform
70+
x:TypeArguments="x:Double"
71+
Android="50"
72+
WinPhone="30"
73+
iOS="30" />
74+
</Button.HeightRequest>
75+
</Button>
76+
</StackLayout>
77+
</Frame>
78+
<ContentView AbsoluteLayout.LayoutBounds="1, 0, -1, -1" AbsoluteLayout.LayoutFlags="PositionProportional">
79+
<ContentView.GestureRecognizers>
80+
<TapGestureRecognizer Tapped="OnCloseButtonTapped" />
81+
</ContentView.GestureRecognizers>
82+
<Image
83+
x:Name="CloseImage"
84+
HeightRequest="30"
85+
WidthRequest="30">
86+
<Image.Source>
87+
<OnPlatform
88+
x:TypeArguments="ImageSource"
89+
Android="close_circle_button.png"
90+
WinPhone="Assets/close_circle_button.png"
91+
iOS="close_circle_button.png" />
92+
</Image.Source>
93+
</Image>
94+
</ContentView>
95+
</AbsoluteLayout>
96+
</ScrollView>
9597
</rg:PopupPage>

0 commit comments

Comments
 (0)