Skip to content

Commit

Permalink
refactor: remove possible null reference
Browse files Browse the repository at this point in the history
  • Loading branch information
huynhsontung committed Nov 25, 2023
1 parent 5967dcf commit 4a749a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions Screenbox/Pages/AlbumDetailsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ManipulationPropertySetReferenceNode>();

CreateHeaderAnimation(scrollingProperties.Translation.Y);
CreateHeaderAnimation(_props, scrollingProperties.Translation.Y);
MediaViewModel firstSong = ViewModel.Source.RelatedSongs[0];
if (firstSong.ThumbnailSource != null)
{
Expand All @@ -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)
{
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions Screenbox/Pages/ArtistDetailsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ManipulationPropertySetReferenceNode>();

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);
Expand Down

0 comments on commit 4a749a5

Please sign in to comment.