2019-11-23 03:47:01 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
2019-12-06 22:00:35 +03:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2019-11-23 03:47:01 +03:00
|
|
|
|
using Xamarin.Forms.Platform;
|
|
|
|
|
|
|
|
|
|
namespace Xamarin.Forms
|
|
|
|
|
{
|
|
|
|
|
[ContentProperty("Content")]
|
|
|
|
|
[RenderWith(typeof(_SwipeViewRenderer))]
|
|
|
|
|
public class SwipeView : ContentView, IElementConfiguration<SwipeView>, ISwipeViewController
|
|
|
|
|
{
|
|
|
|
|
readonly Lazy<PlatformConfigurationRegistry<SwipeView>> _platformConfigurationRegistry;
|
|
|
|
|
|
|
|
|
|
public SwipeView()
|
|
|
|
|
{
|
|
|
|
|
_platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<SwipeView>>(() => new PlatformConfigurationRegistry<SwipeView>(this));
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-06 22:00:35 +03:00
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
|
|
|
public static void VerifySwipeViewFlagEnabled(
|
|
|
|
|
string constructorHint = null,
|
|
|
|
|
[CallerMemberName] string memberName = "")
|
|
|
|
|
{
|
|
|
|
|
ExperimentalFlags.VerifyFlagEnabled(nameof(SwipeView), ExperimentalFlags.SwipeViewExperimental, memberName: memberName);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-04 18:57:54 +03:00
|
|
|
|
public static readonly BindableProperty LeftItemsProperty =
|
|
|
|
|
BindableProperty.Create(nameof(LeftItems), typeof(SwipeItems), typeof(SwipeView), null, BindingMode.OneWay, null, defaultValueCreator: SwipeItemsDefaultValueCreator,
|
|
|
|
|
propertyChanged: OnSwipeItemsChanged);
|
|
|
|
|
|
|
|
|
|
public static readonly BindableProperty RightItemsProperty =
|
2020-03-17 02:20:07 +03:00
|
|
|
|
BindableProperty.Create(nameof(RightItems), typeof(SwipeItems), typeof(SwipeView), null, BindingMode.OneWay, null, defaultValueCreator: SwipeItemsDefaultValueCreator,
|
|
|
|
|
propertyChanged: OnSwipeItemsChanged);
|
2020-03-04 18:57:54 +03:00
|
|
|
|
|
|
|
|
|
public static readonly BindableProperty TopItemsProperty =
|
2020-03-17 02:20:07 +03:00
|
|
|
|
BindableProperty.Create(nameof(TopItems), typeof(SwipeItems), typeof(SwipeView), null, BindingMode.OneWay, null, defaultValueCreator: SwipeItemsDefaultValueCreator,
|
|
|
|
|
propertyChanged: OnSwipeItemsChanged);
|
2020-03-04 18:57:54 +03:00
|
|
|
|
|
|
|
|
|
public static readonly BindableProperty BottomItemsProperty =
|
2020-03-17 02:20:07 +03:00
|
|
|
|
BindableProperty.Create(nameof(BottomItems), typeof(SwipeItems), typeof(SwipeView), null, BindingMode.OneWay, null, defaultValueCreator: SwipeItemsDefaultValueCreator,
|
|
|
|
|
propertyChanged: OnSwipeItemsChanged);
|
2019-11-23 03:47:01 +03:00
|
|
|
|
|
|
|
|
|
public SwipeItems LeftItems
|
|
|
|
|
{
|
|
|
|
|
get { return (SwipeItems)GetValue(LeftItemsProperty); }
|
|
|
|
|
set { SetValue(LeftItemsProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SwipeItems RightItems
|
|
|
|
|
{
|
|
|
|
|
get { return (SwipeItems)GetValue(RightItemsProperty); }
|
|
|
|
|
set { SetValue(RightItemsProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SwipeItems TopItems
|
|
|
|
|
{
|
|
|
|
|
get { return (SwipeItems)GetValue(TopItemsProperty); }
|
|
|
|
|
set { SetValue(TopItemsProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SwipeItems BottomItems
|
|
|
|
|
{
|
|
|
|
|
get { return (SwipeItems)GetValue(BottomItemsProperty); }
|
|
|
|
|
set { SetValue(BottomItemsProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-28 00:24:42 +03:00
|
|
|
|
bool ISwipeViewController.IsOpen { get; set; }
|
|
|
|
|
|
2020-03-04 18:57:54 +03:00
|
|
|
|
static void OnSwipeItemsChanged(BindableObject bindable, object oldValue, object newValue)
|
|
|
|
|
{
|
|
|
|
|
((SwipeView)bindable).UpdateSwipeItemsParent((SwipeItems)newValue);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-23 03:47:01 +03:00
|
|
|
|
public event EventHandler<SwipeStartedEventArgs> SwipeStarted;
|
|
|
|
|
public event EventHandler<SwipeChangingEventArgs> SwipeChanging;
|
|
|
|
|
public event EventHandler<SwipeEndedEventArgs> SwipeEnded;
|
2020-03-18 10:19:13 +03:00
|
|
|
|
|
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
|
|
|
public event EventHandler<OpenSwipeEventArgs> OpenRequested;
|
|
|
|
|
|
2019-11-23 03:47:01 +03:00
|
|
|
|
public event EventHandler CloseRequested;
|
|
|
|
|
|
2020-03-18 10:19:13 +03:00
|
|
|
|
public void Open(OpenSwipeItem openSwipeItem)
|
|
|
|
|
{
|
|
|
|
|
OpenRequested?.Invoke(this, new OpenSwipeEventArgs(openSwipeItem));
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-23 03:47:01 +03:00
|
|
|
|
public void Close()
|
|
|
|
|
{
|
|
|
|
|
CloseRequested?.Invoke(this, EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ISwipeViewController.SendSwipeStarted(SwipeStartedEventArgs args) => SwipeStarted?.Invoke(this, args);
|
|
|
|
|
|
|
|
|
|
void ISwipeViewController.SendSwipeChanging(SwipeChangingEventArgs args) => SwipeChanging?.Invoke(this, args);
|
|
|
|
|
|
|
|
|
|
void ISwipeViewController.SendSwipeEnded(SwipeEndedEventArgs args) => SwipeEnded?.Invoke(this, args);
|
|
|
|
|
|
|
|
|
|
protected override void OnBindingContextChanged()
|
|
|
|
|
{
|
|
|
|
|
base.OnBindingContextChanged();
|
|
|
|
|
|
|
|
|
|
object bc = BindingContext;
|
|
|
|
|
|
|
|
|
|
if (LeftItems != null)
|
|
|
|
|
SetInheritedBindingContext(LeftItems, bc);
|
|
|
|
|
|
|
|
|
|
if (RightItems != null)
|
|
|
|
|
SetInheritedBindingContext(RightItems, bc);
|
|
|
|
|
|
|
|
|
|
if (TopItems != null)
|
|
|
|
|
SetInheritedBindingContext(TopItems, bc);
|
|
|
|
|
|
|
|
|
|
if (BottomItems != null)
|
|
|
|
|
SetInheritedBindingContext(BottomItems, bc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SwipeItems SwipeItemsDefaultValueCreator() => new SwipeItems();
|
|
|
|
|
|
|
|
|
|
static object SwipeItemsDefaultValueCreator(BindableObject bindable)
|
|
|
|
|
{
|
|
|
|
|
return ((SwipeView)bindable).SwipeItemsDefaultValueCreator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IPlatformElementConfiguration<T, SwipeView> On<T>() where T : IConfigPlatform
|
|
|
|
|
{
|
|
|
|
|
return _platformConfigurationRegistry.Value.On<T>();
|
|
|
|
|
}
|
2020-03-04 18:57:54 +03:00
|
|
|
|
|
|
|
|
|
void UpdateSwipeItemsParent(SwipeItems swipeItems)
|
|
|
|
|
{
|
2020-06-16 18:35:13 +03:00
|
|
|
|
if (swipeItems.Parent == null)
|
|
|
|
|
swipeItems.Parent = this;
|
2020-03-04 18:57:54 +03:00
|
|
|
|
|
2020-06-16 18:35:13 +03:00
|
|
|
|
foreach (var item in swipeItems)
|
|
|
|
|
if (item is Element swipeItem && swipeItem.Parent == null)
|
|
|
|
|
swipeItem.Parent = swipeItems;
|
2020-03-04 18:57:54 +03:00
|
|
|
|
}
|
2019-11-23 03:47:01 +03:00
|
|
|
|
}
|
|
|
|
|
}
|