Skip to content

Commit

Permalink
Downgrade to Avalonia 11.0.999-cibuild0044755-beta (WalletWasabi#13342)
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolay authored Aug 23, 2024
1 parent daaa65b commit 056bff2
Show file tree
Hide file tree
Showing 32 changed files with 5,215 additions and 869 deletions.
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<AvaloniaVersion>11.2.0-beta1</AvaloniaVersion>
<AvaloniaVersion>11.0.999-cibuild0044755-beta</AvaloniaVersion>
</PropertyGroup>
<ItemGroup>
<!-- AspNetCore. -->
Expand Down Expand Up @@ -34,9 +34,9 @@
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<!-- UI. -->
<PackageVersion Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.Controls.TreeDataGrid" Version="11.0.10" />
<PackageVersion Include="Avalonia.Controls.TreeDataGrid" Version="11.0.2" />
<PackageVersion Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.Xaml.Behaviors" Version="11.1.0" />
<PackageVersion Include="Avalonia.Xaml.Behaviors" Version="11.0.5" />
<PackageVersion Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.ReactiveUI" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.Skia" Version="$(AvaloniaVersion)" />
Expand All @@ -60,4 +60,4 @@
<PackageVersion Include="xunit" Version="2.6.6" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
</ItemGroup>
</Project>
</Project>
4 changes: 4 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="avalonia-all" value="https://nuget-feed-all.avaloniaui.net/v3/index.json" />
</packageSources>

<packageSourceMapping>
<packageSource key="avalonia-all">
<package pattern="*"/>
</packageSource>
<packageSource key="nuget.org">
<package pattern="*"/>
</packageSource>
Expand Down
2,590 changes: 2,214 additions & 376 deletions WalletWasabi.Fluent.Desktop/packages.lock.json

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions WalletWasabi.Fluent/ApplicationStateManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System.ComponentModel;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Platform;
using ReactiveUI;
using WalletWasabi.Fluent.Extensions;
using WalletWasabi.Fluent.Helpers;
Expand All @@ -29,14 +27,14 @@ public class ApplicationStateManager : IMainWindowService
private bool _hideRequest;
private bool _isShuttingDown;
private bool _restartRequest;
private IActivatableLifetime? _activatable;
private IActivatableApplicationLifetime? _activatable;

internal ApplicationStateManager(IClassicDesktopStyleApplicationLifetime lifetime, UiContext uiContext, bool startInBg)
{
_lifetime = lifetime;
_stateMachine = new StateMachine<State, Trigger>(State.InitialState);

if (Application.Current?.TryGetFeature<IActivatableLifetime>() is { } activatableLifetime)
if (_lifetime is IActivatableApplicationLifetime activatableLifetime)
{
if (startInBg)
{
Expand Down Expand Up @@ -152,6 +150,7 @@ private void ActivatableLifetimeOnActivated(object? sender, ActivatedEventArgs e
{
switch (e.Kind)
{
case ActivationKind.Background:
case ActivationKind.Reopen:
if (this is IMainWindowService service)
{
Expand Down Expand Up @@ -186,9 +185,9 @@ private void CreateAndShowMainWindow()

MainViewModel.Instance.ApplyUiConfigWindowState();

if (Application.Current?.TryGetFeature<IActivatableLifetime>() is { } activatableLifetime)
if (_lifetime is IActivatableApplicationLifetime activatable)
{
activatableLifetime.TryLeaveBackground();
activatable.TryLeaveBackground();
}

var result = new MainWindow
Expand Down
43 changes: 43 additions & 0 deletions WalletWasabi.Fluent/Behaviors/BindPointerOverBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.Xaml.Interactions.Custom;

namespace WalletWasabi.Fluent.Behaviors;

public class BindPointerOverBehavior : DisposingBehavior<Control>
{
public static readonly StyledProperty<bool> IsPointerOverProperty =
AvaloniaProperty.Register<BindPointerOverBehavior, bool>(nameof(IsPointerOver), defaultBindingMode: BindingMode.TwoWay);

public bool IsPointerOver
{
get => GetValue(IsPointerOverProperty);
set => SetValue(IsPointerOverProperty, value);
}

protected override void OnAttached(CompositeDisposable disposables)
{
if (AssociatedObject is null)
{
return;
}

Observable
.FromEventPattern<AvaloniaPropertyChangedEventArgs>(AssociatedObject, nameof(PropertyChanged))
.Select(x => x.EventArgs)
.Subscribe(e =>
{
if (e.Property == InputElement.IsPointerOverProperty)
{
IsPointerOver = e.NewValue is true;
}
})
.DisposeWith(disposables);

disposables.Add(Disposable.Create(() => IsPointerOver = false));
}
}
50 changes: 50 additions & 0 deletions WalletWasabi.Fluent/Behaviors/BoundsObserverBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Reactive.Disposables;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Data;
using Avalonia.Xaml.Interactions.Custom;

namespace WalletWasabi.Fluent.Behaviors;

internal class BoundsObserverBehavior : DisposingBehavior<Control>
{
public static readonly StyledProperty<Rect> BoundsProperty =
AvaloniaProperty.Register<BoundsObserverBehavior, Rect>(nameof(Bounds), defaultBindingMode: BindingMode.OneWay);

public static readonly StyledProperty<double> WidthProperty =
AvaloniaProperty.Register<BoundsObserverBehavior, double>(nameof(Width), defaultBindingMode: BindingMode.TwoWay);

public static readonly StyledProperty<double> HeightProperty =
AvaloniaProperty.Register<BoundsObserverBehavior, double>(nameof(Height), defaultBindingMode: BindingMode.TwoWay);

public Rect Bounds
{
get => GetValue(BoundsProperty);
set => SetValue(BoundsProperty, value);
}

public double Width
{
get => GetValue(WidthProperty);
set => SetValue(WidthProperty, value);
}

public double Height
{
get => GetValue(HeightProperty);
set => SetValue(HeightProperty, value);
}

protected override void OnAttached(CompositeDisposable disposables)
{
if (AssociatedObject is not null)
{
disposables.Add(this.GetObservable(BoundsProperty)
.Subscribe(bounds =>
{
Width = bounds.Width;
Height = bounds.Height;
}));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Reactive.Disposables;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.VisualTree;
using Avalonia.Xaml.Interactions.Custom;

namespace WalletWasabi.Fluent.Behaviors;

public class ButtonExecuteCommandOnKeyDownBehavior : AttachedToVisualTreeBehavior<Button>
{
public static readonly StyledProperty<Key?> KeyProperty =
AvaloniaProperty.Register<ButtonExecuteCommandOnKeyDownBehavior, Key?>(nameof(Key));

public static readonly StyledProperty<bool> IsEnabledProperty =
AvaloniaProperty.Register<ButtonExecuteCommandOnKeyDownBehavior, bool>(nameof(IsEnabled));

public Key? Key
{
get => GetValue(KeyProperty);
set => SetValue(KeyProperty, value);
}

public bool IsEnabled
{
get => GetValue(IsEnabledProperty);
set => SetValue(IsEnabledProperty, value);
}

protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var button = AssociatedObject;
if (button is null)
{
return;
}

if (button.GetVisualRoot() is InputElement inputRoot)
{
inputRoot
.AddDisposableHandler(InputElement.KeyDownEvent, RootDefaultKeyDown)
.DisposeWith(disposable);
}
}

private void RootDefaultKeyDown(object? sender, KeyEventArgs e)
{
var button = AssociatedObject;
if (button is null)
{
return;
}

if (Key is { } && e.Key == Key && button.IsVisible && button.IsEnabled && IsEnabled)
{
if (!e.Handled && button.Command?.CanExecute(button.CommandParameter) == true)
{
button.Command.Execute(button.CommandParameter);
e.Handled = true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static void AnimateImplicit(Control control, TimeSpan opacityDuration, b

var scaleAnimation = compositor.CreateVector3KeyFrameAnimation();
scaleAnimation.Target = "Scale";
if (enableScale && false) // TODO: Remove when Avalonia fixes
if (enableScale)
{
scaleAnimation.InsertExpressionKeyFrame(0f, "Vector3(0.96+(1.0-0.96)*this.Target.Opacity, 0.96+(1.0-0.96)*this.Target.Opacity, 0)", fluentEasing);
scaleAnimation.InsertExpressionKeyFrame(1f, "Vector3(0.96+(1.0-0.96)*this.Target.Opacity, 0.96+(1.0-0.96)*this.Target.Opacity, 0)", fluentEasing);
Expand Down
25 changes: 25 additions & 0 deletions WalletWasabi.Fluent/Behaviors/DisposingTrigger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Reactive.Disposables;
using Avalonia.Xaml.Interactivity;

namespace WalletWasabi.Fluent.Behaviors;

public abstract class DisposingTrigger : Trigger
{
private readonly CompositeDisposable _disposables = new();

protected override void OnAttached()
{
base.OnAttached();

OnAttached(_disposables);
}

protected abstract void OnAttached(CompositeDisposable disposables);

protected override void OnDetaching()
{
base.OnDetaching();

_disposables.Dispose();
}
}
40 changes: 40 additions & 0 deletions WalletWasabi.Fluent/Behaviors/ExecuteCommandOnActivatedBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Windows.Input;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Xaml.Interactions.Custom;

namespace WalletWasabi.Fluent.Behaviors;

public class ExecuteCommandOnActivatedBehavior : DisposingBehavior<Control>
{
public static readonly StyledProperty<ICommand?> CommandProperty =
AvaloniaProperty.Register<ExecuteCommandOnActivatedBehavior, ICommand?>(nameof(Command));

public ICommand? Command
{
get => GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}

protected override void OnAttached(CompositeDisposable disposables)
{
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
{
var mainWindow = lifetime.MainWindow;

Observable
.FromEventPattern(mainWindow, nameof(mainWindow.Activated))
.Subscribe(_ =>
{
if (Command is { } cmd && cmd.CanExecute(default))
{
cmd.Execute(default);
}
})
.DisposeWith(disposables);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Reactive.Disposables;
using System.Windows.Input;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Xaml.Interactions.Custom;

namespace WalletWasabi.Fluent.Behaviors;

public class ExecuteCommandOnDoubleTappedBehavior : DisposingBehavior<Control>
{
public static readonly StyledProperty<ICommand?> CommandProperty =
AvaloniaProperty.Register<ExecuteCommandOnDoubleTappedBehavior, ICommand?>(nameof(Command));

public ICommand? Command
{
get => GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}

protected override void OnAttached(CompositeDisposable disposables)
{
Gestures.DoubleTappedEvent.AddClassHandler<InputElement>(
(x, _) =>
{
if (Equals(x, AssociatedObject))
{
if (Command is { } cmd && cmd.CanExecute(default))
{
cmd.Execute(default);
}
}
},
RoutingStrategies.Tunnel | RoutingStrategies.Bubble)
.DisposeWith(disposables);
}
}
Loading

0 comments on commit 056bff2

Please sign in to comment.