summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/Renderers/DescendantFocusToggler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Renderers/DescendantFocusToggler.cs')
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/DescendantFocusToggler.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/DescendantFocusToggler.cs b/Xamarin.Forms.Platform.Android/Renderers/DescendantFocusToggler.cs
new file mode 100644
index 00000000..1f54b7c5
--- /dev/null
+++ b/Xamarin.Forms.Platform.Android/Renderers/DescendantFocusToggler.cs
@@ -0,0 +1,42 @@
+using System;
+using Android.Views;
+
+namespace Xamarin.Forms.Platform.Android
+{
+ internal class DescendantFocusToggler : IDescendantFocusToggler
+ {
+ public bool RequestFocus(global::Android.Views.View control, Func<bool> baseRequestFocus)
+ {
+ IViewParent ancestor = control.Parent;
+ var previousFocusability = DescendantFocusability.BlockDescendants;
+ ConditionalFocusLayout cfl = null;
+
+ // Work our way up through the tree until we find a ConditionalFocusLayout
+ while (ancestor is ViewGroup)
+ {
+ cfl = ancestor as ConditionalFocusLayout;
+
+ if (cfl != null)
+ {
+ previousFocusability = cfl.DescendantFocusability;
+ // Toggle DescendantFocusability to allow this control to get focus
+ cfl.DescendantFocusability = DescendantFocusability.AfterDescendants;
+ break;
+ }
+
+ ancestor = ancestor.Parent;
+ }
+
+ // Call the original RequestFocus implementation for the View
+ bool result = baseRequestFocus();
+
+ if (cfl != null)
+ {
+ // Toggle descendantfocusability back to whatever it was
+ cfl.DescendantFocusability = previousFocusability;
+ }
+
+ return result;
+ }
+ }
+} \ No newline at end of file