Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow card pages to animate in from any edge #46

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
93 changes: 77 additions & 16 deletions NControl.Controls/NControl.Controls/CardPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ public enum CardPosition
Center
}

public enum EdgePosition
{
Left,
Right,
Top,
Bottom
}

/// <summary>
/// Card page. Based on custom transitions
/// </summary>
Expand Down Expand Up @@ -103,12 +111,6 @@ public CardPage()

_layout.Children.Add(_contentView, () => this.LayerPosition);

if (_platformHelper.ControlAnimatesItself)
{
_shadowLayer.TranslationY = _platformHelper.GetScreenSize().Height - (CardPadding.Top);
_contentView.TranslationY = _platformHelper.GetScreenSize().Height - (CardPadding.Top);
}

// Add tap
_overlay.GestureRecognizers.Add(new TapGestureRecognizer
{
Expand Down Expand Up @@ -251,6 +253,51 @@ public CardPosition Position
}
}

private EdgePosition _edge = EdgePosition.Bottom;
public EdgePosition Edge
{
get { return _edge; }
set
{
if (_edge == value) return;
_edge = value;

if (_platformHelper.ControlAnimatesItself)
{
switch (Edge)
{
case EdgePosition.Top:
_shadowLayer.TranslationX = 0;
_contentView.TranslationX = 0;
_shadowLayer.TranslationY = 0 - _platformHelper.GetScreenSize().Height + (CardPadding.Bottom);
_contentView.TranslationY = 0 - _platformHelper.GetScreenSize().Height + (CardPadding.Bottom);
break;
case EdgePosition.Bottom:
_shadowLayer.TranslationX = 0;
_contentView.TranslationX = 0;
_shadowLayer.TranslationY = _platformHelper.GetScreenSize().Height - (CardPadding.Top);
_contentView.TranslationY = _platformHelper.GetScreenSize().Height - (CardPadding.Top);
break;
case EdgePosition.Left:
_shadowLayer.TranslationX = 0 - _platformHelper.GetScreenSize().Width + (CardPadding.Right);
_contentView.TranslationX = 0 - _platformHelper.GetScreenSize().Width + (CardPadding.Right);
_shadowLayer.TranslationY = 0;
_contentView.TranslationY = 0;
break;
case EdgePosition.Right:
_shadowLayer.TranslationX = _platformHelper.GetScreenSize().Width - (CardPadding.Left);
_contentView.TranslationX = _platformHelper.GetScreenSize().Width - (CardPadding.Left);
_shadowLayer.TranslationY = 0;
_contentView.TranslationY = 0;
break;
default:
throw new ArgumentException(nameof(Edge));
}
}

}
}

private Thickness _cardPadding;
public Thickness CardPadding
{
Expand Down Expand Up @@ -292,18 +339,32 @@ public virtual Task ShowAsync()
public virtual async Task CloseAsync()
{
if (_platformHelper.ControlAnimatesItself) {
var tasks = new Task[3];
switch (Edge)
{
case EdgePosition.Top:
tasks[0] = _shadowLayer.TranslateTo(0.0, 0 - _platformHelper.GetScreenSize().Height + (CardPadding.Bottom), 250, Easing.CubicInOut);
tasks[1] = _contentView.TranslateTo(0.0, 0 - _platformHelper.GetScreenSize().Height + (CardPadding.Bottom), 250, Easing.CubicInOut);
break;
case EdgePosition.Bottom:
tasks[0] = _shadowLayer.TranslateTo(0.0, _platformHelper.GetScreenSize().Height - (CardPadding.Top), 250, Easing.CubicInOut);
tasks[1] = _contentView.TranslateTo(0.0, _platformHelper.GetScreenSize().Height - (CardPadding.Top), 250, Easing.CubicInOut);
break;
case EdgePosition.Left:
tasks[0] = _shadowLayer.TranslateTo(0 - _platformHelper.GetScreenSize().Width + (CardPadding.Right), 0.0, 250, Easing.CubicInOut);
tasks[1] = _contentView.TranslateTo(0 - _platformHelper.GetScreenSize().Width + (CardPadding.Right), 0.0, 250, Easing.CubicInOut);
break;
case EdgePosition.Right:
tasks[0] = _shadowLayer.TranslateTo(_platformHelper.GetScreenSize().Width - (CardPadding.Left), 0.0, 250, Easing.CubicInOut);
tasks[1] = _contentView.TranslateTo(_platformHelper.GetScreenSize().Width - (CardPadding.Left), 0.0, 250, Easing.CubicInOut);
break;
default:
throw new ArgumentException(nameof(Edge));
}

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_shadowLayer.TranslateTo(0.0,

#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
_platformHelper.GetScreenSize().Height - (CardPadding.Top), 250, Easing.CubicInOut);

await _contentView.TranslateTo(0.0,
_platformHelper.GetScreenSize().Height - (CardPadding.Top), 250, Easing.CubicInOut);

await _overlay.FadeTo(0.0F, 150, Easing.CubicInOut);
tasks[2] = _overlay.FadeTo(0.0F, 150, Easing.CubicInOut);

await Task.WhenAll(tasks);
}

await _platformHelper.CloseAsync (this);
Expand Down