Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding ProgressRing extension #1002

Merged
merged 7 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ProgressRing Grid.Row="1"
IsActive="True"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Height="100"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@
Command="{Binding LoadContent1Command}" />
</StackPanel>


<utu:LoadingView.LoadingContentTemplate>
<DataTemplate>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<ProgressRing IsActive="True" />
<TextBlock Text="{Binding}" />
</StackPanel>
</DataTemplate>
</utu:LoadingView.LoadingContentTemplate>
<utu:LoadingView.LoadingContentTemplate>
<DataTemplate>
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center">
<ProgressRing />
<ProgressBar Width="200" />
<TextBlock Text="{Binding}" />
</StackPanel>
</DataTemplate>
</utu:LoadingView.LoadingContentTemplate>
</utu:LoadingView>
<ToggleSwitch IsOn="{Binding UseTransitions, ElementName=LoadingView, Mode=TwoWay}">
<ToggleSwitch.OnContent>
Expand Down
58 changes: 58 additions & 0 deletions src/Uno.Toolkit.UI/Behaviors/ProgressExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Uno.UI.Extensions;

#if IS_WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
#else
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using ItemsRepeater = Microsoft.UI.Xaml.Controls.ItemsRepeater;
#endif

namespace Uno.Toolkit.UI
{
public static class ProgressExtensions
{
#region DependencyProperty: IsActive

/// <summary>
/// Backing property for a value which recursively sets whether the
/// nested progress controls are displaying a loading animation.
/// </summary>
public static readonly DependencyProperty IsActiveProperty = DependencyProperty.RegisterAttached(
"IsActive",
typeof(bool),
typeof(ProgressExtensions),
new PropertyMetadata(false, IsActiveChanged));

public static bool GetIsActive(FrameworkElement element) => (bool)element.GetValue(IsActiveProperty);
public static void SetIsActive(FrameworkElement element, bool value) => element.SetValue(IsActiveProperty, value);

#endregion

private static void IsActiveChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is FrameworkElement element &&
e.NewValue is bool isActive)
{
foreach (var item in element.GetChildren())
{
if (item is ProgressRing progressRing)
{
progressRing.IsActive = isActive;
}
else if (item is ProgressBar progressBar)
{
progressBar.IsIndeterminate = isActive;
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@
</Storyboard>
</VisualTransition>
</VisualStateGroup.Transitions>
<VisualState x:Name="Loading" />
<VisualState x:Name="Loading">
<VisualState.Setters>
<Setter Target="LoadingContentPresenter.(utu:ProgressExtensions.IsActive)" Value="true"/>
<Setter Target="SplashScreenPresenter.(utu:ProgressExtensions.IsActive)" Value="true"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Loaded">
<VisualState.Setters>
<Setter Target="ContentPresenter.Opacity"
Expand All @@ -70,6 +75,8 @@
Value="Collapsed" />
<Setter Target="LoadingContentPresenter.Visibility"
Value="Collapsed" />
<Setter Target="LoadingContentPresenter.(utu:ProgressExtensions.IsActive)" Value="false"/>
<Setter Target="SplashScreenPresenter.(utu:ProgressExtensions.IsActive)" Value="false"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
Expand All @@ -84,6 +91,7 @@
VerticalContentAlignment="Stretch" />
<ContentPresenter x:Name="SplashScreenPresenter"
Content="{TemplateBinding SplashScreenContent}"
utu:ProgressExtensions.IsActive="false"
IsHitTestVisible="False"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
HorizontalContentAlignment="Stretch"
Expand All @@ -92,6 +100,7 @@
<ContentControl x:Name="LoadingContentPresenter"
Content="{TemplateBinding LoadingContent}"
IsHitTestVisible="False"
utu:ProgressExtensions.IsActive="false"
ContentTemplate="{TemplateBinding LoadingContentTemplate}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
HorizontalContentAlignment="Stretch"
Expand Down
9 changes: 8 additions & 1 deletion src/Uno.Toolkit.UI/Controls/LoadingView/LoadingView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,33 @@
</Storyboard>
</VisualTransition>
</VisualStateGroup.Transitions>
<VisualState x:Name="Loading" />
<VisualState x:Name="Loading">
<VisualState.Setters>
<Setter Target="LoadingContentPresenter.(utu:ProgressExtensions.IsActive)" Value="true"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Loaded">
<VisualState.Setters>
<Setter Target="ContentPresenter.Opacity"
Value="1" />
<Setter Target="LoadingContentPresenter.Opacity"
Value="0" />
<Setter Target="LoadingContentPresenter.(utu:ProgressExtensions.IsActive)" Value="false"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>

<ContentPresenter x:Name="ContentPresenter"
Content="{TemplateBinding Content}"
utu:ProgressExtensions.IsActive="false"
Opacity="0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
HorizontalContentAlignment="Stretch"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
VerticalContentAlignment="Stretch" />
<ContentControl x:Name="LoadingContentPresenter"
utu:ProgressExtensions.IsActive="false"
Content="{TemplateBinding LoadingContent}"
ContentTemplate="{TemplateBinding LoadingContentTemplate}"
ContentTemplateSelector="{TemplateBinding LoadingContentTemplateSelector}"
Expand Down
Loading