summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/Renderers/ConditionalFocusLayout.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Renderers/ConditionalFocusLayout.cs')
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/ConditionalFocusLayout.cs48
1 files changed, 48 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/ConditionalFocusLayout.cs b/Xamarin.Forms.Platform.Android/Renderers/ConditionalFocusLayout.cs
new file mode 100644
index 00000000..6368d023
--- /dev/null
+++ b/Xamarin.Forms.Platform.Android/Renderers/ConditionalFocusLayout.cs
@@ -0,0 +1,48 @@
+using Android.Content;
+using Android.Views;
+using Android.Widget;
+
+namespace Xamarin.Forms.Platform.Android
+{
+ internal class ConditionalFocusLayout : LinearLayout, global::Android.Views.View.IOnTouchListener
+ {
+ public ConditionalFocusLayout(Context context) : base(context)
+ {
+ SetOnTouchListener(this);
+ }
+
+ public bool OnTouch(global::Android.Views.View v, MotionEvent e)
+ {
+ bool allowFocus = v is EditText;
+ DescendantFocusability = allowFocus ? DescendantFocusability.AfterDescendants : DescendantFocusability.BlockDescendants;
+ return false;
+ }
+
+ internal void ApplyTouchListenersToSpecialCells(Cell item)
+ {
+ DescendantFocusability = DescendantFocusability.BlockDescendants;
+
+ global::Android.Views.View aView = GetChildAt(0);
+ (aView as EntryCellView)?.EditText.SetOnTouchListener(this);
+
+ var viewCell = item as ViewCell;
+ if (viewCell == null || viewCell?.View == null)
+ return;
+
+ IVisualElementRenderer renderer = Platform.GetRenderer(viewCell.View);
+ if (renderer?.ViewGroup?.ChildCount != 0)
+ (renderer.ViewGroup.GetChildAt(0) as EditText)?.SetOnTouchListener(this);
+
+ foreach (Element descendant in viewCell.View.Descendants())
+ {
+ var element = descendant as VisualElement;
+ if (element == null)
+ continue;
+ renderer = Platform.GetRenderer(element);
+ if (renderer?.ViewGroup?.ChildCount == 0)
+ continue;
+ (renderer.ViewGroup.GetChildAt(0) as EditText)?.SetOnTouchListener(this);
+ }
+ }
+ }
+} \ No newline at end of file