Skip to content

Commit

Permalink
Renamed and moved code
Browse files Browse the repository at this point in the history
  • Loading branch information
haavamoa committed Jan 23, 2020
1 parent a1f188e commit 0fed05f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 56 deletions.
107 changes: 59 additions & 48 deletions src/DIPS.Xamarin.UI/Controls/Sheet/SheetBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,60 +22,36 @@ public class SheetBehavior : Behavior<ModalityLayout>, IModalityHandler
private SheetView? m_sheetView;

/// <summary>
/// <see cref="OpenedCommand"/>
/// <see cref="OnOpenCommand"/>
/// </summary>
public static readonly BindableProperty OpenedCommandProperty = BindableProperty.Create(nameof(OpenedCommand), typeof(ICommand), typeof(SheetBehavior));

/// <summary>
/// Command that executes when the sheet has completed it's animation and is open
/// </summary>
public ICommand OpenedCommand
{
get => (ICommand)GetValue(OpenedCommandProperty);
set => SetValue(OpenedCommandProperty, value);
}

/// <summary>
/// <see cref="OpenedCommandProperty"/>
/// </summary>
public static readonly BindableProperty OpenedCommandParameterProperty = BindableProperty.Create(nameof(OpenedCommandParameter), typeof(object), typeof(SheetBehavior));

/// <summary>
/// The parameter to pass to the <see cref="OpenedCommand"/>
/// </summary>
public object OpenedCommandParameter
{
get => (object)GetValue(OpenedCommandParameterProperty);
set => SetValue(OpenedCommandParameterProperty, value);
}

/// <summary>
/// <see cref="ClosedCommand"/>
/// </summary>
public static readonly BindableProperty ClosedCommandProperty = BindableProperty.Create(nameof(ClosedCommand), typeof(ICommand), typeof(SheetBehavior));
public static readonly BindableProperty OnOpenCommandProperty = BindableProperty.Create(
nameof(OnOpenCommand),
typeof(ICommand),
typeof(SheetBehavior));

/// <summary>
/// Command that executes when the sheet has completed it's animation and is closed
/// <see cref="OnOpenCommandProperty"/>
/// </summary>
public ICommand ClosedCommand
{
get => (ICommand)GetValue(ClosedCommandProperty);
set => SetValue(ClosedCommandProperty, value);
}
public static readonly BindableProperty OnOpenCommandParameterProperty =
BindableProperty.Create(nameof(OnOpenCommandParameter),
typeof(object),
typeof(SheetBehavior));

/// <summary>
/// <see cref="ClosedCommandParameter"/>
/// <see cref="OnCloseCommand"/>
/// </summary>
public static readonly BindableProperty ClosedCommandParameterProperty = BindableProperty.Create(nameof(ClosedCommandParameter), typeof(object), typeof(SheetBehavior));
public static readonly BindableProperty OnCloseCommandProperty = BindableProperty.Create(
nameof(OnCloseCommand),
typeof(ICommand),
typeof(SheetBehavior));

/// <summary>
/// The parameter to pass to the <see cref="ClosedCommand"/>
/// <see cref="OnCloseCommandParameter"/>
/// </summary>
public object ClosedCommandParameter
{
get => (object)GetValue(ClosedCommandParameterProperty);
set => SetValue(ClosedCommandParameterProperty, value);
}
public static readonly BindableProperty OnCloseCommandParameterProperty = BindableProperty.Create(
nameof(OnCloseCommandParameter),
typeof(object),
typeof(SheetBehavior));

/// <summary>
/// <see cref="VerticalContentAlignment" />
Expand Down Expand Up @@ -262,6 +238,42 @@ public bool IsOpen
set => SetValue(IsOpenProperty, value);
}

/// <summary>
/// Command that executes when the sheet has completed it's animation and is open
/// </summary>
public ICommand OnOpenCommand
{
get => (ICommand)GetValue(OnOpenCommandProperty);
set => SetValue(OnOpenCommandProperty, value);
}

/// <summary>
/// The parameter to pass to the <see cref="OnOpenCommand"/>
/// </summary>
public object OnOpenCommandParameter
{
get => GetValue(OnOpenCommandParameterProperty);
set => SetValue(OnOpenCommandParameterProperty, value);
}

/// <summary>
/// Command that executes when the sheet has completed it's animation and is closed
/// </summary>
public ICommand OnCloseCommand
{
get => (ICommand)GetValue(OnCloseCommandProperty);
set => SetValue(OnCloseCommandProperty, value);
}

/// <summary>
/// The parameter to pass to the <see cref="OnCloseCommand"/>
/// </summary>
public object OnCloseCommandParameter
{
get => GetValue(OnCloseCommandParameterProperty);
set => SetValue(OnCloseCommandParameterProperty, value);
}

/// <summary>
/// Determines the maximum position of the sheet when it is visible.
/// This is a bindable property.
Expand Down Expand Up @@ -417,7 +429,7 @@ private async void ToggleSheetVisibility()
else //Set position from input
{
await TranslateBasedOnPosition(false);
OpenedCommand?.Execute(OpenedCommandParameter);
OnOpenCommand?.Execute(OnOpenCommandParameter);
}
}
else {
Expand All @@ -426,7 +438,7 @@ private async void ToggleSheetVisibility()
AlignmentOptions.Top => -m_modalityLayout.Height,
_ => throw new ArgumentOutOfRangeException()
};
m_modalityLayout.Hide(m_sheetView.SheetFrame, m_sheetView.SheetFrame.TranslateTo(m_sheetView.SheetFrame.X, y), () => ClosedCommand?.Execute(ClosedCommandParameter));
m_modalityLayout.Hide(m_sheetView.SheetFrame, m_sheetView.SheetFrame.TranslateTo(m_sheetView.SheetFrame.X, y), () => OnCloseCommand?.Execute(OnCloseCommandParameter));
}

m_fromIsOpenContext = false;
Expand Down Expand Up @@ -475,9 +487,8 @@ private async Task TranslateBasedOnPosition(bool shouldExecuteOpenedCommand = tr

if (shouldExecuteOpenedCommand)
{
OpenedCommand?.Execute(OpenedCommandParameter);
OnOpenCommand?.Execute(OnOpenCommandParameter);
}

}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<dxui:ModalityLayout>
<dxui:ModalityLayout.Behaviors>
<dxui:SheetBehavior IsOpen="{Binding IsSheetOpen}"
OpenedCommand="{Binding OpenedCommand}"
OpenedCommandParameter="Opened"
ClosedCommand="{Binding ClosedCommand}"
ClosedCommandParameter="Closed"
OnOpenCommand="{Binding OnOpenCommand}"
OnOpenCommandParameter="Opened"
OnCloseCommand="{Binding OnCloseCommand}"
OnCloseCommandParameter="Closed"
IsDraggable="{Binding IsDraggable}"
Alignment="{Binding Alignment}"
VerticalContentAlignment="{Binding VerticalContentAlignment}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class SheetPageViewModel : INotifyPropertyChanged
public SheetPageViewModel()
{
OpenSheetCommand = new Command(() => IsSheetOpen = true);
OpenedCommand = new Command<string>(SheetOpened);
ClosedCommand = new Command<string>(SheetClosed);
OnOpenCommand = new Command<string>(SheetOpened);
OnCloseCommand = new Command<string>(SheetClosed);
}

private void SheetClosed(string commandParameter)
Expand Down Expand Up @@ -141,9 +141,9 @@ public ContentAlignment VerticalContentAlignment

public ICommand OpenSheetCommand { get; }

public ICommand OpenedCommand { get; }
public ICommand OnOpenCommand { get; }

public ICommand ClosedCommand { get; }
public ICommand OnCloseCommand { get; }

public string StateText
{
Expand Down

0 comments on commit 0fed05f

Please sign in to comment.