2 using System.ComponentModel;
3 using System.Runtime.CompilerServices;
4 using Xamarin.Forms.Platform;
6 namespace Xamarin.Forms
8 [ContentProperty("Content")]
9 [RenderWith(typeof(_SwipeViewRenderer))]
10 public class SwipeView : ContentView, IElementConfiguration<SwipeView>, ISwipeViewController
12 readonly Lazy<PlatformConfigurationRegistry<SwipeView>> _platformConfigurationRegistry;
16 _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<SwipeView>>(() => new PlatformConfigurationRegistry<SwipeView>(this));
19 [EditorBrowsable(EditorBrowsableState.Never)]
20 public static void VerifySwipeViewFlagEnabled(
21 string constructorHint = null,
22 [CallerMemberName] string memberName = "")
24 ExperimentalFlags.VerifyFlagEnabled(nameof(SwipeView), ExperimentalFlags.SwipeViewExperimental, memberName: memberName);
27 public static readonly BindableProperty LeftItemsProperty =
28 BindableProperty.Create(nameof(LeftItems), typeof(SwipeItems), typeof(SwipeView), null, BindingMode.OneWay, null, defaultValueCreator: SwipeItemsDefaultValueCreator,
29 propertyChanged: OnSwipeItemsChanged);
31 public static readonly BindableProperty RightItemsProperty =
32 BindableProperty.Create(nameof(RightItems), typeof(SwipeItems), typeof(SwipeView), null, BindingMode.OneWay, null, defaultValueCreator: SwipeItemsDefaultValueCreator);
34 public static readonly BindableProperty TopItemsProperty =
35 BindableProperty.Create(nameof(TopItems), typeof(SwipeItems), typeof(SwipeView), null, BindingMode.OneWay, null, defaultValueCreator: SwipeItemsDefaultValueCreator);
37 public static readonly BindableProperty BottomItemsProperty =
38 BindableProperty.Create(nameof(BottomItems), typeof(SwipeItems), typeof(SwipeView), null, BindingMode.OneWay, null, defaultValueCreator: SwipeItemsDefaultValueCreator);
40 public SwipeItems LeftItems
42 get { return (SwipeItems)GetValue(LeftItemsProperty); }
43 set { SetValue(LeftItemsProperty, value); }
46 public SwipeItems RightItems
48 get { return (SwipeItems)GetValue(RightItemsProperty); }
49 set { SetValue(RightItemsProperty, value); }
52 public SwipeItems TopItems
54 get { return (SwipeItems)GetValue(TopItemsProperty); }
55 set { SetValue(TopItemsProperty, value); }
58 public SwipeItems BottomItems
60 get { return (SwipeItems)GetValue(BottomItemsProperty); }
61 set { SetValue(BottomItemsProperty, value); }
64 static void OnSwipeItemsChanged(BindableObject bindable, object oldValue, object newValue)
66 ((SwipeView)bindable).UpdateSwipeItemsParent((SwipeItems)newValue);
69 public event EventHandler<SwipeStartedEventArgs> SwipeStarted;
70 public event EventHandler<SwipeChangingEventArgs> SwipeChanging;
71 public event EventHandler<SwipeEndedEventArgs> SwipeEnded;
72 public event EventHandler CloseRequested;
76 CloseRequested?.Invoke(this, EventArgs.Empty);
79 void ISwipeViewController.SendSwipeStarted(SwipeStartedEventArgs args) => SwipeStarted?.Invoke(this, args);
81 void ISwipeViewController.SendSwipeChanging(SwipeChangingEventArgs args) => SwipeChanging?.Invoke(this, args);
83 void ISwipeViewController.SendSwipeEnded(SwipeEndedEventArgs args) => SwipeEnded?.Invoke(this, args);
85 protected override void OnBindingContextChanged()
87 base.OnBindingContextChanged();
89 object bc = BindingContext;
91 if (LeftItems != null)
92 SetInheritedBindingContext(LeftItems, bc);
94 if (RightItems != null)
95 SetInheritedBindingContext(RightItems, bc);
98 SetInheritedBindingContext(TopItems, bc);
100 if (BottomItems != null)
101 SetInheritedBindingContext(BottomItems, bc);
104 SwipeItems SwipeItemsDefaultValueCreator() => new SwipeItems();
106 static object SwipeItemsDefaultValueCreator(BindableObject bindable)
108 return ((SwipeView)bindable).SwipeItemsDefaultValueCreator();
111 public IPlatformElementConfiguration<T, SwipeView> On<T>() where T : IConfigPlatform
113 return _platformConfigurationRegistry.Value.On<T>();
116 void UpdateSwipeItemsParent(SwipeItems swipeItems)
118 swipeItems.Parent = this;
120 foreach (var swipeItem in swipeItems)
121 ((VisualElement)swipeItem).Parent = swipeItems;