Address review in SlideLock.
MODIFY
WalletWasabi.Gui/Controls/LockScreen/SlideLockScreenViewModel.cs
WalletWasabi.Gui/Controls/LockScreen/SlideLockScreenViewModel.cs
@@ -4,55 +4,68 @@ using System;
using ReactiveUI;
using System.Reactive.Disposables;
using System.Reactive.Linq;
+using Avalonia;
namespace WalletWasabi.Gui.Controls.LockScreen
{
public class SlideLockScreenViewModel : ViewModelBase, ILockScreenViewModel
{
+ public CompositeDisposable Disposables { get; }
private LockScreenViewModel _parentVM;
-
- private CompositeDisposable Disposables { get; }
-
private ObservableAsPropertyHelper<bool> _isLocked;
public bool IsLocked => _isLocked?.Value ?? false;
- private string _token;
+ private bool _isUserDragging;
+ public bool IsUserDragging
+ {
+ get => _isUserDragging;
+ set => this.RaiseAndSetIfChanged(ref _isUserDragging, value);
+ }
- public string Token
+ private double _threshold;
+ public double Threshold
+ {
+ get => _threshold;
+ set => this.RaiseAndSetIfChanged(ref _threshold, value);
+ }
+ private double _offset;
+ public double Offset
{
- get => _token;
- set => this.RaiseAndSetIfChanged(ref _token, value);
+ get => _offset;
+ set => this.RaiseAndSetIfChanged(ref _offset, value);
}
+ public readonly double ThresholdPercent = 1 / 6d;
+ public readonly double Stiffness = 0.12d;
+
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)
+ public void Dispose()
+ {
+ Disposables?.Dispose();
+ }
+
+ internal void OnClockTick(TimeSpan obj)
{
- if (input == "Unlock")
+ if (IsLocked & !IsUserDragging & Math.Abs(Offset) > Threshold)
{
_parentVM.IsLocked = false;
- Token = string.Empty;
+ return;
}
- }
-
- public void Dispose()
+ else if (IsLocked & !IsUserDragging & Offset != 0)
{
- Disposables?.Dispose();
+ Offset *= 1 - Stiffness;
+ }
}
}
}

Address review in SlideLock.