diff options
Diffstat (limited to 'Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2961.cs')
-rw-r--r-- | Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2961.cs | 290 |
1 files changed, 290 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2961.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2961.cs new file mode 100644 index 00000000..24665ea7 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2961.cs @@ -0,0 +1,290 @@ +using System; +using Xamarin.Forms.CustomAttributes; +using System.ComponentModel; +using System.Diagnostics; + + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +using Xamarin.UITest.iOS; +#endif + +namespace Xamarin.Forms.Controls +{ +#if UITEST + [Ignore("This test is looking for an invalid behavior; the second tap *should* keep the drawer open.")] +#endif + [Preserve (AllMembers = true)] + [Issue (IssueTracker.Github, 2961, "MasterDetail NavigationDrawer Does Not Hide On DoubleTap of Item", PlatformAffected.Android)] + public class Issue2961 : TestMasterDetailPage + { + static MasterDetailPage s_mdp; + + SliderMenuItem _selectedMenuItem; + SliderMenuPage _slidingPage; + ContentPage _displayPage; + + protected override void Init () + { + s_mdp = this; + + _slidingPage = new SliderMenuPage { + Title = "Menu", + BackgroundColor = Color.FromHex ("1e1e1e") + }; + _slidingPage.MenuListView.ItemTapped += (sender, e) => OnMenuSelected (e.Item as SliderMenuItem); + Padding = new Thickness (0); + + Master = _slidingPage; + OnMenuSelected (_slidingPage.MenuListView.SelectedItem as SliderMenuItem); + } + + void OnMenuSelected (SliderMenuItem menu) + { + Debug.WriteLine (IsPresented); + + IsPresented = false; + + if (menu == null || menu == _selectedMenuItem) { + return; + } + _displayPage = null; + + if (menu.TargetType.Equals (typeof(SignOutPage))) { + HandleSignOut (); + return; + } + _displayPage = (ContentPage)Activator.CreateInstance (menu.TargetType); + Detail = new NavigationPage (_displayPage); + + if (_selectedMenuItem != null) { + _selectedMenuItem.IsSelected = false; + } + + _selectedMenuItem = menu; + _selectedMenuItem.IsSelected = true; + } + + void HandleSignOut () + { + DisplayAlert ( + "", + "Do you want to sign out?", + "OK", + "Cancel" + ); + } + + [Preserve (AllMembers = true)] + public class SliderMenuItem: INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + + void NotifyPropertyChanged (string info) + { + if (PropertyChanged != null) { + PropertyChanged (this, new PropertyChangedEventArgs (info)); + } + } + + public SliderMenuItem (string title, Type targetType) + { + Title = title; + TargetType = targetType; + + } + + public string Title { get; set; } + + bool _isSelected; + + public bool IsSelected { + get{ return _isSelected; } + set { + if (_isSelected != value) { + _isSelected = value; + Background = _isSelected ? Color.FromHex ("101010") : Color.Transparent; + NotifyPropertyChanged ("Background"); + } + } + } + + public Type TargetType { get; set; } + + public Color Background { get; private set; } + } + + [Preserve (AllMembers = true)] + public class SliderMenuPage: ContentPage + { + public ListView MenuListView { get; set; } + + public SliderMenuPage () + { + var data = GetData (); + MenuListView = new ListView { + HorizontalOptions = LayoutOptions.StartAndExpand, + ItemTemplate = new DataTemplate (typeof(MenuCell)), + ItemsSource = data, + BackgroundColor = Color.FromHex ("1e1e1e"), + }; + + MenuListView.SelectedItem = data [0]; + data [0].IsSelected = true; + + var logoImg = new Image { + Source = ImageSource.FromFile ("bank.png"), + HorizontalOptions = LayoutOptions.Start, + VerticalOptions = LayoutOptions.EndAndExpand + }; + var logoImgWrapper = new StackLayout { + Padding = new Thickness (12, 24), + HorizontalOptions = LayoutOptions.FillAndExpand, + Children = { logoImg } + }; + + var paddingTop = Device.OnPlatform (40, 2, 2); + Content = new StackLayout { + Spacing = 0, + BackgroundColor = Color.FromHex ("1e1e1e"), + Padding = new Thickness (0, paddingTop, 0, 10), + VerticalOptions = LayoutOptions.FillAndExpand, + HorizontalOptions = LayoutOptions.FillAndExpand, + Children = { + MenuListView, + logoImgWrapper + } + }; + } + + SliderMenuItem[] GetData () + { + return new [] { + new SliderMenuItem ("Home", typeof(HomePage)), + new SliderMenuItem ("About", typeof(AboutPage)), + new SliderMenuItem ("Sign Out", typeof(SignOutPage)) + }; + } + } + + [Preserve (AllMembers = true)] + public class HomePage : ContentPage + { + + + public HomePage () + { + var showMasterButton = new Button { + AutomationId = "ShowMasterBtnHome", + Text = "Show Master" + }; + showMasterButton.Clicked += (sender, e) => { + s_mdp.IsPresented = true; + }; + + Content = new StackLayout { + + VerticalOptions = LayoutOptions.CenterAndExpand, + HorizontalOptions = LayoutOptions.CenterAndExpand, + Children = { + showMasterButton, + new Label { + AutomationId = "lblHome", + Text = "Sample Home page", + XAlign = TextAlignment.Center, + YAlign = TextAlignment.Center + } + } + }; + } + } + + [Preserve (AllMembers = true)] + public class AboutPage: ContentPage + { + public AboutPage () + { + var showMasterButton = new Button { + AutomationId = "ShowMasterBtnAbout", + Text = "Show Master" + }; + showMasterButton.Clicked += (sender, e) => { + s_mdp.IsPresented = true; + }; + + Content = new StackLayout { + VerticalOptions = LayoutOptions.CenterAndExpand, + HorizontalOptions = LayoutOptions.CenterAndExpand, + Children = { + showMasterButton, + new Label { + AutomationId = "lblAbout", + Text = "Sample About page", + XAlign = TextAlignment.Center, + YAlign = TextAlignment.Center + } + } + }; + } + } + + [Preserve (AllMembers = true)] + public class SignOutPage + { + public SignOutPage () + { + } + } + + [Preserve (AllMembers = true)] + public class MenuCell: ViewCell + { + public MenuCell () + { + Label textLabel = new Label { + FontSize = 18, + }; + + textLabel.SetBinding (Label.TextProperty, "Title"); + var root = new StackLayout { + Padding = new Thickness (12, 8), + Children = { textLabel } + }; + root.SetBinding (BackgroundColorProperty, "Background"); + View = root; + } + } + + + #if UITEST + [Test] + public void Issue2961Test () + { + RunningApp.Screenshot ("I am at Issue 2961"); + OpenMDP ("ShowMasterBtnHome"); + RunningApp.Tap (c => c.Marked ("Home")); + RunningApp.WaitForElement (c => c.Marked ("lblHome")); + OpenMDP ("ShowMasterBtnHome"); + RunningApp.Tap (c => c.Marked ("About")); + RunningApp.WaitForElement (c => c.Marked ("lblAbout")); + OpenMDP ("ShowMasterBtnAbout"); + if(RunningApp is iOSApp) + return; + RunningApp.DoubleTap (c => c.Marked ("Home")); + RunningApp.WaitForElement (c => c.Marked ("lblHome")); + RunningApp.Tap (c => c.Marked ("About")); + RunningApp.WaitForNoElement (c => c.Marked ("Home")); + + } + + public void OpenMDP(string masterBtnId) { + if(RunningApp is iOSApp) { + RunningApp.Tap (q => q.Marked("Menu")); + } else { + RunningApp.Tap (masterBtnId); + } + } + #endif + } +} |