iOSPlatform.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Reflection;
  3. using Avalonia.Input;
  4. using Avalonia.Input.Platform;
  5. using Avalonia.iOS;
  6. using Avalonia.Platform;
  7. using Avalonia.Shared.PlatformSupport;
  8. using Avalonia.Skia;
  9. using UIKit;
  10. using Avalonia.Controls;
  11. using Avalonia.Rendering;
  12. namespace Avalonia
  13. {
  14. public static class iOSApplicationExtensions
  15. {
  16. public static T UseiOS<T>(this T builder) where T : AppBuilderBase<T>, new()
  17. {
  18. builder.UseWindowingSubsystem(iOSPlatform.Initialize, "iOS");
  19. return builder;
  20. }
  21. /*
  22. // TODO: Can we merge this with UseSkia somehow once HW/platform cleanup is done?
  23. public static T UseSkiaViewHost<T>(this T builder) where T : AppBuilderBase<T>, new()
  24. {
  25. var window = new UIWindow(UIScreen.MainScreen.Bounds);
  26. var controller = new AvaloniaViewController(window);
  27. window.RootViewController = controller;
  28. window.MakeKeyAndVisible();
  29. AvaloniaLocator.CurrentMutable
  30. .Bind<IWindowingPlatform>().ToConstant(new WindowingPlatformImpl(controller.AvaloniaView));
  31. SkiaPlatform.Initialize();
  32. return builder;
  33. }*/
  34. }
  35. }
  36. namespace Avalonia.iOS
  37. {
  38. public class iOSPlatform
  39. {
  40. internal static MouseDevice MouseDevice;
  41. internal static KeyboardDevice KeyboardDevice;
  42. public static void Initialize()
  43. {
  44. MouseDevice = new MouseDevice();
  45. KeyboardDevice = new KeyboardDevice();
  46. AvaloniaLocator.CurrentMutable
  47. .Bind<IRuntimePlatform>().ToSingleton<StandardRuntimePlatform>()
  48. .Bind<IClipboard>().ToTransient<Clipboard>()
  49. // TODO: what does this look like for iOS??
  50. //.Bind<ISystemDialogImpl>().ToTransient<SystemDialogImpl>()
  51. .Bind<IStandardCursorFactory>().ToTransient<CursorFactory>()
  52. .Bind<IKeyboardDevice>().ToConstant(KeyboardDevice)
  53. .Bind<IMouseDevice>().ToConstant(MouseDevice)
  54. .Bind<IRendererFactory>().ToConstant(ImmediateRenderer.Factory)
  55. .Bind<IPlatformSettings>().ToSingleton<PlatformSettings>()
  56. .Bind<IPlatformThreadingInterface>().ToConstant(PlatformThreadingInterface.Instance)
  57. .Bind<IPlatformIconLoader>().ToSingleton<PlatformIconLoader>()
  58. .Bind<IWindowingPlatform>().ToSingleton<WindowingPlatformImpl>()
  59. .Bind<IRenderLoop>().ToSingleton<DisplayLinkRenderLoop>();
  60. }
  61. }
  62. }