Exemple #1
0
        public void TestProgramaticallyClose()
        {
            bool isOpen = false;

            var swipeView = new SwipeView();

            swipeView.OpenRequested  += (sender, args) => isOpen = true;
            swipeView.CloseRequested += (sender, args) => isOpen = false;

            var swipeItem = new SwipeItem
            {
                BackgroundColor = Colors.Red,
                Text            = "Text"
            };

            swipeView.LeftItems = new SwipeItems
            {
                swipeItem
            };

            swipeView.Open(OpenSwipeItem.LeftItems);

            swipeView.Close();

            Assert.IsFalse(isOpen);
        }
Exemple #2
0
        protected override void Init()
        {
            Title = "Issue 10563";

            var swipeLayout = new StackLayout
            {
                Margin = new Thickness(12)
            };

            var openLeftButton = new Button
            {
                AutomationId = OpenLeftId,
                Text         = "Open Left SwipeItem"
            };

            var openRightButton = new Button
            {
                AutomationId = OpenRightId,
                Text         = "Open Right SwipeItem"
            };

            var openTopButton = new Button
            {
                AutomationId = OpenTopId,
                Text         = "Open Top SwipeItem"
            };

            var openBottomButton = new Button
            {
                AutomationId = OpenBottomId,
                Text         = "Open Bottom SwipeItem"
            };

            var closeButton = new Button
            {
                AutomationId = CloseId,
                Text         = "Close SwipeView"
            };

            swipeLayout.Children.Add(openLeftButton);
            swipeLayout.Children.Add(openRightButton);
            swipeLayout.Children.Add(openTopButton);
            swipeLayout.Children.Add(openBottomButton);
            swipeLayout.Children.Add(closeButton);

            var swipeItem = new SwipeItem
            {
                BackgroundColor = Color.Red,
                IconImageSource = "calculator.png",
                Text            = "Issue 10563"
            };

            swipeItem.Invoked += (sender, e) => { DisplayAlert("SwipeView", "SwipeItem Invoked", "Ok"); };

            var swipeItems = new SwipeItems {
                swipeItem
            };

            swipeItems.Mode = SwipeMode.Reveal;

            var swipeContent = new Grid
            {
                BackgroundColor = Color.Gray
            };

            var swipeLabel = new Label
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                Text = "Swipe to any direction"
            };

            swipeContent.Children.Add(swipeLabel);

            var swipeView = new SwipeView
            {
                HeightRequest = 60,
                WidthRequest  = 300,
                LeftItems     = swipeItems,
                RightItems    = swipeItems,
                TopItems      = swipeItems,
                BottomItems   = swipeItems,
                Content       = swipeContent,
                Margin        = new Thickness(0, 48)
            };

            swipeLayout.Children.Add(swipeView);

            Content = swipeLayout;

            openLeftButton.Clicked += (sender, e) =>
            {
                swipeView.Open(OpenSwipeItem.LeftItems);
            };

            openRightButton.Clicked += (sender, e) =>
            {
                swipeView.Open(OpenSwipeItem.RightItems);
            };

            openTopButton.Clicked += (sender, e) =>
            {
                swipeView.Open(OpenSwipeItem.TopItems);
            };

            openBottomButton.Clicked += (sender, e) =>
            {
                swipeView.Open(OpenSwipeItem.BottomItems);
            };

            closeButton.Clicked += (sender, e) =>
            {
                swipeView.Close();
            };
        }
Exemple #3
0
        public AddRemoveSwipeItemsGallery()
        {
            Title = "Add/Remove SwipeItems Gallery";

            var swipeLayout = new StackLayout
            {
                Margin = new Thickness(12)
            };

            var buttonsLayout = new StackLayout
            {
                Orientation = StackOrientation.Horizontal
            };

            var addButton = new Button
            {
                Text = "Add SwipeItem"
            };

            buttonsLayout.Children.Add(addButton);

            var removeButton = new Button
            {
                Text = "Remove SwipeItem"
            };

            buttonsLayout.Children.Add(removeButton);

            var swipeItemIconLabel = new Label
            {
                FontSize = 10,
                Text     = "Choose SwipeItem Icon:"
            };

            var deleteSwipeItem = new SwipeItem
            {
                BackgroundColor = Color.Orange,
                IconImageSource = "calculator.png",
                Text            = "SwipeItem1"
            };

            deleteSwipeItem.Invoked += (sender, e) => { DisplayAlert("SwipeView", "Delete Invoked", "Ok"); };

            var leftSwipeItems = new SwipeItems
            {
                deleteSwipeItem
            };

            leftSwipeItems.Mode = SwipeMode.Reveal;

            var swipeContent = new Grid
            {
                BackgroundColor = Color.Gray
            };

            var swipeLabel = new Label
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                Text = "Swipe to Right"
            };

            swipeContent.Children.Add(swipeLabel);

            var swipeView = new SwipeView
            {
                HeightRequest = 60,
                WidthRequest  = 300,
                LeftItems     = leftSwipeItems,
                Content       = swipeContent
            };

            swipeLayout.Children.Add(buttonsLayout);
            swipeLayout.Children.Add(swipeView);

            Content = swipeLayout;

            addButton.Clicked += (sender, e) =>
            {
                swipeView.Close();

                var swipeItemsCount = swipeView.LeftItems.Count;
                var random          = new Random();

                var newSwipeItem = new SwipeItem
                {
                    BackgroundColor = Color.FromRgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)),
                    IconImageSource = "calculator.png",
                    Text            = $"SwipeItem{swipeItemsCount + 1}"
                };

                swipeView.LeftItems.Add(newSwipeItem);
            };

            removeButton.Clicked += (sender, e) =>
            {
                swipeView.Close();

                var swipeItemsCount = swipeView.LeftItems.Count;

                if (swipeItemsCount > 0)
                {
                    var lastSwipeItem = swipeView.LeftItems.LastOrDefault();
                    swipeView.LeftItems.Remove(lastSwipeItem);
                }
            };
        }
        public CloseSwipeGallery()
        {
            Title = "Open/Close SwipeView Gallery";

            var swipeLayout = new StackLayout
            {
                Margin = new Thickness(12)
            };

            var openButton = new Button
            {
                Text = "Open SwipeView"
            };

            var closeButton = new Button
            {
                Text = "Close SwipeView"
            };

            swipeLayout.Children.Add(openButton);
            swipeLayout.Children.Add(closeButton);

            var swipeItem = new SwipeItem
            {
                BackgroundColor = Color.Red,
                IconImageSource = "calculator.png",
                Text            = "File"
            };

            swipeItem.Invoked += (sender, e) => { DisplayAlert("SwipeView", "File Invoked", "Ok"); };

            var swipeItems = new SwipeItems {
                swipeItem
            };

            swipeItems.Mode = SwipeMode.Reveal;

            var swipeContent = new Grid
            {
                BackgroundColor = Color.Gray
            };

            var fileSwipeLabel = new Label
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                Text = "Swipe to Right (File)"
            };

            swipeContent.Children.Add(fileSwipeLabel);

            var swipeView = new SwipeView
            {
                HeightRequest = 60,
                WidthRequest  = 300,
                LeftItems     = swipeItems,
                Content       = swipeContent
            };

            swipeLayout.Children.Add(swipeView);

            Content = swipeLayout;

            openButton.Clicked += (sender, e) =>
            {
                swipeView.Open(OpenSwipeItem.LeftItems);
            };

            closeButton.Clicked += (sender, e) =>
            {
                swipeView.Close();
            };
        }
        public Programmatical()
        {
            Title = "Programmatically";

            var swipeLayout = new Grid
            {
                RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Star
                    }
                },
                Margin = new Thickness(12)
            };

            var openButton = new Button
            {
                Text = "Open SwipeView"
            };

            var closeButton = new Button
            {
                Text = "Close SwipeView"
            };

            swipeLayout.Children.Add(openButton, 0, 0);
            swipeLayout.Children.Add(closeButton, 0, 1);

            var swipeItem = new SwipeItem
            {
                BackgroundColor = Color.Red,
                IconImageSource = "calculator.png",
                Text            = "File"
            };

            swipeItem.Invoked += (sender, e) => { DisplayAlert("SwipeView", "File Invoked", "Ok"); };

            var swipeItems = new SwipeItems {
                swipeItem
            };

            swipeItems.Mode = SwipeMode.Reveal;

            var swipeContent = new Grid
            {
                BackgroundColor = Color.Gray
            };

            var fileSwipeLabel = new Label
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                Text = "Swipe to Right (File)"
            };

            swipeContent.Children.Add(fileSwipeLabel);

            var swipeView = new SwipeView
            {
                HeightRequest = 60,
                WidthRequest  = 300,
                LeftItems     = swipeItems,
                Content       = swipeContent
            };

            swipeLayout.Children.Add(swipeView, 0, 2);

            var scroll     = new ScrollView();
            var eventsInfo = new Label();

            scroll.Content = eventsInfo;

            swipeLayout.Children.Add(scroll, 0, 3);

            Content = swipeLayout;

            openButton.Clicked += (sender, e) =>
            {
                swipeView.Open(OpenSwipeItem.LeftItems);
            };

            closeButton.Clicked += (sender, e) =>
            {
                swipeView.Close();
            };

            swipeView.SwipeStarted += (sender, e) =>
            {
                eventsInfo.Text += $"SwipeStarted - Direction:{e.SwipeDirection}" + Environment.NewLine;
            };

            swipeView.SwipeChanging += (sender, e) =>
            {
                eventsInfo.Text += $"SwipeChanging - Direction:{e.SwipeDirection}, Offset:{e.Offset}" + Environment.NewLine;
            };

            swipeView.SwipeEnded += (sender, e) =>
            {
                eventsInfo.Text += $"SwipeEnded - Direction:{e.SwipeDirection}" + Environment.NewLine;
            };
        }
        public SwipeItemViewIsEnabledGallery()
        {
            Title = "SwipeItemView IsEnabled Gallery";

            var swipeLayout = new StackLayout
            {
                Margin = new Thickness(12)
            };

            var instructions = new Label
            {
                BackgroundColor = Color.Black,
                TextColor       = Color.White,
                Text            = "RemainOpen is used as SwipeBehaviorOnInvoked, tapping on a SwipeItem will not close it."
            };

            swipeLayout.Children.Add(instructions);

            var closeButton = new Button
            {
                Text = "Close SwipeView"
            };

            swipeLayout.Children.Add(closeButton);

            var swipeItemContent = new StackLayout();

            var monkeyList = new List <string>
            {
                "Baboon",
                "Capuchin Monkey",
                "Blue Monkey",
                "Squirrel Monkey",
                "Golden Lion Tamarin",
                "Howler Monkey",
                "Japanese Macaque"
            };

            var monkeyPicker = new Picker {
                Title = "Select a monkey"
            };

            monkeyPicker.ItemsSource = monkeyList;

            var monkeyButton = new Button
            {
                Text = "Get Selected Monkey"
            };

            monkeyButton.Clicked += (sender, args) =>
            {
                var selectedMonkey = monkeyPicker.SelectedItem ?? "None";
                DisplayAlert("Selected Monkey", $"{selectedMonkey}", "Ok");
            };

            swipeItemContent.Children.Add(monkeyPicker);
            swipeItemContent.Children.Add(monkeyButton);

            var swipeItem = new SwipeItemView
            {
                BackgroundColor = Color.White,
                Content         = swipeItemContent
            };

            var swipeItems = new SwipeItems {
                swipeItem
            };

            swipeItems.SwipeBehaviorOnInvoked = SwipeBehaviorOnInvoked.RemainOpen;
            swipeItems.Mode = SwipeMode.Reveal;

            var swipeContent = new Grid
            {
                BackgroundColor = Color.Gray
            };

            var swipeLabel = new Label
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                Text = "Swipe to Right"
            };

            swipeContent.Children.Add(swipeLabel);

            var swipeView = new SwipeView
            {
                HeightRequest = 120,
                WidthRequest  = 300,
                LeftItems     = swipeItems,
                Content       = swipeContent
            };

            swipeLayout.Children.Add(swipeView);

            var swipeItemLayout = new StackLayout
            {
                Orientation = StackOrientation.Horizontal
            };

            var swipeItemButton = new Button
            {
                Text            = "Disable SwipeItemView",
                WidthRequest    = 250,
                VerticalOptions = LayoutOptions.Center
            };

            var swipeItemLabel = new Label
            {
                Text = "SwipeItemView is enabled"
            };

            swipeItemLayout.Children.Add(swipeItemButton);
            swipeItemLayout.Children.Add(swipeItemLabel);

            swipeLayout.Children.Add(swipeItemLayout);

            Content = swipeLayout;

            closeButton.Clicked += (sender, e) =>
            {
                swipeView.Close();
            };

            swipeItemButton.Clicked += (sender, args) =>
            {
                swipeItem.IsEnabled = !swipeItem.IsEnabled;

                if (swipeItem.IsEnabled)
                {
                    swipeItemButton.Text = "Disable SwipeItemView";
                    swipeItemLabel.Text  = "SwipeItemView is enabled";
                }
                else
                {
                    swipeItemButton.Text = "Enable SwipeItemView";
                    swipeItemLabel.Text  = "SwipeItemView is disabled";
                }
            };
        }
Exemple #7
0
        public SwipeItemIsEnabledGallery()
        {
            Title = "SwipeItem IsEnabled Gallery";

            var swipeLayout = new StackLayout
            {
                Margin = new Thickness(12)
            };

            var instructions = new Label
            {
                BackgroundColor = Colors.Black,
                TextColor       = Colors.White,
                Text            = "RemainOpen is used as SwipeBehaviorOnInvoked, tapping on a SwipeItem will not close it."
            };

            swipeLayout.Children.Add(instructions);

            var closeButton = new Button
            {
                Text = "Close SwipeView"
            };

            swipeLayout.Children.Add(closeButton);

            var swipeItem1 = new SwipeItem
            {
                BackgroundColor = Colors.Red,
                IconImageSource = "calculator.png",
                Text            = "Test 1"
            };

            swipeItem1.Invoked += (sender, e) => { DisplayAlert("SwipeView", "Test 1 Invoked", "Ok"); };

            var swipeItem2 = new SwipeItem
            {
                BackgroundColor = Colors.Orange,
                IconImageSource = "coffee.png",
                Text            = "Test 2"
            };

            swipeItem2.Invoked += (sender, e) => { DisplayAlert("SwipeView", "Test 2 Invoked", "Ok"); };

            var swipeItems = new SwipeItems {
                swipeItem1, swipeItem2
            };

            swipeItems.SwipeBehaviorOnInvoked = SwipeBehaviorOnInvoked.RemainOpen;
            swipeItems.Mode = SwipeMode.Reveal;

            var swipeContent = new Grid
            {
                BackgroundColor = Colors.Gray
            };

            var fileSwipeLabel = new Label
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                Text = "Swipe to Right"
            };

            swipeContent.Children.Add(fileSwipeLabel);

            var swipeView = new SwipeView
            {
                HeightRequest = 60,
                WidthRequest  = 300,
                LeftItems     = swipeItems,
                Content       = swipeContent
            };

            swipeLayout.Children.Add(swipeView);


            var swipeItem1Layout = new StackLayout
            {
                Orientation = StackOrientation.Horizontal
            };

            var swipeItem1Button = new Button
            {
                Text            = "Disable SwipeItem 1",
                WidthRequest    = 250,
                VerticalOptions = LayoutOptions.Center
            };

            var swipeItem1Label = new Label
            {
                Text            = "SwipeItem 1 is enabled",
                VerticalOptions = LayoutOptions.Center
            };

            swipeItem1Layout.Children.Add(swipeItem1Button);
            swipeItem1Layout.Children.Add(swipeItem1Label);

            swipeLayout.Children.Add(swipeItem1Layout);

            var swipeItem2Layout = new StackLayout
            {
                Orientation = StackOrientation.Horizontal
            };

            var swipeItem2Button = new Button
            {
                Text            = "Disable SwipeItem 2",
                WidthRequest    = 250,
                VerticalOptions = LayoutOptions.Center
            };

            var swipeItem2Label = new Label
            {
                Text            = "SwipeItem 2 is enabled",
                VerticalOptions = LayoutOptions.Center
            };

            swipeItem2Layout.Children.Add(swipeItem2Button);
            swipeItem2Layout.Children.Add(swipeItem2Label);

            swipeLayout.Children.Add(swipeItem2Layout);

            Content = swipeLayout;

            closeButton.Clicked += (sender, e) =>
            {
                swipeView.Close();
            };

            swipeItem1Button.Clicked += (sender, args) =>
            {
                swipeItem1.IsEnabled = !swipeItem1.IsEnabled;

                if (swipeItem1.IsEnabled)
                {
                    swipeItem1Button.Text = "Disable SwipeItem 1";
                    swipeItem1Label.Text  = "SwipeItem 1 is enabled";
                }
                else
                {
                    swipeItem1Button.Text = "Enable SwipeItem 1";
                    swipeItem1Label.Text  = "SwipeItem 1 is disabled";
                }
            };

            swipeItem2Button.Clicked += (sender, args) =>
            {
                swipeItem2.IsEnabled = !swipeItem2.IsEnabled;

                if (swipeItem2.IsEnabled)
                {
                    swipeItem2Button.Text = "Disable SwipeItem 2";
                    swipeItem2Label.Text  = "SwipeItem 2 is enabled";
                }
                else
                {
                    swipeItem2Button.Text = "Enable SwipeItem 2";
                    swipeItem2Label.Text  = "SwipeItem 2 is disabled";
                }
            };
        }