Browse Source

Expose activation state via a method.

Previously, the `IsActive` property caused the activator state to be re-evaluated, which meant that when the _debugger_ read it, it was re-evaluated, making debugging difficult.
pull/8600/head
Steven Kirk 4 years ago
parent
commit
96942a2026
  1. 2
      src/Avalonia.Base/Styling/Activators/AndActivator.cs
  2. 18
      src/Avalonia.Base/Styling/Activators/IStyleActivator.cs
  3. 2
      src/Avalonia.Base/Styling/Activators/NotActivator.cs
  4. 2
      src/Avalonia.Base/Styling/Activators/OrActivator.cs
  5. 8
      src/Avalonia.Base/Styling/Activators/StyleActivatorBase.cs
  6. 4
      src/Avalonia.Base/Styling/StyleInstance.cs
  7. 2
      tests/Avalonia.Base.UnitTests/Styling/SelectorTests_Nesting.cs
  8. 2
      tests/Avalonia.Base.UnitTests/Styling/StyleActivatorExtensions.cs

2
src/Avalonia.Base/Styling/Activators/AndActivator.cs

@ -33,7 +33,7 @@ namespace Avalonia.Styling.Activators
for (var i = 0; i < count; ++i)
{
if (_sources[i].IsActive)
if (_sources[i].GetIsActive())
flags |= 1ul << i;
}

18
src/Avalonia.Base/Styling/Activators/IStyleActivator.cs

@ -19,20 +19,20 @@ namespace Avalonia.Styling.Activators
public interface IStyleActivator : IDisposable
{
/// <summary>
/// Gets a value indicating whether the style is activated.
/// Gets a value indicating whether the style is subscribed.
/// </summary>
bool IsSubscribed { get; }
/// <summary>
/// Gets the current activation state.
/// </summary>
/// <remarks>
/// This property should read directly from its inputs and not rely on any subscriptions
/// This method should read directly from its inputs and not rely on any subscriptions
/// to fire in order to be up-to-date. If a change in active state occurs when reading
/// this property then any subscribed <see cref="IStyleActivatorSink"/> should not be
/// this method then any subscribed <see cref="IStyleActivatorSink"/> should not be
/// notified of the change.
/// </remarks>
bool IsActive { get; }
/// <summary>
/// Gets a value indicating whether the style is subscribed.
/// </summary>
bool IsSubscribed { get; }
bool GetIsActive();
/// <summary>
/// Subscribes to the activator.

2
src/Avalonia.Base/Styling/Activators/NotActivator.cs

@ -8,7 +8,7 @@
private readonly IStyleActivator _source;
public NotActivator(IStyleActivator source) => _source = source;
void IStyleActivatorSink.OnNext(bool value, int tag) => ReevaluateIsActive();
protected override bool EvaluateIsActive() => !_source.IsActive;
protected override bool EvaluateIsActive() => !_source.GetIsActive();
protected override void Initialize() => _source.Subscribe(this, 0);
protected override void Deinitialize() => _source.Unsubscribe(this);
}

2
src/Avalonia.Base/Styling/Activators/OrActivator.cs

@ -27,7 +27,7 @@ namespace Avalonia.Styling.Activators
foreach (var source in _sources)
{
if (source.IsActive)
if (source.GetIsActive())
return true;
}

8
src/Avalonia.Base/Styling/Activators/StyleActivatorBase.cs

@ -9,7 +9,7 @@ namespace Avalonia.Styling.Activators
private int _tag;
private bool _value;
public bool IsActive => _value = EvaluateIsActive();
public bool GetIsActive() => _value = EvaluateIsActive();
public bool IsSubscribed => _sink is not null;
@ -48,7 +48,7 @@ namespace Avalonia.Styling.Activators
}
/// <summary>
/// Evaluates the <see cref="IsActive"/> value.
/// Evaluates the activation state.
/// </summary>
/// <remarks>
/// This method should read directly from its inputs and not rely on any subscriptions to
@ -57,8 +57,8 @@ namespace Avalonia.Styling.Activators
protected abstract bool EvaluateIsActive();
/// <summary>
/// Called from a derived class when the <see cref="IsActive"/> state should be re-evaluated
/// and the subscriber notified of any change.
/// Called from a derived class when the activation state should be re-evaluated and the
/// subscriber notified of any change.
/// </summary>
/// <returns>
/// The evaluated active state;

4
src/Avalonia.Base/Styling/StyleInstance.cs

@ -92,10 +92,10 @@ namespace Avalonia.Styling
if (_activator?.IsSubscribed == false)
{
_activator.Subscribe(this);
_animationTrigger?.OnNext(_activator.IsActive);
_animationTrigger?.OnNext(_activator.GetIsActive());
}
_isActive = _activator?.IsActive ?? true;
_isActive = _activator?.GetIsActive() ?? true;
hasChanged = _isActive != previous;
return _isActive;
}

2
tests/Avalonia.Base.UnitTests/Styling/SelectorTests_Nesting.cs

@ -295,7 +295,7 @@ namespace Avalonia.Base.UnitTests.Styling
public ActivatorSink(IStyleActivator source)
{
source.Subscribe(this);
Active = source.IsActive;
Active = source.GetIsActive();
}

2
tests/Avalonia.Base.UnitTests/Styling/StyleActivatorExtensions.cs

@ -39,7 +39,7 @@ namespace Avalonia.Base.UnitTests.Styling
protected override void Subscribed(IObserver<bool> observer, bool first)
{
observer.OnNext(_source.IsActive);
observer.OnNext(_source.GetIsActive());
}
void IStyleActivatorSink.OnNext(bool value, int tag)

Loading…
Cancel
Save