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 2 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
lukeblevins marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
<Page x:Class="Uno.Toolkit.Samples.Content.Controls.LoadingViewSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Uno.Toolkit.Samples.Content.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:utu="using:Uno.Toolkit.UI"
xmlns:sample="using:Uno.Toolkit.Samples"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page
x:Class="Uno.Toolkit.Samples.Content.Controls.LoadingViewSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Uno.Toolkit.Samples.Content.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sample="using:Uno.Toolkit.Samples"
xmlns:utu="using:Uno.Toolkit.UI"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">

<sample:SamplePageLayout x:Name="SamplePageLayout"
IsDesignAgnostic="True">
<sample:SamplePageLayout.DesignAgnosticTemplate>
<DataTemplate>
<StackPanel>
<utu:LoadingView DataContext="{Binding Data}"
LoadingContent="Loading...."
x:Name="LoadingView">
<utu:LoadingView.Source>
<utu:CompositeLoadableSource>
<utu:LoadableSource Source="{Binding LoadContent0Command}" />
<utu:LoadableSource Source="{Binding LoadContent1Command}" />
</utu:CompositeLoadableSource>
</utu:LoadingView.Source>
<sample:SamplePageLayout x:Name="SamplePageLayout" IsDesignAgnostic="True">
<sample:SamplePageLayout.DesignAgnosticTemplate>
<DataTemplate>
<StackPanel>
<utu:LoadingView
x:Name="LoadingView"
DataContext="{Binding Data}"
LoadingContent="Loading....">
<utu:LoadingView.Source>
<utu:CompositeLoadableSource>
<utu:LoadableSource Source="{Binding LoadContent0Command}" />
<utu:LoadableSource Source="{Binding LoadContent1Command}" />
</utu:CompositeLoadableSource>
</utu:LoadingView.Source>

<StackPanel x:Name="TestPanel">
<TextBlock Text="{Binding Text}" />
<ListView ItemsSource="{Binding Source}" />
<StackPanel x:Name="TestPanel">
<TextBlock Text="{Binding Text}" />
<ListView ItemsSource="{Binding Source}" />

<Button Content="Reload Text"
Command="{Binding LoadContent0Command}" />
<Button Content="Reload List"
Command="{Binding LoadContent1Command}" />
</StackPanel>
<Button Command="{Binding LoadContent0Command}" Content="Reload Text" />
<Button Command="{Binding LoadContent1Command}" Content="Reload List" />
</StackPanel>


<utu:LoadingView.LoadingContentTemplate>
<DataTemplate>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<ProgressRing IsActive="True" />
<TextBlock Text="{Binding}" />
</StackPanel>
</DataTemplate>
</utu:LoadingView.LoadingContentTemplate>
</utu:LoadingView>
<ToggleSwitch IsOn="{Binding UseTransitions, ElementName=LoadingView, Mode=TwoWay}">
<ToggleSwitch.OnContent>
<TextBlock Text="Transitions enabled" />
</ToggleSwitch.OnContent>
<ToggleSwitch.OffContent>
<TextBlock Text="Transitions disabled" />
</ToggleSwitch.OffContent>
</ToggleSwitch>
</StackPanel>
</DataTemplate>
</sample:SamplePageLayout.DesignAgnosticTemplate>
</sample:SamplePageLayout>
<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>
<TextBlock Text="Transitions enabled" />
</ToggleSwitch.OnContent>
<ToggleSwitch.OffContent>
<TextBlock Text="Transitions disabled" />
</ToggleSwitch.OffContent>
</ToggleSwitch>
</StackPanel>
</DataTemplate>
</sample:SamplePageLayout.DesignAgnosticTemplate>
</sample:SamplePageLayout>

</Page>
67 changes: 67 additions & 0 deletions src/Uno.Toolkit.UI/Behaviors/ProgressExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Windows.System;
using Microsoft.Extensions.Logging;
using Uno.Extensions;
using Uno.Logging;
using System.Diagnostics.CodeAnalysis;
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 ItemsRepeater = Microsoft.UI.Xaml.Controls.ItemsRepeater;
#endif


namespace Uno.Toolkit.UI
{
public static class ProgressExtensions
{
public static readonly DependencyProperty IsActiveProperty =
lukeblevins marked this conversation as resolved.
Show resolved Hide resolved
DependencyProperty.RegisterAttached(
"IsActive",
typeof(bool),
typeof(ProgressExtensions),
new PropertyMetadata(false, IsActiveChanged));

private static void IsActiveChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is FrameworkElement element &&
e.NewValue is bool isActive)
{
foreach (var item in element.EnumerateDescendants())
{
if(item is ProgressRing progressRing)
{
progressRing.IsActive = isActive;
}
else if(item is ProgressBar progressBar)
{
progressBar.IsIndeterminate = isActive;
}
}
}
}

public static void SetIsActive(this FrameworkElement element, bool value)
{
element.SetValue(IsActiveProperty, value);
}

public static bool GetIsActive(this FrameworkElement element)
{
return (bool)element.GetValue(IsActiveProperty);
}
}
}
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