Last active
April 18, 2017 01:07
-
-
Save davidortinau/6f25b97a6028fa7bd9070352800d0f11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if __ANDROID__ | |
using Xamarin.Forms.Platform.Android; | |
using Android.Views; | |
#endif | |
#if __IOS__ | |
using Xamarin.Forms.Platform.iOS; | |
#endif | |
#if __IOS__ | |
System.Diagnostics.Debug.WriteLine("I'm in iOS"); | |
var native = Platform.GetRenderer(this); | |
var myBabies = native.NativeView.Descendants(); | |
var enumerator = myBabies.GetEnumerator(); | |
var counter = 0; | |
while (enumerator.MoveNext()) | |
{ | |
counter++; | |
} | |
Debug.WriteLine("babies " + counter); | |
#endif | |
#if __ANDROID__ | |
System.Diagnostics.Debug.WriteLine("I'm in Android"); | |
var native = Platform.GetRenderer(this); | |
var result = native.ViewGroup.GetAllChildren(); | |
Debug.WriteLine("babies " + result.Count); | |
#endif | |
#if __ANDROID__ | |
/// <summary> | |
/// View group extension. | |
/// </summary> | |
public static class ViewGroupExtension | |
{ | |
/// <summary> | |
/// Gets all children. | |
/// </summary> | |
/// <returns>The all children.</returns> | |
/// <param name="viewGroup">View group.</param> | |
public static IList<Android.Views.View> GetAllChildren(this ViewGroup viewGroup) | |
{ | |
var children = new List<Android.Views.View>(); | |
for (var index = 0; index < viewGroup.ChildCount; index++) | |
{ | |
var view = viewGroup.GetChildAt(index); | |
if (view is ViewGroup) | |
{ | |
children.AddRange((view as ViewGroup).GetAllChildren()); | |
} | |
else | |
{ | |
children.Add(view); | |
} | |
} | |
return children; | |
} | |
/// <summary> | |
/// Determines if is editable the specified viewGroup. | |
/// </summary> | |
/// <returns><c>true</c> if is editable the specified viewGroup; otherwise, <c>false</c>.</returns> | |
/// <param name="viewGroup">View group.</param> | |
public static bool IsEditable(this ViewGroup viewGroup) | |
{ | |
return viewGroup.GetAllChildren().Where(v => v is Android.Widget.EditText && v.Focusable).Any(); | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment