Skip to content

Commit

Permalink
Add properties for SwipeLeftCommand, SwipeRightCommand, SwipeToChange…
Browse files Browse the repository at this point in the history
…MonthEnabled, rename SwipeUpActionEnabled (#14)
  • Loading branch information
Josip Ćaleta committed Jul 18, 2019
1 parent 70df314 commit 0a76412
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 12 deletions.
9 changes: 7 additions & 2 deletions src/Calendar.Plugin.Sample/SampleApp/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@
<!-- Swipe handling
DisableSwipeDetection="False"
SwipeUpActionEnabled="False"
SwipeUpCommand="{Binding SwipeUpCommand}"-->
SwipeLeftCommand="{Binding SwipeLeftCommand}"
SwipeRightCommand="{Binding SwipeRightCommand}"
SwipeUpCommand="{Binding SwipeUpCommand}"
SwipeUpToHideEnabled="False"
SwipeToChangeMonthEnabled="False"-->

<!-- Customizations
Expand Down
63 changes: 53 additions & 10 deletions src/Calendar.Plugin/Shared/Controls/Calendar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public Style DaysTitleLabelStyle
/// <summary>
/// <para> Disables the swipe detection (needs testing on iOS) </para>
/// Could be useful if your superview has its own swipe-detection logic.
/// Also see if <seealso cref="SwipeUpCommand"/>, <seealso cref="SwipeUpActionEnabled"/> is useful to you.
/// Also see if <seealso cref="SwipeUpCommand"/>, <seealso cref="SwipeUpToHideEnabled"/>, <seealso cref="SwipeLeftCommand"/>, <seealso cref="SwipeRightCommand"/> or <seealso cref="SwipeToChangeMonthEnabled"/> is useful to you.
/// </summary>
public bool DisableSwipeDetection
{
Expand All @@ -338,15 +338,48 @@ public ICommand SwipeUpCommand
set => SetValue(SwipeUpCommandProperty, value);
}

/// <summary> Bindable property for SwipeUpActionEnabled </summary>
public static readonly BindableProperty SwipeUpActionEnabledProperty =
BindableProperty.Create(nameof(SwipeUpActionEnabled), typeof(bool), typeof(Calendar), true);
/// <summary> Bindable property for SwipeUpToHideEnabled </summary>
public static readonly BindableProperty SwipeUpToHideEnabledProperty =
BindableProperty.Create(nameof(SwipeUpToHideEnabled), typeof(bool), typeof(Calendar), true);

/// <summary> Enable/disable default swipe-up action for showing/hiding calendar </summary>
public bool SwipeUpActionEnabled
public bool SwipeUpToHideEnabled
{
get => (bool)GetValue(SwipeUpActionEnabledProperty);
set => SetValue(SwipeUpActionEnabledProperty, value);
get => (bool)GetValue(SwipeUpToHideEnabledProperty);
set => SetValue(SwipeUpToHideEnabledProperty, value);
}

/// <summary> Bindable property for SwipeLeftCommand </summary>
public static readonly BindableProperty SwipeLeftCommandProperty =
BindableProperty.Create(nameof(SwipeLeftCommand), typeof(ICommand), typeof(Calendar), null);

/// <summary> Activated when user swipes-left over days view </summary>
public ICommand SwipeLeftCommand
{
get => (ICommand)GetValue(SwipeLeftCommandProperty);
set => SetValue(SwipeLeftCommandProperty, value);
}

/// <summary> Bindable property for SwipeRightCommand </summary>
public static readonly BindableProperty SwipeRightCommandProperty =
BindableProperty.Create(nameof(SwipeRightCommand), typeof(ICommand), typeof(Calendar), null);

/// <summary> Activated when user swipes-right over days view </summary>
public ICommand SwipeRightCommand
{
get => (ICommand)GetValue(SwipeRightCommandProperty);
set => SetValue(SwipeRightCommandProperty, value);
}

/// <summary> Bindable property for SwipeToChangeMonthEnabled </summary>
public static readonly BindableProperty SwipeToChangeMonthEnabledProperty =
BindableProperty.Create(nameof(SwipeToChangeMonthEnabled), typeof(bool), typeof(Calendar), true);

/// <summary> Enable/disable default swipe actions for changing months </summary>
public bool SwipeToChangeMonthEnabled
{
get => (bool)GetValue(SwipeToChangeMonthEnabledProperty);
set => SetValue(SwipeToChangeMonthEnabledProperty, value);
}

#endregion
Expand Down Expand Up @@ -498,16 +531,26 @@ private void OnCalendarContainerSizeChanged(object sender, EventArgs e)
}

private void OnSwipedRight(object sender, EventArgs e)
=> PrevMonth();
{
SwipeRightCommand?.Execute(null);

if (SwipeToChangeMonthEnabled)
PrevMonth();
}

private void OnSwipedLeft(object sender, EventArgs e)
=> NextMonth();
{
SwipeLeftCommand?.Execute(null);

if (SwipeToChangeMonthEnabled)
NextMonth();
}

private void OnSwipedUp(object sender, EventArgs e)
{
SwipeUpCommand?.Execute(null);

if (SwipeUpActionEnabled)
if (SwipeUpToHideEnabled)
ToggleCalendarSectionVisibility();
}

Expand Down

0 comments on commit 0a76412

Please sign in to comment.