Skip to content

Commit

Permalink
feat(ProgressRing): Add DeterminateSource/IndeterminateSource to MUXC…
Browse files Browse the repository at this point in the history
… ProgressRing
  • Loading branch information
kazo0 committed Feb 5, 2021
1 parent 9a46273 commit 302fd4b
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 10 deletions.
18 changes: 18 additions & 0 deletions src/AddIns/Uno.UI.Lottie/LottieVisualSourceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,23 @@ public LottieVisualSourceProvider(object owner)
public IAnimatedVisualSource CreateFromLottieAsset(Uri sourceFile) => new LottieVisualSource {UriSource = sourceFile};

public IThemableAnimatedVisualSource CreateTheamableFromLottieAsset(Uri sourceFile) => new ThemableLottieVisualSource {UriSource = sourceFile};

public bool TryCreateThemableFromAnimatedVisualSource(IAnimatedVisualSource animatedVisualSource, out IThemableAnimatedVisualSource? themableAnimatedVisualSource)
{
themableAnimatedVisualSource = default;
if (animatedVisualSource is ThemableLottieVisualSource themable)
{
themableAnimatedVisualSource = themable;
return true;
}

if (animatedVisualSource is LottieVisualSource lottieVisualSource)
{
themableAnimatedVisualSource = CreateTheamableFromLottieAsset(lottieVisualSource.UriSource);
return true;
}

return false;
}
}
}
4 changes: 2 additions & 2 deletions src/SamplesApp/SamplesApp.UWP/SamplesApp.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<Version>6.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.UI.Xaml">
<Version>2.5.0</Version>
<Version>2.6.0-prerelease.210113001</Version>
</PackageReference>
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="BenchmarkDotNet" Version="0.11.4-develop" />
Expand Down Expand Up @@ -167,4 +167,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<Page
x:Class="UITests.Microsoft_UI_Xaml_Controls.ProgressRing.WinUIProgressRing_CustomSources"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Microsoft_UI_Xaml_Controls.ProgressRing"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:lottie="using:Microsoft.Toolkit.Uwp.UI.Lottie"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<lottie:LottieVisualSource UriSource="ms-appx:///Assets/Animations/squirrel.json" x:Key="SquirrelAnimation"/>
<lottie:LottieVisualSource UriSource="ms-appx:///Assets/Animations/acrobat.json" x:Key="AcrobatAnimation"/>
</Page.Resources>
<StackPanel Margin="50">
<TextBlock Text="Indeterminate"/>
<muxc:ProgressRing IsActive="True"
IndeterminateSource="{StaticResource SquirrelAnimation}"/>
<muxc:ProgressRing IsActive="True"
IndeterminateSource="{StaticResource AcrobatAnimation}"/>
<TextBlock Text="Determinate"/>
<muxc:ProgressRing IsIndeterminate="False"
IsActive="True"
DeterminateSource="{StaticResource SquirrelAnimation}"
Value="{Binding Value, ElementName=progressSlider}"
Minimum="0"
Maximum="100"/>
<muxc:ProgressRing IsIndeterminate="False"
IsActive="True"
DeterminateSource="{StaticResource AcrobatAnimation}"
Value="{Binding Value, ElementName=progressSlider}"
Minimum="0"
Maximum="100"/>
<Slider x:Name="progressSlider"
Minimum="0"
Maximum="100"
HorizontalAlignment="Left"
Width="250"
Margin="0,10" />
</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Uno.UI.Samples.Controls;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace UITests.Microsoft_UI_Xaml_Controls.ProgressRing
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
[Sample("Progress", "WinUI")]
public sealed partial class WinUIProgressRing_CustomSources : Page
{
public WinUIProgressRing_CustomSources()
{
this.InitializeComponent();
}
}
}
9 changes: 9 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ProgressRing\WinUIProgressRing_CustomSources.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ProgressRing\WinUIProgressRing_Slider.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -4011,6 +4015,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\RatingControlTests\RatingControlPage.xaml.cs">
<DependentUpon>RatingControlPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ProgressRing\WinUIProgressRing_CustomSources.xaml.cs">
<DependentUpon>WinUIProgressRing_CustomSources.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ProgressRing\WinUIProgressRing_Slider.xaml.cs">
<DependentUpon>WinUIProgressRing_Slider.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -6841,6 +6848,8 @@
<Content Include="$(MSBuildThisFileDirectory)Assets\0_leading_number_asset.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\AcrylicBrush.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\Animations.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\Animations\acrobat.json" />
<Content Include="$(MSBuildThisFileDirectory)Assets\Animations\squirrel.json" />
<Content Include="$(MSBuildThisFileDirectory)Assets\AppIcon.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\Asset_GetFileFromApplicationUriAsync_Nested.xml" />
<Content Include="$(MSBuildThisFileDirectory)Assets\AutoSave.png" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public interface ILottieVisualSourceProvider
{
IAnimatedVisualSource CreateFromLottieAsset(Uri sourceFile);
IThemableAnimatedVisualSource CreateTheamableFromLottieAsset(Uri sourceFile);
public bool TryCreateThemableFromAnimatedVisualSource(IAnimatedVisualSource animatedVisualSource, out IThemableAnimatedVisualSource themableAnimatedVisualSource);
}
}
67 changes: 59 additions & 8 deletions src/Uno.UI/Microsoft/UI/Xaml/Controls/ProgressRing/ProgressRing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ public double Minimum
public static DependencyProperty MinimumProperty { get; } = DependencyProperty.Register(
nameof(Minimum), typeof(double), typeof(ProgressRing), new FrameworkPropertyMetadata(0d, (s, e) => (s as ProgressRing)?.OnMinimumPropertyChanged(e)));



public IAnimatedVisualSource DeterminateSource
{
get { return (IAnimatedVisualSource)GetValue(DeterminateSourceProperty); }
set { SetValue(DeterminateSourceProperty, value); }
}

public static readonly DependencyProperty DeterminateSourceProperty =
DependencyProperty.Register("DeterminateSource", typeof(IAnimatedVisualSource), typeof(ProgressRing), new FrameworkPropertyMetadata(null, (s, e) => (s as ProgressRing)?.OnDeterminateSourcePropertyChanged(e)));


public IAnimatedVisualSource IndeterminateSource
{
get { return (IAnimatedVisualSource)GetValue(IndeterminateSourceProperty); }
set { SetValue(IndeterminateSourceProperty, value); }
}

public static readonly DependencyProperty IndeterminateSourceProperty =
DependencyProperty.Register("IndeterminateSource", typeof(IAnimatedVisualSource), typeof(ProgressRing), new FrameworkPropertyMetadata(null, (s, e) => (s as ProgressRing)?.OnIndeterminateSourcePropertyChanged(e)));

public ProgressRing()
{
DefaultStyleKey = typeof(ProgressRing);
Expand Down Expand Up @@ -163,22 +184,52 @@ private void OnMinimumPropertyChanged(DependencyPropertyChangedEventArgs args)
}
}

private void OnDeterminateSourcePropertyChanged(DependencyPropertyChangedEventArgs args)
{
SetAnimatedVisualPlayerSource();
}

private void OnIndeterminateSourcePropertyChanged(DependencyPropertyChangedEventArgs args)
{
SetAnimatedVisualPlayerSource();
}

private void SetAnimatedVisualPlayerSource()
{
if (_lottieProvider != null && _player != null)
{
var isIndeterminate = IsIndeterminate;
if (isIndeterminate && _currentSourceUri != FeatureConfiguration.ProgressRing.ProgressRingAsset)
if (isIndeterminate)
{
_currentSourceUri = FeatureConfiguration.ProgressRing.ProgressRingAsset;
var animatedVisualSource = _lottieProvider.CreateTheamableFromLottieAsset(_currentSourceUri);
_player.Source = animatedVisualSource;
var indeterminateSource = IndeterminateSource;
if (indeterminateSource == null)
{
_currentSourceUri = FeatureConfiguration.ProgressRing.ProgressRingAsset;
var animatedVisualSource = _lottieProvider.CreateTheamableFromLottieAsset(_currentSourceUri);
_player.Source = animatedVisualSource;
}
else
{
_player.Source = _lottieProvider.TryCreateThemableFromAnimatedVisualSource(indeterminateSource, out var themableSource)
? themableSource
: indeterminateSource;
}
}
else if (!isIndeterminate && _currentSourceUri != FeatureConfiguration.ProgressRing.DeterminateProgressRingAsset)
else
{
_currentSourceUri = FeatureConfiguration.ProgressRing.DeterminateProgressRingAsset;
var animatedVisualSource = _lottieProvider.CreateTheamableFromLottieAsset(_currentSourceUri);
_player.Source = animatedVisualSource;
var determinateSource = DeterminateSource;
if (determinateSource == null)
{
_currentSourceUri = FeatureConfiguration.ProgressRing.DeterminateProgressRingAsset;
var animatedVisualSource = _lottieProvider.CreateTheamableFromLottieAsset(_currentSourceUri);
_player.Source = animatedVisualSource;
}
else
{
_player.Source = _lottieProvider.TryCreateThemableFromAnimatedVisualSource(determinateSource, out var themableSource)
? themableSource
: determinateSource;
}
}

}
Expand Down

0 comments on commit 302fd4b

Please sign in to comment.