Skip to content

Commit

Permalink
Implement additional pages navigation for scroll component
Browse files Browse the repository at this point in the history
  • Loading branch information
Kostya Stankevych committed May 31, 2016
1 parent ee5ac7c commit ddd9948
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
39 changes: 38 additions & 1 deletion UserInterface/Elements/CarouselScroll/UICarouselScroll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 12,10 @@ public class UICarouselScroll
private float _dragDistance;
#endregion

#region Events
public event System.Action<int, int> UpdateNavigation;
#endregion

#region Init
public UICarouselScroll(UICarouselScrollSettings settings)
{
Expand Down Expand Up @@ -72,10 76,20 @@ public void EndDrag()

ShowPage(_page);
}

public void NextPage()
{
ShowPage(_page 1);
}

public void PreviousPage()
{
ShowPage(_page - 1);
}
#endregion

#region Helpers
private bool ShowPage(int page, bool tween = true)
public bool ShowPage(int page, bool tween = true)
{
bool result = true;

Expand All @@ -86,8 100,15 @@ private bool ShowPage(int page, bool tween = true)
}

if (result)
{
_page = page;

if (UpdateNavigation != null)
{
UpdateNavigation(_page, MaxPages);
}
}

return result;
}

Expand All @@ -97,5 118,21 @@ private float SwipeThreshold
get { return _settings.Layers[0].PageWidth * _settings.SwipeThreshold; }
}
#endregion

#region Getters
private int MaxPages
{
get
{
int pages = 0;
foreach (UICarouselScrollLayer layer in _settings.Layers)
{
if (layer.Pages > pages)
pages = layer.Pages;
}
return pages;
}
}
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 212,7 @@ private Transform Pivot
get { return _pivot; }
}

private int Pages
public int Pages
{
get { return _pages; }
}
Expand Down

0 comments on commit ddd9948

Please sign in to comment.