Browse Source

Merge branch 'master' into fix/radial-gradient-brush

pull/4749/head
Max Katz 6 years ago
committed by GitHub
parent
commit
ffd7a446a7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/Avalonia.Controls/MenuItem.cs
  2. 18
      src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs
  3. 61
      src/Avalonia.Visuals/Animation/CompositePageTransition.cs
  4. 29
      src/Avalonia.Visuals/Animation/CrossFade.cs
  5. 44
      src/Avalonia.Visuals/Animation/PageSlide.cs

4
src/Avalonia.Controls/MenuItem.cs

@ -101,7 +101,7 @@ namespace Avalonia.Controls
private ICommand? _command; private ICommand? _command;
private bool _commandCanExecute = true; private bool _commandCanExecute = true;
private Popup _popup; private Popup? _popup;
/// <summary> /// <summary>
/// Initializes static members of the <see cref="MenuItem"/> class. /// Initializes static members of the <see cref="MenuItem"/> class.
@ -145,7 +145,7 @@ namespace Avalonia.Controls
{ {
var parent = x as Control; var parent = x as Control;
return parent?.GetObservable(DefinitionBase.PrivateSharedSizeScopeProperty) ?? return parent?.GetObservable(DefinitionBase.PrivateSharedSizeScopeProperty) ??
Observable.Return<DefinitionBase.SharedSizeScope>(null); Observable.Return<DefinitionBase.SharedSizeScope?>(null);
}); });
this.Bind(DefinitionBase.PrivateSharedSizeScopeProperty, parentSharedSizeScope); this.Bind(DefinitionBase.PrivateSharedSizeScopeProperty, parentSharedSizeScope);

18
src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs

@ -148,6 +148,7 @@ namespace Avalonia.Controls.Platform
{ {
case Key.Up: case Key.Up:
case Key.Down: case Key.Down:
{
if (item?.IsTopLevel == true) if (item?.IsTopLevel == true)
{ {
if (item.HasSubMenu && !item.IsSubMenuOpen) if (item.HasSubMenu && !item.IsSubMenuOpen)
@ -161,8 +162,10 @@ namespace Avalonia.Controls.Platform
goto default; goto default;
} }
break; break;
}
case Key.Left: case Key.Left:
{
if (item?.Parent is IMenuItem parent && !parent.IsTopLevel && parent.IsSubMenuOpen) if (item?.Parent is IMenuItem parent && !parent.IsTopLevel && parent.IsSubMenuOpen)
{ {
parent.Close(); parent.Close();
@ -174,8 +177,10 @@ namespace Avalonia.Controls.Platform
goto default; goto default;
} }
break; break;
}
case Key.Right: case Key.Right:
{
if (item != null && !item.IsTopLevel && item.HasSubMenu) if (item != null && !item.IsTopLevel && item.HasSubMenu)
{ {
Open(item, true); Open(item, true);
@ -186,8 +191,10 @@ namespace Avalonia.Controls.Platform
goto default; goto default;
} }
break; break;
}
case Key.Enter: case Key.Enter:
{
if (item != null) if (item != null)
{ {
if (!item.HasSubMenu) if (!item.HasSubMenu)
@ -202,12 +209,14 @@ namespace Avalonia.Controls.Platform
e.Handled = true; e.Handled = true;
} }
break; break;
}
case Key.Escape: case Key.Escape:
if (item?.Parent != null) {
if (item?.Parent is IMenuElement parent)
{ {
item.Parent.Close(); parent.Close();
item.Parent.Focus(); parent.Focus();
} }
else else
{ {
@ -216,8 +225,10 @@ namespace Avalonia.Controls.Platform
e.Handled = true; e.Handled = true;
break; break;
}
default: default:
{
var direction = e.Key.ToNavigationDirection(); var direction = e.Key.ToNavigationDirection();
if (direction.HasValue) if (direction.HasValue)
@ -246,6 +257,7 @@ namespace Avalonia.Controls.Platform
} }
break; break;
}
} }
if (!e.Handled && item?.Parent is IMenuItem parentItem) if (!e.Handled && item?.Parent is IMenuItem parentItem)

61
src/Avalonia.Visuals/Animation/CompositePageTransition.cs

@ -0,0 +1,61 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Metadata;
namespace Avalonia.Animation
{
/// <summary>
/// Defines a composite page transition that can be used to combine multiple transitions.
/// </summary>
/// <remarks>
/// <para>
/// Instantiate the <see cref="CompositePageTransition" /> in XAML and initialize the
/// <see cref="Transitions" /> property in order to have many animations triggered at once.
/// For example, you can combine <see cref="CrossFade"/> and <see cref="PageSlide"/>.
/// <code>
/// <![CDATA[
/// <reactiveUi:RoutedViewHost Router="{Binding Router}">
/// <reactiveUi:RoutedViewHost.PageTransition>
/// <CompositePageTransition>
/// <PageSlide Duration="0.5" />
/// <CrossFade Duration="0.5" />
/// </CompositePageTransition>
/// </reactiveUi:RoutedViewHost.PageTransition>
/// </reactiveUi:RoutedViewHost>
/// ]]>
/// </code>
/// </para>
/// </remarks>
public class CompositePageTransition : IPageTransition
{
/// <summary>
/// Gets or sets the transitions to be executed. Can be defined from XAML.
/// </summary>
[Content]
public List<IPageTransition> PageTransitions { get; set; } = new List<IPageTransition>();
/// <summary>
/// Starts the animation.
/// </summary>
/// <param name="from">
/// The control that is being transitioned away from. May be null.
/// </param>
/// <param name="to">
/// The control that is being transitioned to. May be null.
/// </param>
/// <param name="forward">
/// Defines the direction of the transition.
/// </param>
/// <returns>
/// A <see cref="Task"/> that tracks the progress of the animation.
/// </returns>
public Task Start(Visual from, Visual to, bool forward)
{
var transitionTasks = PageTransitions
.Select(transition => transition.Start(from, to, forward))
.ToList();
return Task.WhenAll(transitionTasks);
}
}
}

29
src/Avalonia.Visuals/Animation/CrossFade.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Animation.Easings;
using Avalonia.Styling; using Avalonia.Styling;
using Avalonia.VisualTree; using Avalonia.VisualTree;
@ -74,14 +75,26 @@ namespace Avalonia.Animation
/// </summary> /// </summary>
public TimeSpan Duration public TimeSpan Duration
{ {
get get => _fadeOutAnimation.Duration;
{ set => _fadeOutAnimation.Duration = _fadeInAnimation.Duration = value;
return _fadeOutAnimation.Duration; }
}
set /// <summary>
{ /// Gets or sets element entrance easing.
_fadeOutAnimation.Duration = _fadeInAnimation.Duration = value; /// </summary>
} public Easing FadeInEasing
{
get => _fadeInAnimation.Easing;
set => _fadeInAnimation.Easing = value;
}
/// <summary>
/// Gets or sets element exit easing.
/// </summary>
public Easing FadeOutEasing
{
get => _fadeOutAnimation.Easing;
set => _fadeOutAnimation.Easing = value;
} }
/// <summary> /// <summary>

44
src/Avalonia.Visuals/Animation/PageSlide.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Animation.Easings;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Styling; using Avalonia.Styling;
using Avalonia.VisualTree; using Avalonia.VisualTree;
@ -48,6 +49,16 @@ namespace Avalonia.Animation
/// Gets the duration of the animation. /// Gets the duration of the animation.
/// </summary> /// </summary>
public SlideAxis Orientation { get; set; } public SlideAxis Orientation { get; set; }
/// <summary>
/// Gets or sets element entrance easing.
/// </summary>
public Easing SlideInEasing { get; set; } = new LinearEasing();
/// <summary>
/// Gets or sets element exit easing.
/// </summary>
public Easing SlideOutEasing { get; set; } = new LinearEasing();
/// <summary> /// <summary>
/// Starts the animation. /// Starts the animation.
@ -75,18 +86,12 @@ namespace Avalonia.Animation
{ {
var animation = new Animation var animation = new Animation
{ {
Children = Easing = SlideOutEasing,
Children =
{ {
new KeyFrame new KeyFrame
{ {
Setters = Setters = { new Setter { Property = translateProperty, Value = 0d } },
{
new Setter
{
Property = translateProperty,
Value = 0d
}
},
Cue = new Cue(0d) Cue = new Cue(0d)
}, },
new KeyFrame new KeyFrame
@ -100,10 +105,10 @@ namespace Avalonia.Animation
} }
}, },
Cue = new Cue(1d) Cue = new Cue(1d)
} }
} },
Duration = Duration
}; };
animation.Duration = Duration;
tasks.Add(animation.RunAsync(from)); tasks.Add(animation.RunAsync(from));
} }
@ -112,9 +117,9 @@ namespace Avalonia.Animation
to.IsVisible = true; to.IsVisible = true;
var animation = new Animation var animation = new Animation
{ {
Easing = SlideInEasing,
Children = Children =
{ {
new KeyFrame new KeyFrame
{ {
Setters = Setters =
@ -129,19 +134,12 @@ namespace Avalonia.Animation
}, },
new KeyFrame new KeyFrame
{ {
Setters = Setters = { new Setter { Property = translateProperty, Value = 0d } },
{
new Setter
{
Property = translateProperty,
Value = 0d
}
},
Cue = new Cue(1d) Cue = new Cue(1d)
} }
} },
Duration = Duration
}; };
animation.Duration = Duration;
tasks.Add(animation.RunAsync(to)); tasks.Add(animation.RunAsync(to));
} }

Loading…
Cancel
Save