fix: memory leak caused by animation

This commit is contained in:
leo 2024-05-30 16:12:28 +08:00
parent 8ae864a14d
commit b6e087259b
7 changed files with 50 additions and 28 deletions

View file

@ -84,10 +84,7 @@
</StackPanel>
<!-- Loading -->
<Path Width="48" Height="48"
Classes="rotating"
Data="{StaticResource Icons.Loading}"
IsVisible="{Binding Data, Converter={x:Static ObjectConverters.IsNull}}"/>
<v:LoadingIcon Width="48" Height="48" IsVisible="{Binding Data, Converter={x:Static ObjectConverters.IsNull}}"/>
</Grid>
<!-- Custom window sizer for Linux -->

View file

@ -106,12 +106,10 @@
BorderThickness="1,0,0,0"
BorderBrush="{DynamicResource Brush.Border2}"/>
<Path Grid.Column="2"
Classes="rotating"
Width="48" Height="48"
Data="{DynamicResource Icons.Loading}"
HorizontalAlignment="Center" VerticalAlignment="Center"
IsVisible="{Binding IsLoading}"/>
<v:LoadingIcon Grid.Column="2"
Width="48" Height="48"
HorizontalAlignment="Center" VerticalAlignment="Center"
IsVisible="{Binding IsLoading}"/>
<Grid Grid.Column="2" RowDefinitions="*,3,*" Margin="0,4,4,4" IsVisible="{Binding !IsLoading}">
<ContentControl Grid.Row="0" Content="{Binding DiffContext}">

View file

@ -135,11 +135,8 @@
IsHitTestVisible="False"
ClipToBounds="True"/>
<Path Classes="rotating"
Width="48" Height="48"
Data="{DynamicResource Icons.Loading}"
HorizontalAlignment="Center" VerticalAlignment="Center"
IsVisible="{Binding IsLoading}"/>
<!-- Fix memory leak -->
<v:LoadingIcon Width="48" Height="48" HorizontalAlignment="Center" VerticalAlignment="Center" IsVisible="{Binding IsLoading}"/>
</Grid>
<GridSplitter Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"

View file

@ -0,0 +1,9 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
xmlns:m="using:SourceGit.Models"
x:Class="SourceGit.Views.LoadingIcon">
<Path x:Name="target" Data="{DynamicResource Icons.Loading}"/>
</UserControl>

View file

@ -0,0 +1,27 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
namespace SourceGit.Views
{
public partial class LoadingIcon : UserControl
{
public LoadingIcon()
{
IsHitTestVisible = false;
InitializeComponent();
}
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
target.Classes.Add("rotating");
}
protected override void OnUnloaded(RoutedEventArgs e)
{
base.OnUnloaded(e);
target.Classes.Clear();
}
}
}

View file

@ -180,11 +180,9 @@
</ContentControl>
<!-- Loading Mask -->
<Path Grid.Row="2"
Classes="rotating"
Width="48" Height="48"
Data="{DynamicResource Icons.Loading}"
HorizontalAlignment="Center" VerticalAlignment="Center"
IsVisible="{Binding IsLoading}"/>
<v:LoadingIcon Grid.Row="2"
Width="48" Height="48"
HorizontalAlignment="Center" VerticalAlignment="Center"
IsVisible="{Binding IsLoading}"/>
</Grid>
</Window>

View file

@ -24,7 +24,7 @@
<v:ChangeViewModeSwitcher Grid.Column="0" Width="12" Height="12" Margin="8,0,0,0" ViewMode="{Binding Source={x:Static vm:Preference.Instance}, Path=UnstagedChangeViewMode, Mode=TwoWay}"/>
<TextBlock Grid.Column="1" Text="{DynamicResource Text.WorkingCopy.Unstaged}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold" Margin="8,0,0,0"/>
<TextBlock Grid.Column="2" FontWeight="Bold" Foreground="{DynamicResource Brush.FG2}" Text="{Binding Unstaged, Converter={x:Static c:ListConverters.ToCount}}"/>
<Path Grid.Column="3" Classes="rotating" Width="14" Height="14" Data="{StaticResource Icons.Loading}" Margin="8,0,0,0" IsVisible="{Binding IsStaging}"/>
<v:LoadingIcon Grid.Column="3" Width="14" Height="14" Margin="8,0,0,0" IsVisible="{Binding IsStaging}"/>
<Button Grid.Column="5"
Classes="icon_button"
@ -81,7 +81,7 @@
<v:ChangeViewModeSwitcher Grid.Column="0" Width="12" Height="12" Margin="8,0,0,0" ViewMode="{Binding Source={x:Static vm:Preference.Instance}, Path=StagedChangeViewMode, Mode=TwoWay}"/>
<TextBlock Grid.Column="1" Text="{DynamicResource Text.WorkingCopy.Staged}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold" Margin="8,0,0,0"/>
<TextBlock Grid.Column="2" FontWeight="Bold" Foreground="{DynamicResource Brush.FG2}" Text="{Binding Staged, Converter={x:Static c:ListConverters.ToCount}}"/>
<Path Grid.Column="3" Classes="rotating" Width="14" Height="14" Data="{StaticResource Icons.Loading}" Margin="8,0,0,0" IsVisible="{Binding IsUnstaging}"/>
<v:LoadingIcon Grid.Column="3" Width="14" Height="14" Margin="8,0,0,0" IsVisible="{Binding IsUnstaging}"/>
<Button Grid.Column="5" Classes="icon_button" Width="26" Height="14" Padding="0" Command="{Binding UnstageSelected}">
<ToolTip.Tip>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
@ -191,11 +191,7 @@
IsChecked="{Binding UseAmend, Mode=TwoWay}"
Content="{DynamicResource Text.WorkingCopy.Amend}"/>
<Path Grid.Column="3"
Classes="rotating"
Width="18" Height="18"
Data="{StaticResource Icons.Loading}"
IsVisible="{Binding IsCommitting}"/>
<v:LoadingIcon Grid.Column="3" Width="18" Height="18" IsVisible="{Binding IsCommitting}"/>
<Button Grid.Column="4"
Classes="flat primary"