From 21ccb8d43aa35ec4aa66a70bfd7660e31e4c7252 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Tue, 12 Jul 2022 16:13:56 +0300 Subject: [PATCH] Fixed animation activation --- .../Composition/Server/ServerObject.cs | 10 +- .../Utilities/SmallDictionary.cs | 101 +++++++++++++++++- 2 files changed, 105 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.Base/Rendering/Composition/Server/ServerObject.cs b/src/Avalonia.Base/Rendering/Composition/Server/ServerObject.cs index c6b468a32f..93ea8e8dee 100644 --- a/src/Avalonia.Base/Rendering/Composition/Server/ServerObject.cs +++ b/src/Avalonia.Base/Rendering/Composition/Server/ServerObject.cs @@ -70,14 +70,16 @@ namespace Avalonia.Rendering.Composition.Server Deactivated(); } - protected virtual void Activated() + protected void Activated() { - + foreach(var kp in _animations) + kp.Value.Activate(); } - protected virtual void Deactivated() + protected void Deactivated() { - + foreach(var kp in _animations) + kp.Value.Deactivate(); } void InvalidateSubscriptions(CompositionProperty property) diff --git a/src/Avalonia.Base/Utilities/SmallDictionary.cs b/src/Avalonia.Base/Utilities/SmallDictionary.cs index b8f532c747..7d6a21c136 100644 --- a/src/Avalonia.Base/Utilities/SmallDictionary.cs +++ b/src/Avalonia.Base/Utilities/SmallDictionary.cs @@ -1,16 +1,19 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; namespace Avalonia.Utilities; -public struct InlineDictionary where TKey : class where TValue : class +public struct InlineDictionary : IEnumerable> where TKey : class where TValue : class { object? _data; TValue? _value; void SetCore(TKey key, TValue value, bool overwrite) { + if (key == null) + throw new ArgumentNullException(); if (_data == null) { _data = key; @@ -178,4 +181,98 @@ public struct InlineDictionary where TKey : class where TValue : c return v; throw new KeyNotFoundException(); } -} \ No newline at end of file + + public struct Enumerator : IEnumerator> + { + private Dictionary.Enumerator _inner; + private readonly KeyValuePair[]? _arr; + private KeyValuePair _first; + private int _index; + private Type _type; + enum Type + { + Empty, Single, Array, Dictionary + } + + public Enumerator(InlineDictionary parent) + { + _arr = null; + _first = default; + _index = -1; + _inner = default; + if (parent._data is Dictionary inner) + { + _inner = inner.GetEnumerator(); + _type = Type.Dictionary; + } + else if (parent._data is KeyValuePair[] arr) + { + _type = Type.Array; + _arr = arr; + } + else if (parent._data != null) + { + _type = Type.Single; + _first = new((TKey)parent._data!, parent._value!); + } + else + _type = Type.Empty; + + } + + public bool MoveNext() + { + if (_type == Type.Single) + { + if (_index != -1) + return false; + _index = 0; + } + else if (_type == Type.Array) + { + var next = _index + 1; + if (_arr!.Length - 1 < next || _arr[next].Key == null) + return false; + _index = next; + return true; + } + else if (_type == Type.Dictionary) + return _inner.MoveNext(); + + return false; + } + + public void Reset() + { + _index = -1; + if(_type == Type.Dictionary) + ((IEnumerator)_inner).Reset(); + } + + public KeyValuePair Current + { + get + { + if (_type == Type.Single) + return _first!; + if (_type == Type.Array) + return _arr![_index]!; + if (_type == Type.Dictionary) + return _inner.Current; + throw new InvalidOperationException(); + } + } + + object IEnumerator.Current => Current; + + public void Dispose() + { + } + } + + public Enumerator GetEnumerator() => new Enumerator(this); + + IEnumerator> IEnumerable>.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + +}