Slide lock fully functional.
MODIFY
WalletWasabi.Gui/Controls/LockScreen/SlideLockScreen.xaml.cs
WalletWasabi.Gui/Controls/LockScreen/SlideLockScreen.xaml.cs
@@ -14,24 +14,38 @@ namespace WalletWasabi.Gui.Controls.LockScreen
{
public class SlideLockScreen : UserControl
{
- public static readonly DirectProperty<SlideLockScreen, CompositeDisposable> DisposablesProperty =
- AvaloniaProperty.RegisterDirect<SlideLockScreen, CompositeDisposable>(nameof(Disposables),
- o => o.Disposables,
- (o, v) => o.Disposables = v);
- private CompositeDisposable _disposables;
- public CompositeDisposable Disposables
+ public static readonly DirectProperty<SlideLockScreen, bool> IsLockedProperty =
+ AvaloniaProperty.RegisterDirect<SlideLockScreen, bool>(nameof(IsLocked),
+ o => o.IsLocked,
+ (o, v) => o.IsLocked = v);
+ private bool _isLocked;
+
+ public bool IsLocked
+ {
+ get => _isLocked;
+ set => this.SetAndRaise(IsLockedProperty, ref _isLocked, value);
+ }
+
+ public static readonly DirectProperty<SlideLockScreen, string> TokenProperty =
+ AvaloniaProperty.RegisterDirect<SlideLockScreen, string>(nameof(Token),
+ o => o.Token,
+ (o, v) => o.Token = v);
+ private string _token;
+
+ public string Token
{
- get => _disposables;
- set => this.SetAndRaise(DisposablesProperty, ref _disposables, value);
+ get => _token;
+ set => this.SetAndRaise(TokenProperty, ref _token, value);
}
- private Thumb DragThumb;
- private TranslateTransform TargetTransform;
- private bool UserDragInProgress, StopSpring;
+ public CompositeDisposable Disposables { get; } = new CompositeDisposable();
+ private TranslateTransform TargetTransform { get; } = new TranslateTransform();
+ private Thumb DragThumb { get; }
- private const double ThresholdPercent = 1 / 6d;
- private double RealThreshold;
- private const double Stiffness = 0.12d;
+ private bool _userDragInProgress;
+ private double _realThreshold;
+ private const double _thresholdPercent = 1 / 6d;
+ private const double _stiffness = 0.12d;
private double _offset = 0;
private double Offset
@@ -45,9 +59,41 @@ namespace WalletWasabi.Gui.Controls.LockScreen
InitializeComponent();
this.DragThumb = this.FindControl<Thumb>("PART_DragThumb");
-
- TargetTransform = new TranslateTransform();
- this.RenderTransform = TargetTransform;
+ this.FindControl<Grid>("Shade").RenderTransform = TargetTransform;
+
+ Observable.FromEventPattern<VectorEventArgs>(DragThumb, nameof(DragThumb.DragCompleted))
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(e => OnDragCompleted(e.EventArgs))
+ .DisposeWith(Disposables);
+
+ Observable.FromEventPattern<VectorEventArgs>(DragThumb, nameof(DragThumb.DragDelta))
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(e => OnDragDelta(e.EventArgs))
+ .DisposeWith(Disposables);
+
+ Observable.FromEventPattern(DragThumb, nameof(DragThumb.DragStarted))
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(e => OnDragStarted())
+ .DisposeWith(Disposables);
+
+ this.WhenAnyValue(x => x.Bounds)
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(OnBoundsChange)
+ .DisposeWith(Disposables);
+
+ Clock.Subscribe(OnClockTick)
+ .DisposeWith(Disposables);
+
+ this.WhenAnyValue(x=>x.IsLocked)
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Where(x=>x)
+ .Subscribe(x=>this.Offset = 0)
+ .DisposeWith(Disposables);
+
+ this.DetachedFromLogicalTree += delegate
+ {
+ Disposables?.Dispose();
+ };
}
private void InitializeComponent()
@@ -58,7 +104,7 @@ namespace WalletWasabi.Gui.Controls.LockScreen
private void OnBoundsChange(Rect obj)
{
var newHeight = obj.Height;
- RealThreshold = newHeight * ThresholdPercent;
+ _realThreshold = newHeight * _thresholdPercent;
}
private void OnOffsetChanged(double value)
@@ -69,75 +115,33 @@ namespace WalletWasabi.Gui.Controls.LockScreen
private void OnClockTick(TimeSpan CurrentTime)
{
- // if (!UserDragInProgress & Math.Abs(Offset) > RealThreshold)
- // {
- // IsLocked = false;
- // StopSpring = true;
- // return;
- // }
-
- // if (IsLocked & !UserDragInProgress & Offset != 0)
- // {
- // Offset *= 1 - Stiffness;
- // }
+ if (IsLocked & !_userDragInProgress & Math.Abs(Offset) > _realThreshold)
+ {
+ Token = "Unlock";
+ return;
+ }
+ else if (IsLocked & !_userDragInProgress & Offset != 0)
+ {
+ Offset *= 1 - _stiffness;
+ }
}
private void OnDragStarted()
{
- UserDragInProgress = true;
+ _userDragInProgress = true;
}
private void OnDragDelta(VectorEventArgs e)
{
if (e.Vector.Y < 0)
{
- this.Offset = e.Vector.Y;
+ Offset = e.Vector.Y;
}
}
private void OnDragCompleted(VectorEventArgs e)
{
- UserDragInProgress = false;
+ _userDragInProgress = false;
}
-
- // public override void DoLock()
- // {
- // Shade.Classes.Add("Locked");
- // Shade.Classes.Remove("Unlocked");
- // Offset = 0;
- // UserDragInProgress = false;
-
- // Disposables = new CompositeDisposable();
-
- // Observable.FromEventPattern<VectorEventArgs>(DragThumb, nameof(DragThumb.DragCompleted))
- // .ObserveOn(RxApp.MainThreadScheduler)
- // .Subscribe(e => OnDragCompleted(e.EventArgs))
- // .DisposeWith(Disposables);
-
- // Observable.FromEventPattern<VectorEventArgs>(DragThumb, nameof(DragThumb.DragDelta))
- // .ObserveOn(RxApp.MainThreadScheduler)
- // .Subscribe(e => OnDragDelta(e.EventArgs))
- // .DisposeWith(Disposables);
-
- // Observable.FromEventPattern(DragThumb, nameof(DragThumb.DragStarted))
- // .ObserveOn(RxApp.MainThreadScheduler)
- // .Subscribe(e => OnDragStarted())
- // .DisposeWith(Disposables);
-
- // this.WhenAnyValue(x => x.Bounds)
- // .ObserveOn(RxApp.MainThreadScheduler)
- // .Subscribe(OnBoundsChange)
- // .DisposeWith(Disposables);
-
- // Clock.Subscribe(OnClockTick)
- // .DisposeWith(Disposables);
- // }
-
- // public override void DoUnlock()
- // {
- // Shade.Classes.Add("Unlocked");
- // Shade.Classes.Remove("Locked");
- // Disposables?.Dispose();
- // }
}
}

MODIFY
WalletWasabi.Gui/Controls/LockScreen/SlideLockScreenViewModel.cs
WalletWasabi.Gui/Controls/LockScreen/SlideLockScreenViewModel.cs
using WalletWasabi.Gui.ViewModels;
using WalletWasabi.Helpers;
+using System;
+using ReactiveUI;
+using System.Reactive.Disposables;
+using System.Reactive.Linq;
namespace WalletWasabi.Gui.Controls.LockScreen
{
@@ -7,13 +11,47 @@ namespace WalletWasabi.Gui.Controls.LockScreen
{
private LockScreenViewModel _parentVM;
+ private CompositeDisposable Disposables { get; }
+
+ private readonly ObservableAsPropertyHelper<bool> _isLocked;
+ public bool IsLocked => _isLocked?.Value ?? false;
+
+ private string _token;
+ public string Token
+ {
+ get => _token;
+ set => this.RaiseAndSetIfChanged(ref _token, value);
+ }
+
public SlideLockScreenViewModel(LockScreenViewModel lockScreenViewModel)
{
_parentVM = Guard.NotNull(nameof(lockScreenViewModel), lockScreenViewModel);
+
+ Disposables = new CompositeDisposable();
+
+ this.WhenAnyValue(x => x.Token)
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Subscribe(CheckToken)
+ .DisposeWith(Disposables);
+
+ _isLocked = _parentVM.WhenAnyValue(x => x.IsLocked)
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .ToProperty(this, x => x.IsLocked)
+ .DisposeWith(Disposables);
}
+
+ private void CheckToken(string input)
+ {
+ if (input == "Unlock")
+ {
+ _parentVM.IsLocked = false;
+ Token = string.Empty;
+ }
+ }
+
public void Dispose()
{
- // empty.
+ this.Disposables?.Dispose();
}
}
}
\ No newline at end of file

Slide lock fully functional.