internal void UpdateContent(ISwipeView swipeView, IMauiContext mauiContext) { ClipsToBounds = true; _contentView?.RemoveFromSuperview(); if (swipeView?.PresentedContent is IView view) { if (Subviews.Length > 0) { _contentView = Subviews[0]; } _contentView = view.ToPlatform(mauiContext); } else { _contentView = CreateEmptyContent(); } AddSubview(_contentView); if (_contentView != null) { BringSubviewToFront(_contentView); } }
internal static ISwipeItems?GetSwipeItemsByDirection(this ISwipeView swipeView, SwipeDirection?swipeDirection) { ISwipeItems?swipeItems = null; switch (swipeDirection) { case SwipeDirection.Left: swipeItems = swipeView.RightItems; break; case SwipeDirection.Right: swipeItems = swipeView.LeftItems; break; case SwipeDirection.Up: swipeItems = swipeView.BottomItems; break; case SwipeDirection.Down: swipeItems = swipeView.TopItems; break; } return(swipeItems); }
internal static double GetSwipeItemHeight(this ISwipeView swipeView, SwipeDirection?swipeDirection, UIView contentView) { var items = GetSwipeItemsByDirection(swipeView, swipeDirection); if (items != null) { foreach (var item in items) { if (item is ISwipeItemView) { var itemsHeight = new List <double>(); double itemHeight = 0; foreach (var swipeItem in items) { if (swipeItem is ISwipeItemView swipeItemView) { var swipeItemViewSizeRequest = swipeItemView.Measure(double.PositiveInfinity, double.PositiveInfinity); if (swipeItemViewSizeRequest.Height > itemHeight) { itemHeight = swipeItemViewSizeRequest.Height; } } } return(itemHeight); } } } return(contentView.Frame.Height); }
internal void UpdateIsSwipeEnabled(ISwipeView swipeView) { UserInteractionEnabled = true; _isSwipeEnabled = swipeView.IsEnabled; if (swipeView?.PresentedContent is IView view) { var isContentEnabled = view.IsEnabled; _contentView.UserInteractionEnabled = isContentEnabled; } }
internal static Size GetSwipeItemSize(this ISwipeView swipeView, ISwipeItem swipeItem, UIView contentView, SwipeDirection?swipeDirection) { var items = GetSwipeItemsByDirection(swipeView, swipeDirection); double threshold = swipeView.Threshold; if (items == null) { return(Size.Zero); } var contentHeight = contentView.Frame.Height; var contentWidth = contentView.Frame.Width; if (swipeDirection.IsHorizontalSwipe()) { if (swipeItem is ISwipeItemMenuItem) { return(new Size(items.Mode == SwipeMode.Execute ? (threshold > 0 ? threshold : contentWidth) / items.Count : (threshold < SwipeItemWidth ? SwipeItemWidth : threshold), contentHeight)); } if (swipeItem is ISwipeItemView horizontalSwipeItemView) { var swipeItemViewSizeRequest = horizontalSwipeItemView.Measure(double.PositiveInfinity, double.PositiveInfinity); double swipeItemWidth; if (swipeItemViewSizeRequest.Width > 0) { swipeItemWidth = threshold > swipeItemViewSizeRequest.Width ? threshold : swipeItemViewSizeRequest.Width; } else { swipeItemWidth = threshold > SwipeItemWidth ? threshold : SwipeItemWidth; } return(new Size(swipeItemWidth, contentHeight)); } } else { if (swipeItem is ISwipeItemMenuItem) { var swipeItemHeight = GetSwipeItemHeight(swipeView, swipeDirection, contentView); return(new Size(contentWidth / items.Count, (threshold > 0 && threshold < swipeItemHeight) ? threshold : swipeItemHeight)); } if (swipeItem is ISwipeItemView verticalSwipeItemView) { var swipeItemViewSizeRequest = verticalSwipeItemView.Measure(double.PositiveInfinity, double.PositiveInfinity); double swipeItemHeight; if (swipeItemViewSizeRequest.Width > 0) { swipeItemHeight = threshold > swipeItemViewSizeRequest.Height ? threshold : (float)swipeItemViewSizeRequest.Height; } else { swipeItemHeight = threshold > contentHeight ? threshold : contentHeight; } return(new Size(contentWidth / items.Count, swipeItemHeight)); } } return(Size.Zero); }
// temporary workaround to make it work internal void SetElement(ISwipeView swipeView) { Element = swipeView; }