From e5241a59e707a7cba8e7c106c36f4a6ead9d1469 Mon Sep 17 00:00:00 2001 From: Steven He Date: Fri, 22 Jul 2022 13:16:38 +0900 Subject: [PATCH 1/5] various fixes --- src/Avalonia.Base/Visual.cs | 10 ++++++++-- src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Base/Visual.cs b/src/Avalonia.Base/Visual.cs index 8feba116f0..fbc940114a 100644 --- a/src/Avalonia.Base/Visual.cs +++ b/src/Avalonia.Base/Visual.cs @@ -667,8 +667,14 @@ namespace Avalonia if (_visualParent is IRenderRoot || _visualParent?.IsAttachedToVisualTree == true) { - var root = this.FindAncestorOfType() ?? - throw new AvaloniaInternalException("Visual is atached to visual tree but root could not be found."); + var root = this.FindAncestorOfType(); + if (root is null) + { + Logger.TryGet(LogEventLevel.Error, "Visual")?.Log("Visual", + "Visual is atached to visual tree but root could not be found."); + return; + } + var e = new VisualTreeAttachmentEventArgs(_visualParent, root); OnAttachedToVisualTreeCore(e); } diff --git a/src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs b/src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs index b3469c212b..ccdc5ac19b 100644 --- a/src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs +++ b/src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs @@ -148,6 +148,13 @@ namespace Avalonia.OpenGL.Controls return false; } + if (_context == null) + { + Logger.TryGet(LogEventLevel.Error, "OpenGL")?.Log("OpenGlControlBase", + "Unable to initialize OpenGL: unable to create additional OpenGL context."); + return false; + } + GlVersion = _context.Version; try { From 2132ba2cc909884fb069b384f5ac30fce7cc63b5 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sat, 6 Aug 2022 03:58:45 -0400 Subject: [PATCH 2/5] Delete legacy ReactiveUI.TransitioningContentControl --- .../TransitioningContentControl.cs | 80 ------------------- 1 file changed, 80 deletions(-) delete mode 100644 src/Avalonia.ReactiveUI/TransitioningContentControl.cs diff --git a/src/Avalonia.ReactiveUI/TransitioningContentControl.cs b/src/Avalonia.ReactiveUI/TransitioningContentControl.cs deleted file mode 100644 index d26e90b2da..0000000000 --- a/src/Avalonia.ReactiveUI/TransitioningContentControl.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Threading; - -using Avalonia.Animation; -using Avalonia.Controls; -using Avalonia.Styling; - -namespace Avalonia.ReactiveUI -{ - /// - /// A ContentControl that animates the transition when its content is changed. - /// - [Obsolete("Use TransitioningContentControl in Avalonia.Controls namespace")] - public class TransitioningContentControl : ContentControl, IStyleable - { - /// - /// for the property. - /// - public static readonly StyledProperty PageTransitionProperty = - AvaloniaProperty.Register(nameof(PageTransition), - new CrossFade(TimeSpan.FromSeconds(0.5))); - - /// - /// for the property. - /// - public static readonly StyledProperty DefaultContentProperty = - AvaloniaProperty.Register(nameof(DefaultContent)); - - private CancellationTokenSource? _lastTransitionCts; - - /// - /// Gets or sets the animation played when content appears and disappears. - /// - public IPageTransition? PageTransition - { - get => GetValue(PageTransitionProperty); - set => SetValue(PageTransitionProperty, value); - } - - /// - /// Gets or sets the content displayed whenever there is no page currently routed. - /// - public object? DefaultContent - { - get => GetValue(DefaultContentProperty); - set => SetValue(DefaultContentProperty, value); - } - - /// - /// Gets or sets the content with animation. - /// - public new object? Content - { - get => base.Content; - set => UpdateContentWithTransition(value); - } - - /// - /// TransitioningContentControl uses the default ContentControl - /// template from Avalonia default theme. - /// - Type IStyleable.StyleKey => typeof(ContentControl); - - /// - /// Updates the content with transitions. - /// - /// New content to set. - private async void UpdateContentWithTransition(object? content) - { - _lastTransitionCts?.Cancel(); - _lastTransitionCts = new CancellationTokenSource(); - - if (PageTransition != null) - await PageTransition.Start(this, null, true, _lastTransitionCts.Token); - base.Content = content; - if (PageTransition != null) - await PageTransition.Start(null, this, true, _lastTransitionCts.Token); - } - } -} From 748a25df0d8210c070c07dd9e0cd7a95ffa12e5f Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sat, 6 Aug 2022 22:38:36 -0400 Subject: [PATCH 3/5] Restore missing DefaultContentProperty prop --- src/Avalonia.ReactiveUI/RoutedViewHost.cs | 15 +++++++++++++++ src/Avalonia.ReactiveUI/ViewModelViewHost.cs | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/Avalonia.ReactiveUI/RoutedViewHost.cs b/src/Avalonia.ReactiveUI/RoutedViewHost.cs index 9269dc70f8..775014d419 100644 --- a/src/Avalonia.ReactiveUI/RoutedViewHost.cs +++ b/src/Avalonia.ReactiveUI/RoutedViewHost.cs @@ -64,6 +64,12 @@ namespace Avalonia.ReactiveUI public static readonly StyledProperty ViewContractProperty = AvaloniaProperty.Register(nameof(ViewContract)); + /// + /// for the property. + /// + public static readonly StyledProperty DefaultContentProperty = + ViewModelViewHost.DefaultContentProperty.AddOwner(); + /// /// Initializes a new instance of the class. /// @@ -106,6 +112,15 @@ namespace Avalonia.ReactiveUI set => SetValue(ViewContractProperty, value); } + /// + /// Gets or sets the content displayed whenever there is no page currently routed. + /// + public object? DefaultContent + { + get => GetValue(DefaultContentProperty); + set => SetValue(DefaultContentProperty, value); + } + /// /// Gets or sets the ReactiveUI view locator used by this router. /// diff --git a/src/Avalonia.ReactiveUI/ViewModelViewHost.cs b/src/Avalonia.ReactiveUI/ViewModelViewHost.cs index 16dee00ebc..869238b377 100644 --- a/src/Avalonia.ReactiveUI/ViewModelViewHost.cs +++ b/src/Avalonia.ReactiveUI/ViewModelViewHost.cs @@ -1,5 +1,8 @@ using System; using System.Reactive.Disposables; + +using Avalonia.Controls; + using ReactiveUI; using Splat; @@ -24,6 +27,12 @@ namespace Avalonia.ReactiveUI public static readonly StyledProperty ViewContractProperty = AvaloniaProperty.Register(nameof(ViewContract)); + /// + /// for the property. + /// + public static readonly StyledProperty DefaultContentProperty = + AvaloniaProperty.Register(nameof(DefaultContent)); + /// /// Initializes a new instance of the class. /// @@ -55,6 +64,15 @@ namespace Avalonia.ReactiveUI set => SetValue(ViewContractProperty, value); } + /// + /// Gets or sets the content displayed whenever there is no page currently routed. + /// + public object? DefaultContent + { + get => GetValue(DefaultContentProperty); + set => SetValue(DefaultContentProperty, value); + } + /// /// Gets or sets the view locator. /// From 8436e0f7624a050b7e256abcf7d7a1d8f5aae30d Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sun, 7 Aug 2022 01:32:48 -0400 Subject: [PATCH 4/5] Remove test that doesn't make sense anymore --- .../TransitioningContentControlTest.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/Avalonia.ReactiveUI.UnitTests/TransitioningContentControlTest.cs b/tests/Avalonia.ReactiveUI.UnitTests/TransitioningContentControlTest.cs index 6ca617d2d4..daa3830b7d 100644 --- a/tests/Avalonia.ReactiveUI.UnitTests/TransitioningContentControlTest.cs +++ b/tests/Avalonia.ReactiveUI.UnitTests/TransitioningContentControlTest.cs @@ -12,14 +12,6 @@ namespace Avalonia.ReactiveUI.UnitTests { public class TransitioningContentControlTest { - [Fact] - public void Transitioning_Control_Should_Derive_Template_From_Content_Control() - { - var target = new TransitioningContentControl(); - var stylable = (IStyledElement)target; - Assert.Equal(typeof(ContentControl),stylable.StyleKey); - } - [Fact] public void Transitioning_Control_Template_Should_Be_Instantiated() { From 9377ce2a8fa630de33373d8beda3392d2e1dcb06 Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 7 Aug 2022 15:23:51 +0900 Subject: [PATCH 5/5] Update Visual.cs --- src/Avalonia.Base/Visual.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Avalonia.Base/Visual.cs b/src/Avalonia.Base/Visual.cs index fbc940114a..8feba116f0 100644 --- a/src/Avalonia.Base/Visual.cs +++ b/src/Avalonia.Base/Visual.cs @@ -667,14 +667,8 @@ namespace Avalonia if (_visualParent is IRenderRoot || _visualParent?.IsAttachedToVisualTree == true) { - var root = this.FindAncestorOfType(); - if (root is null) - { - Logger.TryGet(LogEventLevel.Error, "Visual")?.Log("Visual", - "Visual is atached to visual tree but root could not be found."); - return; - } - + var root = this.FindAncestorOfType() ?? + throw new AvaloniaInternalException("Visual is atached to visual tree but root could not be found."); var e = new VisualTreeAttachmentEventArgs(_visualParent, root); OnAttachedToVisualTreeCore(e); }