Added ContextMenu/Flyout animations. Added platform services. Use bitmap cache for all views.
This commit is contained in:
17
Harmonia.UI/Platform/ClipboardLocator.cs
Normal file
17
Harmonia.UI/Platform/ClipboardLocator.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input.Platform;
|
||||
|
||||
namespace Harmonia.UI.Platform;
|
||||
|
||||
public class ClipboardLocator : PlatformServiceLocator<IClipboard>, IClipboardLocator
|
||||
{
|
||||
protected override IClipboard? GetFromWindow(Window mainWindow)
|
||||
{
|
||||
return mainWindow.Clipboard;
|
||||
}
|
||||
|
||||
protected override IClipboard? GetFromTopLevel(TopLevel topLevel)
|
||||
{
|
||||
return topLevel.Clipboard;
|
||||
}
|
||||
}
|
||||
8
Harmonia.UI/Platform/IClipboardLocator.cs
Normal file
8
Harmonia.UI/Platform/IClipboardLocator.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Avalonia.Input.Platform;
|
||||
|
||||
namespace Harmonia.UI.Platform;
|
||||
|
||||
public interface IClipboardLocator : IPlatformServiceLocator<IClipboard>
|
||||
{
|
||||
|
||||
}
|
||||
6
Harmonia.UI/Platform/IPlatformServiceLocator.cs
Normal file
6
Harmonia.UI/Platform/IPlatformServiceLocator.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Harmonia.UI.Platform;
|
||||
|
||||
public interface IPlatformServiceLocator<T>
|
||||
{
|
||||
T? Get();
|
||||
}
|
||||
8
Harmonia.UI/Platform/IStorageProviderLocator.cs
Normal file
8
Harmonia.UI/Platform/IStorageProviderLocator.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Avalonia.Platform.Storage;
|
||||
|
||||
namespace Harmonia.UI.Platform;
|
||||
|
||||
public interface IStorageProviderLocator : IPlatformServiceLocator<IStorageProvider>
|
||||
{
|
||||
|
||||
}
|
||||
40
Harmonia.UI/Platform/PlatformServiceLocator.cs
Normal file
40
Harmonia.UI/Platform/PlatformServiceLocator.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Rendering;
|
||||
using Avalonia;
|
||||
using Avalonia.VisualTree;
|
||||
|
||||
namespace Harmonia.UI.Platform;
|
||||
|
||||
public abstract class PlatformServiceLocator<T> : IPlatformServiceLocator<T>
|
||||
{
|
||||
public T? Get()
|
||||
{
|
||||
//Desktop
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
if (desktop.MainWindow == null)
|
||||
return default;
|
||||
|
||||
return GetFromWindow(desktop.MainWindow);
|
||||
}
|
||||
//Android (and iOS?)
|
||||
else if (Application.Current?.ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
|
||||
{
|
||||
if (singleViewPlatform.MainView == null)
|
||||
return default;
|
||||
|
||||
IRenderRoot? visualRoot = singleViewPlatform.MainView.GetVisualRoot();
|
||||
|
||||
if (visualRoot is TopLevel topLevel)
|
||||
{
|
||||
return GetFromTopLevel(topLevel);
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
protected abstract T? GetFromWindow(Window mainWindow);
|
||||
protected abstract T? GetFromTopLevel(TopLevel topLevel);
|
||||
}
|
||||
17
Harmonia.UI/Platform/StorageProviderLocator.cs
Normal file
17
Harmonia.UI/Platform/StorageProviderLocator.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
|
||||
namespace Harmonia.UI.Platform;
|
||||
|
||||
public class StorageProviderLocator : PlatformServiceLocator<IStorageProvider>, IStorageProviderLocator
|
||||
{
|
||||
protected override IStorageProvider? GetFromWindow(Window mainWindow)
|
||||
{
|
||||
return mainWindow.StorageProvider;
|
||||
}
|
||||
|
||||
protected override IStorageProvider? GetFromTopLevel(TopLevel topLevel)
|
||||
{
|
||||
return topLevel.StorageProvider;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user