-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to swipe between views with setting context by user
No need to set Items Context
- Loading branch information
1 parent
5655b37
commit 511bc6e
Showing
6 changed files
with
240 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
PanCardViewSample/PanCardViewSample/ViewModels/SharedSampleCustomViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel; | ||
using Xamarin.Forms; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Windows.Input; | ||
using System.Linq; | ||
|
||
namespace PanCardViewSample.ViewModels | ||
{ | ||
public sealed class SharedSampleCustomViewModel : INotifyPropertyChanged | ||
{ | ||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
private int _ImageCount = 500; | ||
|
||
private Stack<object> _contextStack = new Stack<object>(); | ||
|
||
public SharedSampleCustomViewModel() | ||
{ | ||
PrevContext = CreateContext(); | ||
CurrentContext = CreateContext(); | ||
NextContext = CreateContext(); | ||
|
||
_contextStack.Push(PrevContext); | ||
|
||
PanStartedCommand = new Command(() => | ||
{ | ||
if (_contextStack.Any() && PrevContext == null) | ||
{ | ||
PrevContext = _contextStack.Peek(); | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PrevContext))); | ||
} | ||
if (NextContext == null) | ||
{ | ||
NextContext = new { Source = CreateSource(), Color = CreateColor() }; | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(NextContext))); | ||
} | ||
|
||
}); | ||
|
||
PanPositionChangedCommand = new Command((p) => | ||
{ | ||
var isNext = (bool)p; | ||
if(isNext) | ||
{ | ||
_contextStack.Push(CurrentContext); | ||
PrevContext = CurrentContext; | ||
CurrentContext = NextContext; | ||
NextContext = CreateContext(); | ||
} | ||
else | ||
{ | ||
NextContext = CurrentContext; | ||
CurrentContext = PrevContext; | ||
_contextStack.Pop(); | ||
PrevContext = _contextStack.Any() ? _contextStack.Peek() : null; | ||
} | ||
|
||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentContext))); | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(NextContext))); | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PrevContext))); | ||
}); | ||
} | ||
|
||
public object CurrentContext { get; set; } | ||
public object NextContext { get; set; } | ||
public object PrevContext { get; set; } | ||
|
||
public ICommand PanStartedCommand { get; } | ||
public ICommand PanPositionChangedCommand { get; } | ||
|
||
|
||
private object CreateContext() | ||
{ | ||
return new { Source = CreateSource(), Color = CreateColor() }; | ||
} | ||
|
||
private string CreateSource() | ||
{ | ||
return $"http://lorempixel.com/300/300/animals/text{++_ImageCount}/"; | ||
} | ||
|
||
private Color CreateColor() | ||
{ | ||
var rnd = new Random(); | ||
return Color.FromRgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
PanCardViewSample/PanCardViewSample/Views/CardsSampleCustomView.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using FFImageLoading.Forms; | ||
using PanCardView; | ||
using PanCardView.Factory; | ||
using Xamarin.Forms; | ||
using PanCardView.Processors; | ||
using PanCardViewSample.ViewModels; | ||
using PanCardViewSample.CardsFactory; | ||
|
||
namespace PanCardViewSample.Views | ||
{ | ||
public class CardsSampleCustomView : ContentPage | ||
{ | ||
public CardsSampleCustomView() | ||
{ | ||
var cardsView = new CardsView() | ||
{ | ||
ItemViewFactory = new CardViewItemFactory(RuleHolder.Rule), | ||
BackgroundColor = Color.Black.MultiplyAlpha(.9), | ||
IsPanInCourse = true | ||
}; | ||
|
||
cardsView.SetBinding(CardsView.CurrentContextProperty, nameof(SharedSampleCustomViewModel.CurrentContext)); | ||
cardsView.SetBinding(CardsView.NextContextProperty, nameof(SharedSampleCustomViewModel.NextContext)); | ||
cardsView.SetBinding(CardsView.PrevContextProperty, nameof(SharedSampleCustomViewModel.PrevContext)); | ||
|
||
cardsView.SetBinding(CardsView.PanStartedCommandProperty, nameof(SharedSampleCustomViewModel.PanStartedCommand)); | ||
cardsView.SetBinding(CardsView.PositionChangedCommandProperty, nameof(SharedSampleCustomViewModel.PanPositionChangedCommand)); | ||
|
||
Title = "CardsView"; | ||
Content = cardsView; | ||
BindingContext = new SharedSampleCustomViewModel(); | ||
} | ||
} | ||
} |