From c5f0e18d55a3485960cbacaa2d88fdfa50e32b6a Mon Sep 17 00:00:00 2001 From: Max Katz Date: Wed, 28 Dec 2022 14:47:29 -0800 Subject: [PATCH 1/9] Support TransformOperations animations in Brush animator --- .../Animators/GradientBrushAnimator.cs | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Base/Animation/Animators/GradientBrushAnimator.cs b/src/Avalonia.Base/Animation/Animators/GradientBrushAnimator.cs index 068c190fa1..7da1b68051 100644 --- a/src/Avalonia.Base/Animation/Animators/GradientBrushAnimator.cs +++ b/src/Avalonia.Base/Animation/Animators/GradientBrushAnimator.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Avalonia.Data; using Avalonia.Media; using Avalonia.Media.Immutable; +using Avalonia.Media.Transformation; #nullable enable @@ -30,7 +31,7 @@ namespace Avalonia.Animation.Animators return new ImmutableRadialGradientBrush( InterpolateStops(progress, oldValue.GradientStops, newValue.GradientStops), s_doubleAnimator.Interpolate(progress, oldValue.Opacity, newValue.Opacity), - oldValue.Transform is { } ? new ImmutableTransform(oldValue.Transform.Value) : null, + InterpolateTransform(progress, oldValue.Transform, newValue.Transform), s_relativePointAnimator.Interpolate(progress, oldValue.TransformOrigin, newValue.TransformOrigin), oldValue.SpreadMethod, s_relativePointAnimator.Interpolate(progress, oldRadial.Center, newRadial.Center), @@ -41,7 +42,7 @@ namespace Avalonia.Animation.Animators return new ImmutableConicGradientBrush( InterpolateStops(progress, oldValue.GradientStops, newValue.GradientStops), s_doubleAnimator.Interpolate(progress, oldValue.Opacity, newValue.Opacity), - oldValue.Transform is { } ? new ImmutableTransform(oldValue.Transform.Value) : null, + InterpolateTransform(progress, oldValue.Transform, newValue.Transform), s_relativePointAnimator.Interpolate(progress, oldValue.TransformOrigin, newValue.TransformOrigin), oldValue.SpreadMethod, s_relativePointAnimator.Interpolate(progress, oldConic.Center, newConic.Center), @@ -51,7 +52,7 @@ namespace Avalonia.Animation.Animators return new ImmutableLinearGradientBrush( InterpolateStops(progress, oldValue.GradientStops, newValue.GradientStops), s_doubleAnimator.Interpolate(progress, oldValue.Opacity, newValue.Opacity), - oldValue.Transform is { } ? new ImmutableTransform(oldValue.Transform.Value) : null, + InterpolateTransform(progress, oldValue.Transform, newValue.Transform), s_relativePointAnimator.Interpolate(progress, oldValue.TransformOrigin, newValue.TransformOrigin), oldValue.SpreadMethod, s_relativePointAnimator.Interpolate(progress, oldLinear.StartPoint, newLinear.StartPoint), @@ -72,6 +73,25 @@ namespace Avalonia.Animation.Animators return control.Bind((AvaloniaProperty)Property, instance, BindingPriority.Animation); } + private static ImmutableTransform? InterpolateTransform(double progress, + ITransform? oldTransform, ITransform? newTransform) + { + if (oldTransform is TransformOperations oldTransformOperations + && newTransform is TransformOperations newTransformOperations) + { + + return new ImmutableTransform(TransformOperations + .Interpolate(oldTransformOperations, newTransformOperations, progress).Value); + } + + if (oldTransform is { }) + { + return new ImmutableTransform(oldTransform.Value); + } + + return null; + } + private static IReadOnlyList InterpolateStops(double progress, IReadOnlyList oldValue, IReadOnlyList newValue) { var resultCount = Math.Max(oldValue.Count, newValue.Count); From a4d94f62f4c61f674e65f9be4613596f630d4c4b Mon Sep 17 00:00:00 2001 From: Max Katz Date: Wed, 28 Dec 2022 18:30:21 -0800 Subject: [PATCH 2/9] Update src/Avalonia.Base/Animation/Animators/GradientBrushAnimator.cs --- src/Avalonia.Base/Animation/Animators/GradientBrushAnimator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Base/Animation/Animators/GradientBrushAnimator.cs b/src/Avalonia.Base/Animation/Animators/GradientBrushAnimator.cs index 7da1b68051..801f247754 100644 --- a/src/Avalonia.Base/Animation/Animators/GradientBrushAnimator.cs +++ b/src/Avalonia.Base/Animation/Animators/GradientBrushAnimator.cs @@ -84,7 +84,7 @@ namespace Avalonia.Animation.Animators .Interpolate(oldTransformOperations, newTransformOperations, progress).Value); } - if (oldTransform is { }) + if (oldTransform is not null) { return new ImmutableTransform(oldTransform.Value); } From 37545cbeb1a07c9fbea4e86912686b0d48717e6a Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 12 Jan 2023 00:35:03 -0500 Subject: [PATCH 3/9] IStorageProvider API updates --- samples/ControlCatalog/Pages/DialogsPage.xaml | 17 ++- .../ControlCatalog/Pages/DialogsPage.xaml.cs | 59 +++++++-- .../Avalonia.Android/AvaloniaMainActivity.cs | 9 ++ .../IActivityResultHandler.cs | 3 + .../Platform/PlatformSupport.cs | 52 ++++++++ .../Platform/Storage/AndroidStorageItem.cs | 101 +++++++++----- .../Storage/AndroidStorageProvider.cs | 124 ++++++++++++++++-- .../Platform/Storage/FileIO/BclStorageFile.cs | 71 +++++----- .../Storage/FileIO/BclStorageFolder.cs | 63 ++++----- .../Storage/FileIO/BclStorageProvider.cs | 103 ++++++++++++++- .../Storage/FileIO/StorageProviderHelpers.cs | 18 ++- .../Platform/Storage/IStorageItem.cs | 4 +- .../Platform/Storage/IStorageProvider.cs | 35 ++++- .../Platform/Storage/NameCollisionOption.cs | 6 + .../Storage/StorageProviderExtensions.cs | 55 ++++++++ .../Platform/Storage/WellKnownFolder.cs | 37 ++++++ .../Platform/Dialogs/SystemDialogImpl.cs | 11 +- src/Avalonia.Dialogs/Avalonia.Dialogs.csproj | 5 + .../Internal/ManagedFileChooserViewModel.cs | 12 +- .../ManagedFileDialogExtensions.cs | 4 +- .../ManagedStorageProvider.cs | 2 +- src/Avalonia.FreeDesktop/DBusSystemDialog.cs | 6 +- src/Avalonia.Native/SystemDialogs.cs | 9 +- .../NativeDialogs/CompositeStorageProvider.cs | 18 +++ .../NativeDialogs/GtkNativeFileDialogs.cs | 10 +- .../Avalonia.Browser/Interop/StorageHelper.cs | 3 + .../Storage/BrowserStorageProvider.cs | 34 ++++- .../webapp/modules/storage/storageItem.ts | 34 ++++- .../webapp/modules/storage/storageProvider.ts | 6 +- .../Avalonia.Win32/Win32StorageProvider.cs | 4 +- .../Avalonia.iOS/Storage/IOSStorageItem.cs | 41 +++--- .../Storage/IOSStorageProvider.cs | 50 +++++-- .../Utilities/UriExtensionsTests.cs | 15 +++ 33 files changed, 804 insertions(+), 217 deletions(-) create mode 100644 src/Android/Avalonia.Android/Platform/PlatformSupport.cs create mode 100644 src/Avalonia.Base/Platform/Storage/NameCollisionOption.cs create mode 100644 src/Avalonia.Base/Platform/Storage/StorageProviderExtensions.cs create mode 100644 src/Avalonia.Base/Platform/Storage/WellKnownFolder.cs diff --git a/samples/ControlCatalog/Pages/DialogsPage.xaml b/samples/ControlCatalog/Pages/DialogsPage.xaml index cc23ef796a..53c0a2c547 100644 --- a/samples/ControlCatalog/Pages/DialogsPage.xaml +++ b/samples/ControlCatalog/Pages/DialogsPage.xaml @@ -1,6 +1,8 @@ + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:storage="clr-namespace:Avalonia.Platform.Storage;assembly=Avalonia.Base" + xmlns:generic="clr-namespace:System.Collections.Generic;assembly=System.Collections"> @@ -42,6 +44,19 @@ + + + + Desktop + Documents + Downloads + Pictures + Videos + Music + + + + ("PickerLastResults"); var resultsVisible = this.Get("PickerLastResultsVisible"); var bookmarkContainer = this.Get("BookmarkContainer"); var openedFileContent = this.Get("OpenedFileContent"); var openMultiple = this.Get("OpenMultiple"); + var currentFolderBox = this.Get("CurrentFolderBox"); + + currentFolderBox.TextChanged += async (sender, args) => + { + if (ignoreTextChanged) return; + + if (Enum.TryParse(currentFolderBox.Text, true, out var folderEnum)) + { + lastSelectedDirectory = await GetStorageProvider().TryGetWellKnownFolder(folderEnum); + } + else + { + if (!Uri.TryCreate(currentFolderBox.Text, UriKind.Absolute, out var folderLink)) + { + Uri.TryCreate("file://" + currentFolderBox.Text, UriKind.Absolute, out folderLink); + } + + if (folderLink is not null) + { + lastSelectedDirectory = await GetStorageProvider().TryGetFolderFromPath(folderLink); + } + } + }; - IStorageFolder? lastSelectedDirectory = null; List GetFilters() { @@ -84,7 +109,7 @@ namespace ControlCatalog.Pages { Title = "Open multiple files", Filters = GetFilters(), - Directory = lastSelectedDirectory?.TryGetUri(out var path) == true ? path.LocalPath : null, + Directory = lastSelectedDirectory?.Path is {IsAbsoluteUri:true} path ? path.LocalPath : null, AllowMultiple = true }.ShowAsync(GetWindow()); results.Items = result; @@ -97,7 +122,7 @@ namespace ControlCatalog.Pages { Title = "Save file", Filters = filters, - Directory = lastSelectedDirectory?.TryGetUri(out var path) == true ? path.LocalPath : null, + Directory = lastSelectedDirectory?.Path is {IsAbsoluteUri:true} path ? path.LocalPath : null, DefaultExtension = filters?.Any() == true ? "txt" : null, InitialFileName = "test.txt" }.ShowAsync(GetWindow()); @@ -109,7 +134,7 @@ namespace ControlCatalog.Pages var result = await new OpenFolderDialog() { Title = "Select folder", - Directory = lastSelectedDirectory?.TryGetUri(out var path) == true ? path.LocalPath : null + Directory = lastSelectedDirectory?.Path is {IsAbsoluteUri:true} path ? path.LocalPath : null, }.ShowAsync(GetWindow()); if (string.IsNullOrEmpty(result)) { @@ -117,7 +142,7 @@ namespace ControlCatalog.Pages } else { - lastSelectedDirectory = new BclStorageFolder(new System.IO.DirectoryInfo(result)); + SetFolder(await GetStorageProvider().TryGetFolderFromPath(result)); results.Items = new[] { result }; resultsVisible.IsVisible = true; } @@ -127,7 +152,7 @@ namespace ControlCatalog.Pages var result = await new OpenFileDialog() { Title = "Select both", - Directory = lastSelectedDirectory?.TryGetUri(out var path) == true ? path.LocalPath : null, + Directory = lastSelectedDirectory?.Path is {IsAbsoluteUri:true} path ? path.LocalPath : null, AllowMultiple = true }.ShowManagedAsync(GetWindow(), new ManagedFileDialogOptions { @@ -210,7 +235,7 @@ namespace ControlCatalog.Pages #endif await reader.WriteLineAsync(openedFileContent.Text); - lastSelectedDirectory = await file.GetParentAsync(); + SetFolder(await file.GetParentAsync()); } await SetPickerResult(file is null ? null : new [] {file}); @@ -226,7 +251,7 @@ namespace ControlCatalog.Pages await SetPickerResult(folders); - lastSelectedDirectory = folders.FirstOrDefault(); + SetFolder(folders.FirstOrDefault()); }; this.Get