void UpdateSwipeItems() { if (_contentView == null || _actionView != null) { return; } _swipeItemsRect = new List <CGRect>(); SwipeItems items = GetSwipeItemsByDirection(); double swipeItemsWidth; if (_swipeDirection == SwipeDirection.Left || _swipeDirection == SwipeDirection.Right) { swipeItemsWidth = (items != null ? items.Count : 0) * SwipeItemWidth; } else { swipeItemsWidth = _contentView.Frame.Width; } if (items == null) { return; } _actionView = new UIStackView { Axis = UILayoutConstraintAxis.Horizontal, Frame = new CGRect(0, 0, swipeItemsWidth, _contentView.Frame.Height) }; int i = 0; float previousWidth = 0; foreach (var item in items) { var swipeItem = (item is SwipeItem) ? CreateSwipeItem((SwipeItem)item) : CreateSwipeItemView((SwipeItemView)item); var swipeItemSize = GetSwipeItemSize(item); float swipeItemHeight = (float)swipeItemSize.Height; float swipeItemWidth = (float)swipeItemSize.Width; switch (_swipeDirection) { case SwipeDirection.Left: swipeItem.Frame = new CGRect(_contentView.Frame.Width - (swipeItemWidth + previousWidth), 0, i + 1 * swipeItemWidth, swipeItemHeight); break; case SwipeDirection.Right: case SwipeDirection.Up: case SwipeDirection.Down: swipeItem.Frame = new CGRect(previousWidth, 0, i + 1 * swipeItemWidth, swipeItemHeight); break; } _actionView.AddSubview(swipeItem); _swipeItemsRect.Add(swipeItem.Frame); previousWidth += swipeItemWidth; i++; } AddSubview(_actionView); BringSubviewToFront(_contentView); }
public SecondIssue10679Page() { var layout = new Grid(); var swipeView = new SwipeView(); var leftItem = new SwipeItem { BackgroundColor = Color.Red }; var leftItems = new SwipeItems { Mode = SwipeMode.Execute, SwipeBehaviorOnInvoked = SwipeBehaviorOnInvoked.Close }; leftItems.Add(leftItem); var rightItem = new SwipeItem { BackgroundColor = Color.Green }; var rightItems = new SwipeItems { Mode = SwipeMode.Execute, SwipeBehaviorOnInvoked = SwipeBehaviorOnInvoked.Close }; rightItems.Add(rightItem); var content = new Grid { BackgroundColor = Color.White }; var contentLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Swipe Left or Right" }; content.Children.Add(contentLabel); swipeView.Content = content; swipeView.LeftItems = leftItems; swipeView.RightItems = rightItems; layout.Children.Add(swipeView); Content = layout; leftItem.Invoked += async(sender, args) => { Shell.Current.Navigation.InsertPageBefore(new ThirdIssue10679Page(), this); _ = await Shell.Current.Navigation.PopAsync(false); }; rightItem.Invoked += async(sender, args) => { Shell.Current.Navigation.InsertPageBefore(new ThirdIssue10679Page(), this); _ = await Shell.Current.Navigation.PopAsync(false); }; }
public SwipeView CreateMySwipeView() { // Define Right Swipe var rightSwipeItem = new SwipeItem { Text = "Right", BackgroundColor = Color.Green, Command = new Command(() => { _leftCount++; _leftSwipeCountLabel.Text = _leftCount.ToString(); }) }; var rightSwipeItems = new SwipeItems { rightSwipeItem }; rightSwipeItems.SwipeBehaviorOnInvoked = SwipeBehaviorOnInvoked.Close; rightSwipeItems.Mode = SwipeMode.Execute; // Define Left Swipe var leftSwipeItem = new SwipeItem { Text = "Left", BackgroundColor = Color.Red, Command = new Command(() => { _rightCount++; _rightSwipeCountLabel.Text = _rightCount.ToString(); }) }; var leftSwipeItems = new SwipeItems { leftSwipeItem }; leftSwipeItems.SwipeBehaviorOnInvoked = SwipeBehaviorOnInvoked.Close; leftSwipeItems.Mode = SwipeMode.Execute; // Define Swipe Content var swipeContent = new ContentView { Content = new StackLayout { AutomationId = SwipeViewId, BackgroundColor = Color.Coral, Children = { new Label { Text = "Standalone SwipeItem", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center } } } }; // Create SwipeView var mySwipeView = new SwipeView { RightItems = rightSwipeItems, LeftItems = leftSwipeItems, Content = swipeContent, HeightRequest = 80 }; return(mySwipeView); }
bool IsValidSwipeItems(SwipeItems swipeItems) { return(swipeItems != null && swipeItems.Where(s => s.IsVisible).Count() > 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); } }; }
bool IsValidSwipeItems(SwipeItems swipeItems) { return(swipeItems != null && swipeItems.Count > 0); }
protected override void Init() { Title = "Issue 12079"; var layout = new StackLayout { Margin = new Thickness(12) }; var instructions = new Label { BackgroundColor = Colors.Black, TextColor = Colors.White, Text = "Swipe to the right, if can open the SwipeView the test has passed." }; var swipeItem = new SwipeItem { BackgroundColor = Colors.Red, IconImageSource = "calculator.png" }; swipeItem.Invoked += (sender, e) => { DisplayAlert("Issue12079", "Invoked", "Ok"); }; var swipeItems = new SwipeItems { swipeItem }; swipeItems.Mode = SwipeMode.Reveal; var swipeContent = new Grid { BackgroundColor = Colors.Gray }; var swipeLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Swipe to Right (No Text)" }; swipeContent.Children.Add(swipeLabel); var swipeView = new SwipeView { AutomationId = SwipeViewId, HeightRequest = 60, WidthRequest = 300, LeftItems = swipeItems, Content = swipeContent }; var result = new Label(); swipeView.SwipeEnded += (sender, args) => { result.Text = "Success"; }; layout.Children.Add(instructions); layout.Children.Add(swipeView); layout.Children.Add(result); Content = layout; }
public SwipeBehaviorOnInvokedGallery() { Title = "SwipeBehaviorOnInvoked Gallery"; var swipeLayout = new StackLayout { Margin = new Thickness(12) }; var swipeBehaviorOnInvokedLabel = new Label { FontSize = 10, Text = "SwipeBehaviorOnInvoked:" }; swipeLayout.Children.Add(swipeBehaviorOnInvokedLabel); var swipeBehaviorOnInvokedItems = Enum.GetNames(typeof(SwipeBehaviorOnInvoked)).Select(s => s).ToList(); var swipeBehaviorOnInvokedPicker = new Picker { ItemsSource = swipeBehaviorOnInvokedItems, SelectedIndex = 0 }; swipeLayout.Children.Add(swipeBehaviorOnInvokedPicker); var deleteSwipeItem = new SwipeItem { BackgroundColor = Color.Red, Text = "Delete", IconImageSource = "calculator.png" }; deleteSwipeItem.Invoked += (sender, e) => { DisplayAlert("SwipeView", "Delete Invoked", "Ok"); }; var leftSwipeItems = new SwipeItems { deleteSwipeItem }; leftSwipeItems.Mode = SwipeMode.Reveal; leftSwipeItems.SwipeBehaviorOnInvoked = SwipeBehaviorOnInvoked.Auto; var swipeContent = new Grid { BackgroundColor = Color.Gray }; var swipeLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Swipe to Right (and tap the SwipeItem)" }; swipeContent.Children.Add(swipeLabel); var swipeView = new SwipeView { HeightRequest = 60, WidthRequest = 300, LeftItems = leftSwipeItems, Content = swipeContent }; swipeLayout.Children.Add(swipeView); swipeBehaviorOnInvokedPicker.SelectedIndexChanged += (sender, e) => { Enum.TryParse(swipeBehaviorOnInvokedPicker.SelectedItem.ToString(), out SwipeBehaviorOnInvoked swipeBehaviorOnInvoked); leftSwipeItems.SwipeBehaviorOnInvoked = swipeBehaviorOnInvoked; }; Content = swipeLayout; }
public SwipeItemIconGallery() { Title = "SwipeItem Icon Gallery"; var scroll = new ScrollView(); var swipeLayout = new StackLayout { Margin = new Thickness(12) }; var fileSwipeItem = new SwipeItem { BackgroundColor = Color.Red, IconImageSource = "calculator.png", Text = "File" }; fileSwipeItem.Invoked += (sender, e) => { DisplayAlert("SwipeView", "File Invoked", "Ok"); }; var fileSwipeItems = new SwipeItems { fileSwipeItem }; fileSwipeItems.Mode = SwipeMode.Reveal; var fileSwipeContent = new Grid { BackgroundColor = Color.Gray }; var fileSwipeLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Swipe to Right (File)" }; fileSwipeContent.Children.Add(fileSwipeLabel); var fileSwipeView = new SwipeView { HeightRequest = 60, WidthRequest = 300, LeftItems = fileSwipeItems, Content = fileSwipeContent }; swipeLayout.Children.Add(fileSwipeView); var urlSwipeItem = new SwipeItem { BackgroundColor = Color.Red, IconImageSource = "https://image.flaticon.com/icons/png/512/61/61848.png", Text = "Url" }; urlSwipeItem.Invoked += (sender, e) => { DisplayAlert("SwipeView", "Url Invoked", "Ok"); }; var urlSwipeItems = new SwipeItems { urlSwipeItem }; urlSwipeItems.Mode = SwipeMode.Reveal; var urlSwipeContent = new Grid { BackgroundColor = Color.Gray }; var urlSwipeLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Swipe to Right (Url)" }; urlSwipeContent.Children.Add(urlSwipeLabel); var urlSwipeView = new SwipeView { HeightRequest = 60, WidthRequest = 300, LeftItems = urlSwipeItems, Content = urlSwipeContent }; swipeLayout.Children.Add(urlSwipeView); var fontFamily = string.Empty; switch (Device.RuntimePlatform) { case Device.iOS: fontFamily = "Ionicons"; break; case Device.UWP: fontFamily = "Assets/Fonts/ionicons.ttf#ionicons"; break; case Device.Android: default: fontFamily = "fonts/ionicons.ttf#"; break; } var fontSwipeItem = new SwipeItem { BackgroundColor = Color.Red, IconImageSource = new FontImageSource { Glyph = "\uf101", FontFamily = fontFamily, Size = 16 }, Text = "Font" }; fontSwipeItem.Invoked += (sender, e) => { DisplayAlert("SwipeView", "Font Invoked", "Ok"); }; var fontSwipeItems = new SwipeItems { fontSwipeItem }; fontSwipeItems.Mode = SwipeMode.Reveal; var fontSwipeContent = new Grid { BackgroundColor = Color.Gray }; var fontSwipeLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Swipe to Right (Font)" }; fontSwipeContent.Children.Add(fontSwipeLabel); var fontSwipeView = new SwipeView { HeightRequest = 60, WidthRequest = 300, LeftItems = fontSwipeItems, Content = fontSwipeContent }; swipeLayout.Children.Add(fontSwipeView); scroll.Content = swipeLayout; Content = scroll; }
public CustomizeSwipeItemGallery() { Title = "Customize SwipeItem Gallery"; var swipeLayout = new StackLayout { Margin = new Thickness(12) }; var swipeItemTextLabel = new Label { FontSize = 10, Text = "SwipeItem Text:" }; swipeLayout.Children.Add(swipeItemTextLabel); var swipeItemTextEntry = new Entry { Text = "Delete", Placeholder = "SwipeItem Text" }; swipeLayout.Children.Add(swipeItemTextEntry); var swipeItemBackgroundColorLabel = new Label { FontSize = 10, Text = "Choose SwipeItem BackgroundColor:" }; swipeLayout.Children.Add(swipeItemBackgroundColorLabel); var swipeItemBackgroundColorPicker = new Picker(); var colors = new List <string> { "#FFFFFF", "#FF0000", "#00FF00", "#0000FF", "#000000" }; swipeItemBackgroundColorPicker.ItemsSource = colors; swipeItemBackgroundColorPicker.SelectedItem = colors[1]; swipeLayout.Children.Add(swipeItemBackgroundColorPicker); var swipeItemIconLabel = new Label { FontSize = 10, Text = "Choose SwipeItem Icon:" }; swipeLayout.Children.Add(swipeItemIconLabel); var swipeItemIconPicker = new Picker(); var icons = new List <string> { "add.png", "edit.png", "delete.png" }; swipeItemIconPicker.ItemsSource = icons; swipeItemIconPicker.SelectedItem = icons[1]; swipeLayout.Children.Add(swipeItemIconPicker); var deleteSwipeItem = new SwipeItem { BackgroundColor = Color.FromHex(colors[swipeItemBackgroundColorPicker.SelectedIndex]), IconImageSource = swipeItemIconPicker.SelectedItem.ToString(), Text = swipeItemTextEntry.Text }; deleteSwipeItem.Invoked += (sender, e) => { DisplayAlert("SwipeView", "Delete Invoked", "Ok"); }; var leftSwipeItems = new SwipeItems { deleteSwipeItem }; leftSwipeItems.Mode = SwipeMode.Execute; 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(swipeView); swipeItemTextEntry.TextChanged += (sender, e) => { deleteSwipeItem.Text = swipeItemTextEntry.Text; }; swipeItemBackgroundColorPicker.SelectedIndexChanged += (sender, e) => { deleteSwipeItem.BackgroundColor = Color.FromHex(colors[swipeItemBackgroundColorPicker.SelectedIndex]); }; swipeItemIconPicker.SelectedIndexChanged += (sender, e) => { deleteSwipeItem.IconImageSource = swipeItemIconPicker.SelectedItem.ToString(); }; Content = swipeLayout; }
public OpenCloseSwipeGallery() { Title = "Open/Close SwipeView Gallery"; var swipeLayout = new StackLayout { Margin = new Thickness(12) }; var openButton = new Button { HorizontalOptions = LayoutOptions.Start, Text = "Open SwipeView" }; var closeButton = new Button { HorizontalOptions = LayoutOptions.Start, Text = "Close SwipeView" }; var animatedLayout = new StackLayout { HorizontalOptions = LayoutOptions.Start, Orientation = StackOrientation.Horizontal }; var animatedCheckBox = new CheckBox { IsChecked = true, VerticalOptions = LayoutOptions.Center }; animatedLayout.Children.Add(animatedCheckBox); animatedLayout.Children.Add(animatedCheckBox); var animatedLabel = new Label { Text = "Animated", VerticalOptions = LayoutOptions.Center }; animatedLayout.Children.Add(animatedLabel); swipeLayout.Children.Add(animatedLayout); 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) => { bool animated = animatedCheckBox.IsChecked; swipeView.Open(OpenSwipeItem.LeftItems, animated); }; closeButton.Clicked += (sender, e) => { bool animated = animatedCheckBox.IsChecked; swipeView.Close(animated); }; }
public SwipeItemViewIsEnabledGallery() { Title = "SwipeItemView 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 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 = Colors.White, Content = swipeItemContent }; var swipeItems = new SwipeItems { swipeItem }; swipeItems.SwipeBehaviorOnInvoked = SwipeBehaviorOnInvoked.RemainOpen; swipeItems.Mode = SwipeMode.Reveal; var swipeContent = new Grid { BackgroundColor = Colors.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"; } }; }
static SwipeView LoadTemplate(OpportunityModel opportunityModel) { var beaconFundingImage = new Image { Source = "beaconfundingicon", HeightRequest = _rowHeight }; var topicTitleLabel = new Label { Text = "Topic", FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.End }; var topicDescriptionLabel = new Label { VerticalTextAlignment = TextAlignment.Start, Text = opportunityModel.Topic }; var companyTitleLabel = new Label { Text = "Company", FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.End }; var companyDescriptionLabel = new Label { VerticalTextAlignment = TextAlignment.Start, Text = opportunityModel.Company }; var leaseAmountTitleLabel = new Label { Text = "Lease Amount", FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.End }; var leaseAmountDescriptionLabel = new Label { VerticalTextAlignment = TextAlignment.Start, Text = opportunityModel.LeaseAmountAsCurrency }; var ownerTitleLabel = new Label { Text = "Owner", FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.End }; var ownerDescriptionLabel = new Label { VerticalTextAlignment = TextAlignment.Start, Text = opportunityModel.Owner }; var grid = new Grid { BackgroundColor = Color.White, Padding = new Thickness(5, 0, 0, 0), ColumnSpacing = 20, RowDefinitions = { new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, new RowDefinition { Height = new GridLength(1, GridUnitType.Star) } }, ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(_rowHeight / 3, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) } } }; grid.Children.Add(beaconFundingImage, 0, 0); Grid.SetRowSpan(beaconFundingImage, 2); grid.Children.Add(topicTitleLabel, 1, 0); grid.Children.Add(topicDescriptionLabel, 1, 1); if (Device.Idiom != TargetIdiom.Phone) { grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); grid.Children.Add(companyTitleLabel, 2, 0); grid.Children.Add(companyDescriptionLabel, 2, 1); grid.Children.Add(leaseAmountTitleLabel, 3, 0); grid.Children.Add(leaseAmountDescriptionLabel, 3, 1); grid.Children.Add(ownerTitleLabel, 4, 0); grid.Children.Add(ownerDescriptionLabel, 4, 1); } var deleteSwipeItem = new SwipeItem { Text = "Delete", IconImageSource = "Delete", BackgroundColor = Color.Red, Command = new AsyncCommand <string>(ExecuteSwipeToDeleteCommand) }; deleteSwipeItem.SetBinding(SwipeItem.CommandParameterProperty, nameof(OpportunityModel.Topic)); var rightSwipeItems = new SwipeItems { Mode = SwipeMode.Execute }; rightSwipeItems.Add(deleteSwipeItem); var swipeViewTappedCommand = new AsyncCommand <OpportunityModel>(ExecuteSwipeViewTappedCommand); var swipeView = new ExtendedSwipeView(swipeViewTappedCommand, opportunityModel) { RightItems = rightSwipeItems, Content = grid, Margin = new Thickness(0, 5, 0, 15) }; return(swipeView); }
public CloseSwipeGallery() { Title = "Close SwipeView Gallery"; var swipeLayout = new StackLayout { Margin = new Thickness(12) }; var closeButton = new Button { Text = "Close SwipeView" }; swipeLayout.Children.Add(closeButton); var swipeItem = new SwipeItem { BackgroundColor = Color.Red, IconImageSource = "delete.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; closeButton.Clicked += (sender, e) => { swipeView.Close(); }; }
public SwipeItemIsEnabledGallery() { Title = "SwipeItem 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 swipeItem1 = new SwipeItem { BackgroundColor = Color.Red, IconImageSource = "calculator.png", Text = "Test 1" }; swipeItem1.Invoked += (sender, e) => { DisplayAlert("SwipeView", "Test 1 Invoked", "Ok"); }; var swipeItem2 = new SwipeItem { BackgroundColor = Color.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 = Color.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"; } }; }
protected override void Init() { Title = "Issue 8806"; var layout = new StackLayout { Margin = new Thickness(12) }; var instructions = new Label { BackgroundColor = Color.Black, TextColor = Color.White, Text = "Swipe left and right several times and verify that the layout is always correct." }; var leftSwipeItem = new SwipeItem { BackgroundColor = Color.Red, IconImageSource = "calculator.png", Text = "Delete" }; leftSwipeItem.Invoked += (sender, e) => { DisplayAlert("SwipeView", "Delete Invoked", "Ok"); }; var rightSwipeItem = new SwipeItem { BackgroundColor = Color.LightGoldenrodYellow, IconImageSource = "calculator.png", Text = "Edit" }; rightSwipeItem.Invoked += (sender, e) => { DisplayAlert("SwipeView", "Edit Invoked", "Ok"); }; var leftSwipeItems = new SwipeItems { leftSwipeItem }; leftSwipeItems.Mode = SwipeMode.Reveal; var rightSwipeItems = new SwipeItems { leftSwipeItem, rightSwipeItem }; rightSwipeItems.Mode = SwipeMode.Reveal; var swipeContent = new Grid { BackgroundColor = Color.Gray }; var swipeLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Swipe to Left or Right" }; swipeContent.Children.Add(swipeLabel); var swipeView = new SwipeView { HeightRequest = 60, WidthRequest = 300, LeftItems = leftSwipeItems, RightItems = rightSwipeItems, Content = swipeContent }; layout.Children.Add(instructions); layout.Children.Add(swipeView); Content = layout; }
private void UpdateSwipeControlItems() { var swipeControl = _swipeControl as SwipeControl; if (swipeControl == null) { return; } if (IsLeftCommandEnabled) { var leftItem = _leftSwipeItem as SwipeItem; var leftItems = _leftSwipeItems as SwipeItems; if (leftItem == null) { leftItem = new SwipeItem(); leftItem.IconSource = new SymbolIconSource(); leftItem.Invoked += LeftControl_Invoked; leftItems = new SwipeItems() { leftItem }; leftItems.Mode = SwipeMode.Execute; _leftSwipeItems = leftItems; _leftSwipeItem = leftItem; } leftItem.BehaviorOnInvoked = SwipeBehaviorOnInvoked.Close; leftItem.Background = LeftBackground; leftItem.Text = LeftLabel; leftItem.Foreground = LeftForeground; leftItem.Command = LeftCommand; leftItem.CommandParameter = LeftCommandParameter; leftItem.IconSource.Foreground = LeftForeground; ((SymbolIconSource)leftItem.IconSource).Symbol = LeftIcon; swipeControl.LeftItems = leftItems; } else { swipeControl.LeftItems = null; } if (IsRightCommandEnabled) { var rightItem = _rightSwipeItem as SwipeItem; var rightItems = _rightSwipeItems as SwipeItems; if (rightItem == null) { rightItem = new SwipeItem(); rightItem.IconSource = new SymbolIconSource(); rightItem.Invoked += RightControl_Invoked; rightItems = new SwipeItems() { rightItem }; rightItems.Mode = SwipeMode.Execute; _rightSwipeItems = rightItems; _rightSwipeItem = rightItem; } rightItem.BehaviorOnInvoked = SwipeBehaviorOnInvoked.Close; rightItem.Background = RightBackground; rightItem.Text = RightLabel; rightItem.Foreground = RightForeground; rightItem.Command = RightCommand; rightItem.CommandParameter = RightCommandParameter; rightItem.IconSource.Foreground = RightForeground; ((SymbolIconSource)rightItem.IconSource).Symbol = RightIcon; swipeControl.RightItems = rightItems; } else { swipeControl.RightItems = null; } }
public SwipeViewEventsGallery() { Title = "SwipeView Events Gallery"; var swipeLayout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star } }, Margin = new Thickness(12) }; 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.Execute; 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 scroll = new ScrollView(); var eventsInfo = new Label(); scroll.Content = eventsInfo; var swipeView = new SwipeView { HeightRequest = 60, WidthRequest = 300, LeftItems = leftSwipeItems, Content = swipeContent }; swipeLayout.Children.Add(swipeView, 0, 0); swipeLayout.Children.Add(scroll, 0, 1); Content = swipeLayout; 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; }; }
WSwipeItems CreateSwipeItems(SwipeDirection swipeDirection) { var swipeItems = new WSwipeItems(); SwipeItems items = null; switch (swipeDirection) { case SwipeDirection.Left: DisposeSwipeItems(_leftItems); items = Element.LeftItems; _leftItems = new Dictionary <WSwipeItem, SwipeItem>(); break; case SwipeDirection.Right: DisposeSwipeItems(_rightItems); items = Element.RightItems; _rightItems = new Dictionary <WSwipeItem, SwipeItem>(); break; case SwipeDirection.Up: DisposeSwipeItems(_topItems); items = Element.TopItems; _topItems = new Dictionary <WSwipeItem, SwipeItem>(); break; case SwipeDirection.Down: DisposeSwipeItems(_bottomItems); items = Element.BottomItems; _bottomItems = new Dictionary <WSwipeItem, SwipeItem>(); break; } items.PropertyChanged += OnSwipeItemsPropertyChanged; swipeItems.Mode = GetSwipeMode(items.Mode); foreach (var item in items) { if (item is SwipeItem formsSwipeItem) { var textColor = GetSwipeItemColor(formsSwipeItem.BackgroundColor); var windowsSwipeItem = new WSwipeItem { Background = formsSwipeItem.BackgroundColor.IsDefault() ? null : formsSwipeItem.BackgroundColor.ToPlatform(), Foreground = textColor.ToPlatform(), IconSource = formsSwipeItem.IconImageSource.ToWindowsIconSource(), Text = !string.IsNullOrEmpty(formsSwipeItem.Text) ? formsSwipeItem.Text : string.Empty, BehaviorOnInvoked = GetSwipeBehaviorOnInvoked(items.SwipeBehaviorOnInvoked) }; formsSwipeItem.PropertyChanged += OnSwipeItemPropertyChanged; windowsSwipeItem.Invoked += OnSwipeItemInvoked; swipeItems.Add(windowsSwipeItem); FillSwipeItemsCache(swipeDirection, windowsSwipeItem, formsSwipeItem); } } return(swipeItems); }
void UpdateItems() { CurrentItems = GetSwipedItems(); var itemsLayout = new StackLayout { Spacing = 0, Orientation = IsHorizontalSwipe ? StackOrientation.Horizontal : StackOrientation.Vertical, FlowDirection = SwipeDirection == SwipeDirection.Left ? FlowDirection.RightToLeft : FlowDirection.LeftToRight }; foreach (var item in CurrentItems) { View itemView = null; if (item is SwipeItem switem) { itemView = CreateItemView(switem, !IsHorizontalSwipe); } else if (item is SwipeItemView customItem) { itemView = CreateItemView(customItem); } else { continue; } var tap = new TapGestureRecognizer(); tap.Command = item.Command; tap.CommandParameter = item.CommandParameter; tap.Tapped += (s, e) => { if (item is SwipeItem swipeItem) { swipeItem.OnInvoked(); } if (item is SwipeItemView customSwipeItem) { customSwipeItem.OnInvoked(); } if (CurrentItems.SwipeBehaviorOnInvoked != SwipeBehaviorOnInvoked.RemainOpen) { Device.BeginInvokeOnMainThread(() => { _ = SwipeCloseAsync(); }); } }; itemView.GestureRecognizers.Add(tap); if (IsHorizontalSwipe) { itemView.HorizontalOptions = LayoutOptions.Start; itemView.VerticalOptions = LayoutOptions.FillAndExpand; } else { itemView.VerticalOptions = LayoutOptions.Start; itemView.HorizontalOptions = LayoutOptions.FillAndExpand; } itemsLayout.Children.Add(itemView); } var itemsRenderer = Platform.GetOrCreateRenderer(itemsLayout); (itemsRenderer as LayoutRenderer)?.RegisterOnLayoutUpdated(); var measured = itemsLayout.Measure(Element.Width, Element.Height); MaximumSwipeSize = Forms.ConvertToScaledPixel( IsHorizontalSwipe ? Math.Min(measured.Request.Width, Element.Width) : Math.Min(measured.Request.Height, Element.Height)); Control.Children.Add(itemsRenderer.NativeView); var itemsGeometry = NativeView.Geometry; if (SwipeDirection == SwipeDirection.Up) { itemsGeometry.Y += (itemsGeometry.Height - MaximumSwipeSize); } itemsRenderer.NativeView.Geometry = itemsGeometry; itemsRenderer.NativeView.StackBelow(Platform.GetRenderer(SwipeView.Content).NativeView); _itemsRenderer = itemsRenderer; }
public SwipeTransitionModeGallery() { Title = "SwipeTransitionMode Gallery"; var scroll = new Microsoft.Maui.Controls.ScrollView(); var swipeLayout = new StackLayout { Margin = new Thickness(12) }; var instructions = new Label { BackgroundColor = Colors.Black, TextColor = Colors.White, Text = "This Gallery use a Platform Specific only available for Android and iOS." }; swipeLayout.Add(instructions); var swipeItemSwipeTransitionModeLabel = new Label { FontSize = 10, Text = "SwipeTransitionMode:" }; swipeLayout.Add(swipeItemSwipeTransitionModeLabel); var swipeItemSwipeTransitionModePicker = new Microsoft.Maui.Controls.Picker(); var swipeTransitionModes = Enum.GetNames(typeof(SwipeTransitionMode)).Select(t => t).ToList(); swipeItemSwipeTransitionModePicker.ItemsSource = swipeTransitionModes; swipeItemSwipeTransitionModePicker.SelectedIndex = 0; // Reveal swipeLayout.Add(swipeItemSwipeTransitionModePicker); var deleteSwipeItem = new SwipeItem { BackgroundColor = Colors.Red, IconImageSource = "calculator.png", Text = "Delete" }; deleteSwipeItem.Invoked += (sender, e) => { DisplayAlert("SwipeView", "Delete Invoked", "Ok"); }; var swipeItems = new SwipeItems { deleteSwipeItem }; swipeItems.Mode = SwipeMode.Reveal; var leftSwipeContent = new Grid { BackgroundColor = Colors.Gray }; var leftSwipeLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Swipe to Right" }; leftSwipeContent.Add(leftSwipeLabel); var leftSwipeView = new Microsoft.Maui.Controls.SwipeView { HeightRequest = 60, WidthRequest = 300, LeftItems = swipeItems, Content = leftSwipeContent }; swipeLayout.Add(leftSwipeView); var rightSwipeContent = new Grid { BackgroundColor = Colors.Gray }; var rightSwipeLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Swipe to Left" }; rightSwipeContent.Add(rightSwipeLabel); var rightSwipeView = new Microsoft.Maui.Controls.SwipeView { HeightRequest = 60, WidthRequest = 300, RightItems = swipeItems, Content = rightSwipeContent }; swipeLayout.Children.Add(rightSwipeView); var topSwipeContent = new Grid { BackgroundColor = Colors.Gray }; var topSwipeLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Swipe to Top" }; topSwipeContent.Add(topSwipeLabel); var topSwipeView = new Microsoft.Maui.Controls.SwipeView { HeightRequest = 60, WidthRequest = 300, BottomItems = swipeItems, Content = topSwipeContent }; swipeLayout.Add(topSwipeView); var bottomSwipeContent = new Grid { BackgroundColor = Colors.Gray }; var bottomSwipeLabel = new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Swipe to Bottom" }; bottomSwipeContent.Add(bottomSwipeLabel); var bottomSwipeView = new Microsoft.Maui.Controls.SwipeView { HeightRequest = 60, WidthRequest = 300, TopItems = swipeItems, Content = bottomSwipeContent }; swipeLayout.Add(bottomSwipeView); swipeItemSwipeTransitionModePicker.SelectedIndexChanged += (sender, e) => { var swipeTransitionMode = swipeItemSwipeTransitionModePicker.SelectedItem; switch (swipeTransitionMode) { case "Drag": leftSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetSwipeTransitionMode(SwipeTransitionMode.Drag); leftSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.iOS>().SetSwipeTransitionMode(SwipeTransitionMode.Drag); rightSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetSwipeTransitionMode(SwipeTransitionMode.Drag); rightSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.iOS>().SetSwipeTransitionMode(SwipeTransitionMode.Drag); topSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetSwipeTransitionMode(SwipeTransitionMode.Drag); topSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.iOS>().SetSwipeTransitionMode(SwipeTransitionMode.Drag); bottomSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetSwipeTransitionMode(SwipeTransitionMode.Drag); bottomSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.iOS>().SetSwipeTransitionMode(SwipeTransitionMode.Drag); break; case "Reveal": leftSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetSwipeTransitionMode(SwipeTransitionMode.Reveal); leftSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.iOS>().SetSwipeTransitionMode(SwipeTransitionMode.Reveal); rightSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetSwipeTransitionMode(SwipeTransitionMode.Drag); rightSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.iOS>().SetSwipeTransitionMode(SwipeTransitionMode.Drag); topSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetSwipeTransitionMode(SwipeTransitionMode.Drag); topSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.iOS>().SetSwipeTransitionMode(SwipeTransitionMode.Drag); bottomSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetSwipeTransitionMode(SwipeTransitionMode.Drag); bottomSwipeView.On <Microsoft.Maui.Controls.PlatformConfiguration.iOS>().SetSwipeTransitionMode(SwipeTransitionMode.Drag); break; } }; scroll.Content = swipeLayout; Content = scroll; }
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 = Colors.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 = Colors.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(); }; }