2017-03-23 20:18:38 +03:00
using Xamarin.Forms.CustomAttributes ;
using Xamarin.Forms.Internals ;
#if UITEST
using Xamarin.Forms.Core.UITests ;
using Xamarin.UITest ;
using NUnit.Framework ;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.IsEnabled)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 44096, "Grid, StackLayout, and ContentView still participate in hit testing on Android after IsEnabled is set to false", PlatformAffected.Android)]
public class Bugzilla44096 : TestContentPage
{
bool _flag ;
2017-09-06 01:18:05 +03:00
const string Child = "Child" ;
const string Original = "Original" ;
const string ToggleColor = "color" ;
const string ToggleIsEnabled = "disabled" ;
const string StackLayout = "stackLayout" ;
const string ContentView = "contentView" ;
const string Grid = "grid" ;
2017-09-06 01:23:28 +03:00
const string RelativeLayout = "relativeLayout" ;
2017-03-23 20:18:38 +03:00
protected override void Init ( )
{
var result = new Label
{
2017-09-06 01:18:05 +03:00
Text = Original
2017-03-23 20:18:38 +03:00
} ;
var grid = new Grid
{
IsEnabled = true ,
WidthRequest = 250 ,
HeightRequest = 50 ,
2017-09-06 01:18:05 +03:00
AutomationId = Grid
2017-03-23 20:18:38 +03:00
} ;
AddTapGesture ( result , grid ) ;
var contentView = new ContentView
{
IsEnabled = true ,
WidthRequest = 250 ,
HeightRequest = 50 ,
2017-09-06 01:18:05 +03:00
AutomationId = ContentView
2017-03-23 20:18:38 +03:00
} ;
AddTapGesture ( result , contentView ) ;
var stackLayout = new StackLayout
{
IsEnabled = true ,
WidthRequest = 250 ,
HeightRequest = 50 ,
2017-09-06 01:18:05 +03:00
AutomationId = StackLayout
2017-03-23 20:18:38 +03:00
} ;
AddTapGesture ( result , stackLayout ) ;
2017-09-06 01:23:28 +03:00
var relativeLayout = new RelativeLayout
{
IsEnabled = true ,
WidthRequest = 250 ,
HeightRequest = 50 ,
AutomationId = RelativeLayout
} ;
AddTapGesture ( result , relativeLayout ) ;
2017-03-23 20:18:38 +03:00
var color = new Button
{
Text = "Toggle colors" ,
Command = new Command ( ( ) = >
{
if ( ! _flag )
{
grid . BackgroundColor = Color . Red ;
contentView . BackgroundColor = Color . Blue ;
stackLayout . BackgroundColor = Color . Yellow ;
2017-09-06 01:23:28 +03:00
relativeLayout . BackgroundColor = Color . Green ;
2017-03-23 20:18:38 +03:00
}
else
{
grid . BackgroundColor = Color . Default ;
contentView . BackgroundColor = Color . Default ;
stackLayout . BackgroundColor = Color . Default ;
2017-09-06 01:23:28 +03:00
relativeLayout . BackgroundColor = Color . Default ;
2017-03-23 20:18:38 +03:00
}
_flag = ! _flag ;
} ) ,
2017-09-06 01:18:05 +03:00
AutomationId = ToggleColor
2017-03-23 20:18:38 +03:00
} ;
var disabled = new Button
{
2017-09-06 01:18:05 +03:00
Text = "Toggle IsEnabled" ,
2017-03-23 20:18:38 +03:00
Command = new Command ( ( ) = >
{
grid . IsEnabled = false ;
contentView . IsEnabled = false ;
stackLayout . IsEnabled = false ;
2017-09-06 01:23:28 +03:00
relativeLayout . IsEnabled = false ;
2017-03-23 20:18:38 +03:00
2017-09-06 01:18:05 +03:00
result . Text = Original ;
2017-03-23 20:18:38 +03:00
} ) ,
2017-09-06 01:18:05 +03:00
AutomationId = ToggleIsEnabled
2017-03-23 20:18:38 +03:00
} ;
var parent = new StackLayout
{
Spacing = 10 ,
Orientation = StackOrientation . Vertical ,
HorizontalOptions = LayoutOptions . Center ,
VerticalOptions = LayoutOptions . Center ,
Children =
{
color ,
disabled ,
result ,
grid ,
contentView ,
2017-09-06 01:23:28 +03:00
stackLayout ,
relativeLayout
2017-03-23 20:18:38 +03:00
}
} ;
Content = parent ;
}
void AddTapGesture ( Label result , View view )
{
var tapGestureRecognizer = new TapGestureRecognizer
{
Command = new Command ( ( ) = >
{
2017-09-06 01:18:05 +03:00
result . Text = Child ;
2017-03-23 20:18:38 +03:00
} )
} ;
view . GestureRecognizers . Add ( tapGestureRecognizer ) ;
}
#if UITEST
2017-09-06 01:18:05 +03:00
2017-03-23 20:18:38 +03:00
[Test]
2017-09-06 01:18:05 +03:00
public void TestGrid ( )
2017-03-23 20:18:38 +03:00
{
2017-09-06 01:18:05 +03:00
TestControl ( Grid ) ;
}
2017-03-23 20:18:38 +03:00
2017-09-06 01:18:05 +03:00
[Test]
public void TestContentView ( )
{
TestControl ( ContentView ) ;
}
2017-03-23 20:18:38 +03:00
2017-09-06 01:18:05 +03:00
[Test]
public void TestStackLayout ( )
{
TestControl ( StackLayout ) ;
}
2017-03-23 20:18:38 +03:00
2017-09-06 01:23:28 +03:00
[Test]
public void TestRelativeLayout ( )
{
TestControl ( RelativeLayout ) ;
}
2017-09-06 01:18:05 +03:00
void TestControl ( string control )
{
RunningApp . WaitForElement ( q = > q . Marked ( control ) ) ;
RunningApp . Tap ( q = > q . Marked ( control ) ) ;
RunningApp . WaitForElement ( q = > q . Marked ( Child ) ) ;
2017-03-23 20:18:38 +03:00
2017-09-06 01:18:05 +03:00
RunningApp . WaitForElement ( q = > q . Marked ( ToggleColor ) ) ;
RunningApp . Tap ( q = > q . Marked ( ToggleColor ) ) ;
2017-03-23 20:18:38 +03:00
2017-09-06 01:18:05 +03:00
RunningApp . WaitForElement ( q = > q . Marked ( control ) ) ;
RunningApp . Tap ( q = > q . Marked ( control ) ) ;
RunningApp . WaitForElement ( q = > q . Marked ( Child ) ) ;
2017-03-23 20:18:38 +03:00
2017-09-06 01:18:05 +03:00
RunningApp . WaitForElement ( q = > q . Marked ( ToggleIsEnabled ) ) ;
RunningApp . Tap ( q = > q . Marked ( ToggleIsEnabled ) ) ;
2017-03-23 20:18:38 +03:00
2017-09-06 01:18:05 +03:00
RunningApp . WaitForElement ( q = > q . Marked ( control ) ) ;
RunningApp . Tap ( q = > q . Marked ( control ) ) ;
RunningApp . WaitForElement ( q = > q . Marked ( Original ) ) ;
2017-03-23 20:18:38 +03:00
2017-09-06 01:18:05 +03:00
RunningApp . WaitForElement ( q = > q . Marked ( ToggleColor ) ) ;
RunningApp . Tap ( q = > q . Marked ( ToggleColor ) ) ;
2017-03-23 20:18:38 +03:00
2017-09-06 01:18:05 +03:00
RunningApp . WaitForElement ( q = > q . Marked ( control ) ) ;
RunningApp . Tap ( q = > q . Marked ( control ) ) ;
RunningApp . WaitForElement ( q = > q . Marked ( Original ) ) ;
2017-03-23 20:18:38 +03:00
}
#endif
}
}