Skip to content

Commit 37e34a9

Browse files
committed
CQ: Add for Animated Icon
1 parent 2e56817 commit 37e34a9

File tree

4 files changed

+66
-17
lines changed

4 files changed

+66
-17
lines changed

src/Files.App/UserControls/Symbols/ArrowGlyph.xaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,27 @@
22
x:Class="Files.App.UserControls.Symbols.ArrowGlyph"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"
56
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
67
xmlns:local="using:Files.App.UserControls.Symbols"
78
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
89
x:Name="Root"
910
mc:Ignorable="d">
1011

11-
<Grid x:Name="SymbolGrid">
12+
<Grid x:Name="SymbolGrid" Loaded="SymbolGrid_Loaded">
1213
<FontIcon
1314
x:Name="SymbolIcon"
1415
FontSize="{Binding FontSize, ElementName=Root}"
15-
Glyph="{x:Bind Glyph, Mode=OneWay}" />
16+
Glyph="{x:Bind Glyph, Mode=OneWay}"
17+
Visibility="{x:Bind IsStaticIconVisible, Mode=OneWay}" />
18+
19+
<AnimatedIcon x:Name="DynamicAnimatedIcon" Visibility="{x:Bind IsAnimatedIconVisible, Mode=OneWay}">
20+
<AnimatedIcon.Source>
21+
<animatedvisuals:AnimatedBackVisualSource />
22+
</AnimatedIcon.Source>
23+
<AnimatedIcon.FallbackIconSource>
24+
<SymbolIconSource Symbol="Back" />
25+
</AnimatedIcon.FallbackIconSource>
26+
</AnimatedIcon>
1627
</Grid>
1728
</UserControl>

src/Files.App/UserControls/Symbols/ArrowGlyph.xaml.cs

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1-
using Microsoft.UI;
2-
using Microsoft.UI.Xaml;
1+
using Microsoft.UI.Xaml;
32
using Microsoft.UI.Xaml.Controls;
3+
using Microsoft.UI.Xaml.Controls.AnimatedVisuals;
44
using Microsoft.UI.Xaml.Media;
5+
using System.Numerics;
6+
using System.Runtime.CompilerServices;
57

68
namespace Files.App.UserControls.Symbols
79
{
810
[DependencyProperty<double>("FontSize", DefaultValue = "(double)12.0")]
9-
[DependencyProperty<Brush>("Color", nameof(OnColorChange), DefaultValue = "null")]
11+
[DependencyProperty<Brush>("Foreground", nameof(OnColorChange), DefaultValue = "null")]
1012
[DependencyProperty<ArrowSymbolType>("Arrow", nameof(OnArrowChange), DefaultValue = "Files.App.Data.Enums.ArrowSymbolType.ChevronRight")]
13+
[DependencyProperty<bool>("UseAnimatedIcon", nameof(OnUseAnimatedIconChanged), DefaultValue = "false")]
1114
[DependencyProperty<string>("Glyph", DefaultValue = "null")]
12-
public sealed partial class ArrowGlyph : UserControl, IRealTimeControl
15+
public partial class ArrowGlyph : UserControl, INotifyPropertyChanged, IRealTimeControl
1316
{
1417
private static ICommandManager Commands { get; } = Ioc.Default.GetRequiredService<ICommandManager>();
1518

1619
private string ForwardGlyph { get; } = Commands.NavigateForward.Glyph.BaseGlyph;
17-
1820
private string BackGlyph { get; } = Commands.NavigateBack.Glyph.BaseGlyph;
19-
2021
private string ChevronLeft { get; } = "\uE76B";
2122
private string ChevronRight { get; } = "\uE76C";
2223

2324
private long _token;
2425

26+
public event PropertyChangedEventHandler? PropertyChanged;
27+
28+
public bool IsStaticIconVisible => !UseAnimatedIcon;
29+
30+
public bool IsAnimatedIconVisible => UseAnimatedIcon;
31+
2532
public ArrowGlyph()
2633
{
2734
InitializeComponent();
@@ -30,8 +37,25 @@ public ArrowGlyph()
3037
RealTimeLayoutService.AddCallback(this, UpdateGlyph);
3138
}
3239

40+
41+
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
42+
{
43+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
44+
}
45+
3346
private void UpdateGlyph()
3447
{
48+
if (UseAnimatedIcon)
49+
{
50+
SymbolGrid.Rotation = Arrow switch
51+
{
52+
ArrowSymbolType.Forward => FlowDirection == FlowDirection.LeftToRight ? 180 : 0,
53+
ArrowSymbolType.Back => FlowDirection == FlowDirection.LeftToRight ? 0 : 180,
54+
_ => 0
55+
};
56+
return;
57+
}
58+
3559
Glyph = Arrow switch
3660
{
3761
ArrowSymbolType.Forward => FlowDirection == FlowDirection.LeftToRight ? ForwardGlyph : BackGlyph,
@@ -56,6 +80,26 @@ private void OnArrowChange(ArrowSymbolType oldValue, ArrowSymbolType newValue)
5680
if (oldValue != newValue)
5781
UpdateGlyph();
5882
}
83+
84+
private void OnUseAnimatedIconChanged(bool oldValue, bool newValue)
85+
{
86+
if (oldValue != newValue)
87+
{
88+
UpdateGlyph();
89+
OnPropertyChanged(nameof(IsStaticIconVisible));
90+
OnPropertyChanged(nameof(IsAnimatedIconVisible));
91+
}
92+
}
93+
94+
private void SymbolGrid_Loaded(object sender, RoutedEventArgs e)
95+
{
96+
if (UseAnimatedIcon)
97+
{
98+
var centerX = SymbolGrid.ActualWidth / 2;
99+
var centerY = SymbolGrid.ActualHeight / 2;
100+
SymbolGrid.CenterPoint = new Vector3((float)centerX, (float)centerY, 0);
101+
}
102+
}
59103
}
60104

61105
}

src/Files.App/Views/Layouts/ColumnLayoutPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@
345345
x:Load="{x:Bind IsFolder}"
346346
Arrow="ChevronRight"
347347
FontSize="12"
348-
Color="{ThemeResource TextFillColorSecondaryBrush}" />
348+
Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
349349

350350
</StackPanel>
351351
</Grid>

src/Files.App/Views/Properties/MainPropertiesPage.xaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
xmlns:dataitems="using:Files.App.Data.Items"
1010
xmlns:helpers="using:Files.App.Helpers"
1111
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
12+
xmlns:s="using:Files.App.UserControls.Symbols"
1213
xmlns:uc="using:Files.App.UserControls"
1314
xmlns:vm="using:Files.App.ViewModels.Properties"
1415
xmlns:wctconverters="using:CommunityToolkit.WinUI.UI.Converters"
@@ -69,14 +70,7 @@
6970
<StaticResource x:Key="ButtonBorderBrushDisabled" ResourceKey="SystemControlTransparentBrush" />
7071
</ResourceDictionary>
7172
</Button.Resources>
72-
<AnimatedIcon x:Name="BackAnimatedIcon">
73-
<AnimatedIcon.Source>
74-
<animatedvisuals:AnimatedBackVisualSource />
75-
</AnimatedIcon.Source>
76-
<AnimatedIcon.FallbackIconSource>
77-
<SymbolIconSource Symbol="Back" />
78-
</AnimatedIcon.FallbackIconSource>
79-
</AnimatedIcon>
73+
<s:ArrowGlyph Arrow="Back" UseAnimatedIcon="True" />
8074
</Button>
8175

8276
<!-- Title Text Area -->

0 commit comments

Comments
 (0)