From 4a749a50e00f555c178295516e905a3110a84398 Mon Sep 17 00:00:00 2001 From: Tung Huynh Date: Sat, 25 Nov 2023 01:31:46 -0800 Subject: [PATCH] refactor: remove possible null reference --- Screenbox/Pages/AlbumDetailsPage.xaml.cs | 9 +++++---- Screenbox/Pages/ArtistDetailsPage.xaml.cs | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Screenbox/Pages/AlbumDetailsPage.xaml.cs b/Screenbox/Pages/AlbumDetailsPage.xaml.cs index 4454341d4..d1602fe7a 100644 --- a/Screenbox/Pages/AlbumDetailsPage.xaml.cs +++ b/Screenbox/Pages/AlbumDetailsPage.xaml.cs @@ -76,7 +76,7 @@ private void AlbumDetailsPage_OnLoaded(object sender, RoutedEventArgs e) // Get references to our property sets for use with ExpressionNodes ManipulationPropertySetReferenceNode scrollingProperties = _scrollerPropertySet.GetSpecializedReference(); - CreateHeaderAnimation(scrollingProperties.Translation.Y); + CreateHeaderAnimation(_props, scrollingProperties.Translation.Y); MediaViewModel firstSong = ViewModel.Source.RelatedSongs[0]; if (firstSong.ThumbnailSource != null) { @@ -90,6 +90,7 @@ private void AlbumDetailsPage_OnLoaded(object sender, RoutedEventArgs e) private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { + if (_scrollerPropertySet == null) return; MediaViewModel media = (MediaViewModel)sender; if (e.PropertyName == nameof(MediaViewModel.Thumbnail) && media.ThumbnailSource != null) { @@ -99,16 +100,16 @@ private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) } } - private void CreateHeaderAnimation(ScalarNode scrollVerticalOffset) + private void CreateHeaderAnimation(CompositionPropertySet propSet, ScalarNode scrollVerticalOffset) { - PropertySetReferenceNode props = _props.GetReference(); + PropertySetReferenceNode props = propSet.GetReference(); ScalarNode progressNode = props.GetScalarProperty("progress"); ScalarNode clampSizeNode = props.GetScalarProperty("clampSize"); ScalarNode bottomMarginNode = props.GetScalarProperty("bottomMargin"); // Create and start an ExpressionAnimation to track scroll progress over the desired distance ExpressionNode progressAnimation = EF.Clamp(-scrollVerticalOffset / clampSizeNode, 0, 1); - _props.StartAnimation("progress", progressAnimation); + propSet.StartAnimation("progress", progressAnimation); // Get the backing visual for the photo in the header so that its properties can be animated Visual photoVisual = ElementCompositionPreview.GetElementVisual(BackgroundAcrylic); diff --git a/Screenbox/Pages/ArtistDetailsPage.xaml.cs b/Screenbox/Pages/ArtistDetailsPage.xaml.cs index 9965e1d60..68167f05d 100644 --- a/Screenbox/Pages/ArtistDetailsPage.xaml.cs +++ b/Screenbox/Pages/ArtistDetailsPage.xaml.cs @@ -65,19 +65,19 @@ private void ArtistDetailsPage_OnLoaded(object sender, RoutedEventArgs e) // Get references to our property sets for use with ExpressionNodes ManipulationPropertySetReferenceNode scrollingProperties = _scrollerPropertySet.GetSpecializedReference(); - CreateHeaderAnimation(scrollingProperties.Translation.Y); + CreateHeaderAnimation(_props, scrollingProperties.Translation.Y); } - private void CreateHeaderAnimation(ScalarNode scrollVerticalOffset) + private void CreateHeaderAnimation(CompositionPropertySet propSet, ScalarNode scrollVerticalOffset) { - PropertySetReferenceNode props = _props.GetReference(); + PropertySetReferenceNode props = propSet.GetReference(); ScalarNode progressNode = props.GetScalarProperty("progress"); ScalarNode clampSizeNode = props.GetScalarProperty("clampSize"); ScalarNode bottomMarginNode = props.GetScalarProperty("bottomMargin"); // Create and start an ExpressionAnimation to track scroll progress over the desired distance ExpressionNode progressAnimation = EF.Clamp(-scrollVerticalOffset / clampSizeNode, 0, 1); - _props.StartAnimation("progress", progressAnimation); + propSet.StartAnimation("progress", progressAnimation); // Get the backing visual for the photo in the header so that its properties can be animated Visual photoVisual = ElementCompositionPreview.GetElementVisual(BackgroundAcrylic);