diff --git a/src/Compatibility/ControlGallery/src/Core/App.cs b/src/Compatibility/ControlGallery/src/Core/App.cs index bb41b7a20064..f16124425a0a 100644 --- a/src/Compatibility/ControlGallery/src/Core/App.cs +++ b/src/Compatibility/ControlGallery/src/Core/App.cs @@ -33,11 +33,15 @@ public App() { _testCloudService = DependencyService.Get(); - SetMainPage(CreateDefaultMainPage()); - //TestMainPageSwitches(); - //SetMainPage(new ImageSourcesGallery()); + if (Device.RuntimePlatform != Device.iOS) + SetMainPage(new ImageSourcesGallery()); + } + + protected override IWindow CreateWindow(IActivationState activationState) + { + return new Window(CreateDefaultMainPage()); } protected override void OnStart() diff --git a/src/Compatibility/ControlGallery/src/Core/Compatibility.ControlGallery.Core-net6.csproj b/src/Compatibility/ControlGallery/src/Core/Compatibility.ControlGallery.Core-net6.csproj index b0181fb7ffa8..7df8956c6e2b 100644 --- a/src/Compatibility/ControlGallery/src/Core/Compatibility.ControlGallery.Core-net6.csproj +++ b/src/Compatibility/ControlGallery/src/Core/Compatibility.ControlGallery.Core-net6.csproj @@ -123,6 +123,7 @@ + diff --git a/src/Compatibility/ControlGallery/src/Core/Startup.cs b/src/Compatibility/ControlGallery/src/Core/Startup.cs new file mode 100644 index 000000000000..5ed2effa2aab --- /dev/null +++ b/src/Compatibility/ControlGallery/src/Core/Startup.cs @@ -0,0 +1,35 @@ +using Microsoft.Maui; +using Microsoft.Maui.Controls.Compatibility; +using Microsoft.Maui.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Maui.Controls.Hosting; + +namespace Microsoft.Maui.Controls.Compatibility.ControlGallery +{ + public class Startup : IStartup + { + internal static bool UseBlazor = false; + + public void Configure(IAppHostBuilder appBuilder) + { + appBuilder + .UseMauiApp() + .ConfigureMauiHandlers(handlers => + { + handlers.AddCompatibilityRenderers(Device.GetAssemblies()); + }) + .ConfigureImageSources(sources => + { + sources.AddCompatibilityServices(Device.GetAssemblies()); + }) + .ConfigureFonts(fonts => + { + fonts.AddCompatibilityFonts(Device.GetAssemblies()); + }) + .ConfigureServices(services => + { + DependencyService.Register(Device.GetAssemblies()); + }); + } + } +} diff --git a/src/Compatibility/ControlGallery/src/Issues.Shared/Helpers/ViewHelper.cs b/src/Compatibility/ControlGallery/src/Issues.Shared/Helpers/ViewHelper.cs index 7cdb62ce58d6..7f27698617c4 100644 --- a/src/Compatibility/ControlGallery/src/Issues.Shared/Helpers/ViewHelper.cs +++ b/src/Compatibility/ControlGallery/src/Issues.Shared/Helpers/ViewHelper.cs @@ -43,9 +43,6 @@ public static List GetAllPages() { var controls = new List { -#pragma warning disable CS0618 // Type or member is obsolete - new MasterDetailPage { Master = new Page { Title = "Flyout" }, Detail = new Page() }, -#pragma warning restore CS0618 // Type or member is obsolete new FlyoutPage { Flyout = new Page { Title = "Flyout" }, Detail = new Page() }, new NavigationPage(new Page()), new Page(), diff --git a/src/Compatibility/ControlGallery/src/WinUI/BrokenImageSourceHandler.cs b/src/Compatibility/ControlGallery/src/WinUI/BrokenImageSourceHandler.cs index ab507fc5c220..184aae5bd688 100644 --- a/src/Compatibility/ControlGallery/src/WinUI/BrokenImageSourceHandler.cs +++ b/src/Compatibility/ControlGallery/src/WinUI/BrokenImageSourceHandler.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.Maui.Controls.Compatibility; using Microsoft.Maui.Controls.Compatibility.ControlGallery.Issues; using Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI; using Microsoft.Maui.Controls.Compatibility.Platform.UWP; diff --git a/src/Compatibility/ControlGallery/src/WinUI/CustomRenderers.cs b/src/Compatibility/ControlGallery/src/WinUI/CustomRenderers.cs index 53373a8c3609..5f3aefcd9218 100644 --- a/src/Compatibility/ControlGallery/src/WinUI/CustomRenderers.cs +++ b/src/Compatibility/ControlGallery/src/WinUI/CustomRenderers.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Linq; using Microsoft.Maui; +using Microsoft.Maui.Controls.Compatibility; using Microsoft.Maui.Controls.Compatibility.ControlGallery.Issues; using Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI; using Microsoft.Maui.Controls.Compatibility.Platform.UWP; diff --git a/src/Compatibility/ControlGallery/src/WinUI/CustomSwitchRenderer.cs b/src/Compatibility/ControlGallery/src/WinUI/CustomSwitchRenderer.cs index 6eabb356bee5..947ae9882a1a 100644 --- a/src/Compatibility/ControlGallery/src/WinUI/CustomSwitchRenderer.cs +++ b/src/Compatibility/ControlGallery/src/WinUI/CustomSwitchRenderer.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using Microsoft.Maui.Controls.Compatibility; using Microsoft.Maui.Controls.Compatibility.ControlGallery.Issues; using Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI; using Microsoft.Maui.Controls.Compatibility.Platform.UWP; diff --git a/src/Compatibility/ControlGallery/src/WinUI/DisposePageRenderer.cs b/src/Compatibility/ControlGallery/src/WinUI/DisposePageRenderer.cs index 1ddcda2aaa79..5bbb341b0ea6 100644 --- a/src/Compatibility/ControlGallery/src/WinUI/DisposePageRenderer.cs +++ b/src/Compatibility/ControlGallery/src/WinUI/DisposePageRenderer.cs @@ -1,3 +1,4 @@ +using Microsoft.Maui.Controls.Compatibility; using Microsoft.Maui.Controls.Compatibility.ControlGallery; using Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI; using Microsoft.Maui.Controls.Compatibility.Platform.UWP; diff --git a/src/Compatibility/ControlGallery/src/WinUI/NavPageOverrideRenderer.cs b/src/Compatibility/ControlGallery/src/WinUI/NavPageOverrideRenderer.cs index bfa1ef8eb178..858179d9934c 100644 --- a/src/Compatibility/ControlGallery/src/WinUI/NavPageOverrideRenderer.cs +++ b/src/Compatibility/ControlGallery/src/WinUI/NavPageOverrideRenderer.cs @@ -1,4 +1,5 @@ using Microsoft.Maui.Controls; +using Microsoft.Maui.Controls.Compatibility; using Microsoft.Maui.Controls.Compatibility.ControlGallery.Issues; using Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI; using Microsoft.Maui.Controls.Compatibility.Platform.UWP; diff --git a/src/Compatibility/ControlGallery/src/WinUI/Properties/AssemblyInfo.cs b/src/Compatibility/ControlGallery/src/WinUI/Properties/AssemblyInfo.cs index c9c71ef677c6..dde6c3f4a41e 100644 --- a/src/Compatibility/ControlGallery/src/WinUI/Properties/AssemblyInfo.cs +++ b/src/Compatibility/ControlGallery/src/WinUI/Properties/AssemblyInfo.cs @@ -2,6 +2,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Microsoft.Maui.Controls; +using Microsoft.Maui.Controls.Compatibility; using Microsoft.Maui.Controls.Compatibility.ControlGallery; using Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI; using Microsoft.Maui.Controls.Compatibility.Platform.UWP; diff --git a/src/Compatibility/ControlGallery/src/WinUI/_2489CustomRenderer.cs b/src/Compatibility/ControlGallery/src/WinUI/_2489CustomRenderer.cs index dfbc5f7b0fdd..b45a261ed29e 100644 --- a/src/Compatibility/ControlGallery/src/WinUI/_2489CustomRenderer.cs +++ b/src/Compatibility/ControlGallery/src/WinUI/_2489CustomRenderer.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using Microsoft.Maui.Controls; +using Microsoft.Maui.Controls.Compatibility; using Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI; using Microsoft.Maui.Controls.Compatibility.Platform.UWP; using Microsoft.Maui.Controls.Platform; diff --git a/src/Compatibility/ControlGallery/src/WinUI/_57114Renderer.cs b/src/Compatibility/ControlGallery/src/WinUI/_57114Renderer.cs index 6e972e97c411..96eb882cb4e6 100644 --- a/src/Compatibility/ControlGallery/src/WinUI/_57114Renderer.cs +++ b/src/Compatibility/ControlGallery/src/WinUI/_57114Renderer.cs @@ -1,3 +1,4 @@ +using Microsoft.Maui.Controls.Compatibility; using Microsoft.Maui.Controls.Compatibility.ControlGallery.Issues; using Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI; using Microsoft.Maui.Controls.Compatibility.Platform.UWP; diff --git a/src/Compatibility/ControlGallery/src/WinUI/_60122ImageRenderer.cs b/src/Compatibility/ControlGallery/src/WinUI/_60122ImageRenderer.cs index c0bbda4c7396..264f0abe60bc 100644 --- a/src/Compatibility/ControlGallery/src/WinUI/_60122ImageRenderer.cs +++ b/src/Compatibility/ControlGallery/src/WinUI/_60122ImageRenderer.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.Maui.Controls.Compatibility; using Microsoft.Maui.Controls.Compatibility.ControlGallery.Issues; using Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI; using Microsoft.Maui.Controls.Compatibility.Platform.UWP; diff --git a/src/Compatibility/ControlGallery/src/WinUI/_9087CustomRenderer.cs b/src/Compatibility/ControlGallery/src/WinUI/_9087CustomRenderer.cs index 3c1be43f7518..03348a79ab00 100644 --- a/src/Compatibility/ControlGallery/src/WinUI/_9087CustomRenderer.cs +++ b/src/Compatibility/ControlGallery/src/WinUI/_9087CustomRenderer.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.Maui.Controls.Compatibility; using Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI; using Microsoft.Maui.Controls.Compatibility.Platform.UWP; using Microsoft.Maui.Controls.Platform; diff --git a/src/Compatibility/ControlGallery/src/iOS/AppDelegate.cs b/src/Compatibility/ControlGallery/src/iOS/AppDelegate.cs index 94a290da10b3..a4e9f0abac93 100644 --- a/src/Compatibility/ControlGallery/src/iOS/AppDelegate.cs +++ b/src/Compatibility/ControlGallery/src/iOS/AppDelegate.cs @@ -99,10 +99,8 @@ public string GetTestCloudDevice() } [Register("AppDelegate")] - public partial class AppDelegate : FormsApplicationDelegate + public partial class AppDelegate : MauiUIApplicationDelegate { - App _app; - public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions) { UISwitch.Appearance.OnTintColor = UIColor.Red; @@ -113,8 +111,8 @@ public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary Xamarin.Calabash.Start(); #endif - Forms.Init(); - FormsMaps.Init(); + //Forms.Init(); + //FormsMaps.Init(); //FormsMaterial.Init(); Forms.ViewInitialized += (object sender, ViewInitializedEventArgs e) => @@ -136,9 +134,6 @@ public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary }; } - var app = new App(); - _app = app; - // When the native control gallery loads up, it'll let us know so we can add the nested native controls MessagingCenter.Subscribe(this, NestedNativeControlGalleryPage.ReadyForNativeControlsMessage, AddNativeControls); MessagingCenter.Subscribe(this, Bugzilla40911.ReadyToSetUp40911Test, SetUp40911Test); @@ -150,8 +145,6 @@ public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary // When the native binding gallery loads up, it'll let us know so we can set up the native bindings MessagingCenter.Subscribe(this, NativeBindingGalleryPage.ReadyForNativeBindingsMessage, AddNativeBindings); - LoadApplication(app); - return base.FinishedLaunching(uiApplication, launchOptions); } @@ -351,13 +344,13 @@ public string NavigateToTest(string test) { // According to https://developer.xamarin.com/guides/testcloud/uitest/working-with/backdoors/ // this method has to return a string - return _app.NavigateToTestPage(test).ToString(); + return (Microsoft.Maui.Controls.Application.Current as App).NavigateToTestPage(test).ToString(); } [Export("reset:")] public string Reset(string str) { - _app.Reset(); + (Microsoft.Maui.Controls.Application.Current as App).Reset(); return String.Empty; } diff --git a/src/Compatibility/Core/src/Android/ExportCellAttribute.cs b/src/Compatibility/Core/src/Android/ExportCellAttribute.cs deleted file mode 100644 index f351795fcd81..000000000000 --- a/src/Compatibility/Core/src/Android/ExportCellAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Microsoft.Maui.Controls.Compatibility -{ - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class ExportCellAttribute : HandlerAttribute - { - public ExportCellAttribute(Type handler, Type target) : base(handler, target) - { - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Android/ExportImageSourceHandlerAttribute.cs b/src/Compatibility/Core/src/Android/ExportImageSourceHandlerAttribute.cs deleted file mode 100644 index e279218cd34c..000000000000 --- a/src/Compatibility/Core/src/Android/ExportImageSourceHandlerAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Microsoft.Maui.Controls.Compatibility -{ - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class ExportImageSourceHandlerAttribute : HandlerAttribute - { - public ExportImageSourceHandlerAttribute(Type handler, Type target) : base(handler, target) - { - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Android/ExportRendererAttribute.cs b/src/Compatibility/Core/src/Android/ExportRendererAttribute.cs deleted file mode 100644 index 8ed06aca5672..000000000000 --- a/src/Compatibility/Core/src/Android/ExportRendererAttribute.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace Microsoft.Maui.Controls.Compatibility -{ - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class ExportRendererAttribute : HandlerAttribute - { - public ExportRendererAttribute(Type handler, Type target) : this(handler, target, null) - { - } - - public ExportRendererAttribute(Type handler, Type target, Type[] supportedVisuals) : base(handler, target, supportedVisuals) - { - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Android/Forms.cs b/src/Compatibility/Core/src/Android/Forms.cs index e2a1f8a3b823..45bacc076eeb 100644 --- a/src/Compatibility/Core/src/Android/Forms.cs +++ b/src/Compatibility/Core/src/Android/Forms.cs @@ -258,29 +258,6 @@ internal static void RenderersRegistered() IsInitializedRenderers = true; } - internal static void RegisterCompatRenderers( - Assembly[] assemblies, - Assembly defaultRendererAssembly, - Action viewRegistered) - { - if (IsInitializedRenderers) - return; - - IsInitializedRenderers = true; - - // Only need to do this once - Registrar.RegisterAll( - assemblies, - defaultRendererAssembly, - new[] { - typeof(ExportRendererAttribute), - typeof(ExportCellAttribute), - typeof(ExportImageSourceHandlerAttribute), - typeof(ExportFontAttribute) - }, default(InitializationFlags), - viewRegistered); - } - internal static void RegisterCompatRenderers(InitializationOptions? maybeOptions) { if (!IsInitializedRenderers) diff --git a/src/Compatibility/Core/src/Android/Properties/AssemblyInfo.cs b/src/Compatibility/Core/src/Android/Properties/AssemblyInfo.cs index 70bb22191f8f..231ef479c6ac 100644 --- a/src/Compatibility/Core/src/Android/Properties/AssemblyInfo.cs +++ b/src/Compatibility/Core/src/Android/Properties/AssemblyInfo.cs @@ -1,71 +1,6 @@ using System.Runtime.CompilerServices; -using Microsoft.Maui.Controls; -using Microsoft.Maui.Controls.Compatibility; -using Microsoft.Maui.Controls.Compatibility.Platform.Android; -using Microsoft.Maui.Controls.Compatibility.Platform.Android.AppCompat; using Microsoft.Maui.Controls.Internals; -using Microsoft.Maui.Controls.Shapes; -[assembly: ExportRenderer(typeof(BoxView), typeof(BoxRenderer))] -[assembly: ExportRenderer(typeof(Entry), typeof(EntryRenderer))] -[assembly: ExportRenderer(typeof(Editor), typeof(EditorRenderer))] -[assembly: ExportRenderer(typeof(Label), typeof(Microsoft.Maui.Controls.Compatibility.Platform.Android.FastRenderers.LabelRenderer))] -[assembly: ExportRenderer(typeof(Image), typeof(ImageRenderer))] -[assembly: ExportRenderer(typeof(Button), typeof(Microsoft.Maui.Controls.Compatibility.Platform.Android.FastRenderers.ButtonRenderer))] -[assembly: ExportRenderer(typeof(ImageButton), typeof(ImageButtonRenderer))] -[assembly: ExportRenderer(typeof(TableView), typeof(TableViewRenderer))] -[assembly: ExportRenderer(typeof(ListView), typeof(ListViewRenderer))] -[assembly: ExportRenderer(typeof(CollectionView), typeof(CollectionViewRenderer))] -[assembly: ExportRenderer(typeof(CarouselView), typeof(CarouselViewRenderer))] -[assembly: ExportRenderer(typeof(IndicatorView), typeof(IndicatorViewRenderer))] -[assembly: ExportRenderer(typeof(Path), typeof(PathRenderer))] -[assembly: ExportRenderer(typeof(Ellipse), typeof(EllipseRenderer))] -[assembly: ExportRenderer(typeof(Line), typeof(LineRenderer))] -[assembly: ExportRenderer(typeof(Polyline), typeof(PolylineRenderer))] -[assembly: ExportRenderer(typeof(Polygon), typeof(PolygonRenderer))] -[assembly: ExportRenderer(typeof(Rectangle), typeof(RectangleRenderer))] -[assembly: ExportRenderer(typeof(RadioButton), typeof(RadioButtonRenderer))] -[assembly: ExportRenderer(typeof(Slider), typeof(SliderRenderer))] -[assembly: ExportRenderer(typeof(WebView), typeof(WebViewRenderer))] -[assembly: ExportRenderer(typeof(SearchBar), typeof(SearchBarRenderer))] -[assembly: ExportRenderer(typeof(Switch), typeof(SwitchRenderer))] -[assembly: ExportRenderer(typeof(SwipeView), typeof(SwipeViewRenderer))] -[assembly: ExportRenderer(typeof(DatePicker), typeof(DatePickerRenderer))] -[assembly: ExportRenderer(typeof(TimePicker), typeof(TimePickerRenderer))] -[assembly: ExportRenderer(typeof(Picker), typeof(PickerRenderer))] -[assembly: ExportRenderer(typeof(Stepper), typeof(StepperRenderer))] -[assembly: ExportRenderer(typeof(ProgressBar), typeof(ProgressBarRenderer))] -[assembly: ExportRenderer(typeof(ScrollView), typeof(ScrollViewRenderer))] -[assembly: ExportRenderer(typeof(ActivityIndicator), typeof(ActivityIndicatorRenderer))] -[assembly: ExportRenderer(typeof(Frame), typeof(Microsoft.Maui.Controls.Compatibility.Platform.Android.FastRenderers.FrameRenderer))] -[assembly: ExportRenderer(typeof(OpenGLView), typeof(OpenGLViewRenderer))] -[assembly: ExportRenderer(typeof(CheckBox), typeof(CheckBoxRenderer))] - -[assembly: ExportRenderer(typeof(TabbedPage), typeof(TabbedPageRenderer))] -[assembly: ExportRenderer(typeof(NavigationPage), typeof(NavigationPageRenderer))] -[assembly: ExportRenderer(typeof(CarouselPage), typeof(CarouselPageRenderer))] -[assembly: ExportRenderer(typeof(Page), typeof(PageRenderer))] -[assembly: ExportRenderer(typeof(FlyoutPage), typeof(FlyoutPageRenderer))] -[assembly: ExportRenderer(typeof(RefreshView), typeof(RefreshViewRenderer))] - - - -[assembly: ExportRenderer(typeof(Shell), typeof(ShellRenderer))] - -[assembly: ExportRenderer(typeof(NativeViewWrapper), typeof(NativeViewWrapperRenderer))] -[assembly: ExportCell(typeof(Cell), typeof(CellRenderer))] -[assembly: ExportCell(typeof(EntryCell), typeof(EntryCellRenderer))] -[assembly: ExportCell(typeof(SwitchCell), typeof(SwitchCellRenderer))] -[assembly: ExportCell(typeof(TextCell), typeof(TextCellRenderer))] -[assembly: ExportCell(typeof(ImageCell), typeof(ImageCellRenderer))] -[assembly: ExportCell(typeof(ViewCell), typeof(ViewCellRenderer))] -[assembly: ExportRenderer(typeof(Microsoft.Maui.EmbeddedFont), typeof(Microsoft.Maui.EmbeddedFontLoader))] -[assembly: ExportImageSourceHandler(typeof(FileImageSource), typeof(FileImageSourceHandler))] -[assembly: ExportImageSourceHandler(typeof(StreamImageSource), typeof(StreamImagesourceHandler))] -[assembly: ExportImageSourceHandler(typeof(UriImageSource), typeof(ImageLoaderSourceHandler))] -[assembly: ExportImageSourceHandler(typeof(FontImageSource), typeof(FontImageSourceHandler))] -[assembly: Microsoft.Maui.Controls.Dependency(typeof(Deserializer))] -[assembly: Microsoft.Maui.Controls.Dependency(typeof(ResourcesProvider))] [assembly: Preserve] [assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Compatibility.Platform")] [assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Compatibility.Material")] diff --git a/src/Compatibility/Core/src/AppHostBuilderExtensions.cs b/src/Compatibility/Core/src/AppHostBuilderExtensions.cs index 561a6c777a6f..45f7649e5518 100644 --- a/src/Compatibility/Core/src/AppHostBuilderExtensions.cs +++ b/src/Compatibility/Core/src/AppHostBuilderExtensions.cs @@ -11,6 +11,7 @@ using LabelRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Android.FastRenderers.LabelRenderer; using ImageRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Android.FastRenderers.ImageRenderer; using ButtonRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Android.FastRenderers.ButtonRenderer; +using DefaultRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Android.AppCompat.Platform.DefaultRenderer; #elif WINDOWS using Microsoft.Maui.Controls.Compatibility.Platform.UWP; using BoxRenderer = Microsoft.Maui.Controls.Compatibility.Platform.UWP.BoxViewBorderRenderer; @@ -19,6 +20,7 @@ using ResourcesProvider = Microsoft.Maui.Controls.Compatibility.Platform.UWP.WindowsResourcesProvider; using StreamImagesourceHandler = Microsoft.Maui.Controls.Compatibility.Platform.UWP.StreamImageSourceHandler; using ImageLoaderSourceHandler = Microsoft.Maui.Controls.Compatibility.Platform.UWP.UriImageSourceHandler; +using DefaultRenderer = Microsoft.Maui.Controls.Compatibility.Platform.UWP.DefaultRenderer; #elif __IOS__ using Microsoft.Maui.Controls.Compatibility.Platform.iOS; @@ -27,6 +29,7 @@ using TabbedPageRenderer = Microsoft.Maui.Controls.Compatibility.Platform.iOS.TabbedRenderer; using FlyoutPageRenderer = Microsoft.Maui.Controls.Compatibility.Platform.iOS.PhoneFlyoutPageRenderer; using RadioButtonRenderer = Microsoft.Maui.Controls.Compatibility.Platform.iOS.Platform.DefaultRenderer; +using DefaultRenderer = Microsoft.Maui.Controls.Compatibility.Platform.iOS.Platform.DefaultRenderer; #endif using Microsoft.Maui.Hosting; @@ -162,7 +165,6 @@ static IAppHostBuilder SetupDefaults(this IAppHostBuilder builder) #if __ANDROID__ || __IOS__ || WINDOWS || MACCATALYST - Forms.RenderersRegistered(); handlers.TryAddCompatibilityRenderer(typeof(BoxView), typeof(BoxRenderer)); handlers.TryAddCompatibilityRenderer(typeof(Entry), typeof(EntryRenderer)); handlers.TryAddCompatibilityRenderer(typeof(Editor), typeof(EditorRenderer)); @@ -215,6 +217,14 @@ static IAppHostBuilder SetupDefaults(this IAppHostBuilder builder) handlers.TryAddCompatibilityRenderer(typeof(TextCell), typeof(TextCellRenderer)); handlers.TryAddCompatibilityRenderer(typeof(ViewCell), typeof(ViewCellRenderer)); handlers.TryAddCompatibilityRenderer(typeof(SwitchCell), typeof(SwitchCellRenderer)); + + // This is for Layouts that currently don't work when assigned to LayoutHandler + handlers.TryAddCompatibilityRenderer(typeof(ContentView), typeof(DefaultRenderer)); +#if __IOS__ + handlers.TryAddCompatibilityRenderer(typeof(AbsoluteLayout), typeof(DefaultRenderer)); +#endif + + DependencyService.Register(); DependencyService.Register(); DependencyService.Register(); diff --git a/src/Compatibility/Core/src/Compatibility-net6.csproj b/src/Compatibility/Core/src/Compatibility-net6.csproj index adcda46cb09d..0dac3bb87d62 100644 --- a/src/Compatibility/Core/src/Compatibility-net6.csproj +++ b/src/Compatibility/Core/src/Compatibility-net6.csproj @@ -33,7 +33,7 @@ - + @@ -60,20 +60,21 @@ - + - + + diff --git a/src/Compatibility/Core/src/Compatibility.csproj b/src/Compatibility/Core/src/Compatibility.csproj index 0783981e48e5..8206d4ef9311 100644 --- a/src/Compatibility/Core/src/Compatibility.csproj +++ b/src/Compatibility/Core/src/Compatibility.csproj @@ -44,7 +44,7 @@ - + @@ -56,12 +56,13 @@ - + + diff --git a/src/Compatibility/Core/src/WinUI/ExportRendererAttribute.cs b/src/Compatibility/Core/src/ExportRendererAttribute.cs similarity index 93% rename from src/Compatibility/Core/src/WinUI/ExportRendererAttribute.cs rename to src/Compatibility/Core/src/ExportRendererAttribute.cs index dfad5b07229d..212130be8af0 100644 --- a/src/Compatibility/Core/src/WinUI/ExportRendererAttribute.cs +++ b/src/Compatibility/Core/src/ExportRendererAttribute.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.Maui.Controls.Compatibility.Platform.UWP +namespace Microsoft.Maui.Controls.Compatibility { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] public sealed class ExportRendererAttribute : HandlerAttribute diff --git a/src/Compatibility/Core/src/MauiHandlersCollectionExtensions.cs b/src/Compatibility/Core/src/MauiHandlersCollectionExtensions.cs index b4383e38f9bf..d71a032c863e 100644 --- a/src/Compatibility/Core/src/MauiHandlersCollectionExtensions.cs +++ b/src/Compatibility/Core/src/MauiHandlersCollectionExtensions.cs @@ -1,5 +1,4 @@ using System; -using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Hosting; namespace Microsoft.Maui.Controls.Compatibility @@ -46,5 +45,61 @@ public static IMauiHandlersCollection AddCompatibilityRenderer + { + handlersCollection?.TryAddHandler(result.target, typeof(RendererToHandlerShim)); + }); +#endif + + + return handlersCollection; + } + + public static IFontCollection AddCompatibilityFonts(this IFontCollection fontCollection, params global::System.Reflection.Assembly[] assemblies) + { + Internals.Registrar.RegisterAll( + assemblies, + null, + new[] + { + typeof(ExportFontAttribute) + }, default(InitializationFlags), + null); + return fontCollection; + } + + public static IImageSourceServiceCollection AddCompatibilityServices(this IImageSourceServiceCollection services, params global::System.Reflection.Assembly[] assemblies) + { + +#if __ANDROID__ || __IOS__ || WINDOWS || MACCATALYST + Internals.Registrar.RegisterAll( + assemblies, + null, + new[] + { + typeof(ExportImageSourceHandlerAttribute) + }, default(InitializationFlags), + (result) => + { + // TODO MAUI: need to fill in registration of a service + // that can map legacy image handlers to new image service structures + }); +#endif + return services; + } } } \ No newline at end of file diff --git a/src/Compatibility/Core/src/WinUI/Forms.cs b/src/Compatibility/Core/src/WinUI/Forms.cs index 888f435d990d..079b1374883d 100644 --- a/src/Compatibility/Core/src/WinUI/Forms.cs +++ b/src/Compatibility/Core/src/WinUI/Forms.cs @@ -134,9 +134,6 @@ static void SetupInit( Device.PlatformServices = platformServices; Device.PlatformInvalidator = platformServices; - if (maybeOptions?.Flags.HasFlag(InitializationFlags.SkipRenderers) != true) - RegisterCompatRenderers(); - if (mainWindow != null) { MainWindow = mainWindow; @@ -151,54 +148,6 @@ static void SetupInit( IsInitialized = true; } - static bool IsInitializedRenderers; - - // Once we get essentials/cg converted to using startup.cs - // we will delete all the renderer code inside this file - internal static void RenderersRegistered() - { - IsInitializedRenderers = true; - } - internal static void RegisterCompatRenderers() - { - if (IsInitializedRenderers) - return; - - IsInitializedRenderers = true; - - // Only need to do this once - Registrar.RegisterAll(new[] - { - typeof(ExportRendererAttribute), - typeof(ExportCellAttribute), - typeof(ExportImageSourceHandlerAttribute), - typeof(ExportFontAttribute) - }); - } - - internal static void RegisterCompatRenderers( - Assembly[] assemblies, - Assembly defaultRendererAssembly, - Action viewRegistered) - { - if (IsInitializedRenderers) - return; - - IsInitializedRenderers = true; - - // Only need to do this once - Controls.Internals.Registrar.RegisterAll( - assemblies, - defaultRendererAssembly, - new[] { - typeof(ExportRendererAttribute), - typeof(ExportCellAttribute), - typeof(ExportImageSourceHandlerAttribute), - typeof(ExportFontAttribute) - }, default(InitializationFlags), - viewRegistered); - } - static FlowDirection GetFlowDirection() { string resourceFlowDirection = "LTR"; //TODO WINUI3 ResourceContext.GetForCurrentView().QualifierValues["LayoutDirection"]; diff --git a/src/Compatibility/Core/src/WinUI/Properties/AssemblyInfo.cs b/src/Compatibility/Core/src/WinUI/Properties/AssemblyInfo.cs index 5026859c2ccb..d607f305d908 100644 --- a/src/Compatibility/Core/src/WinUI/Properties/AssemblyInfo.cs +++ b/src/Compatibility/Core/src/WinUI/Properties/AssemblyInfo.cs @@ -6,79 +6,6 @@ using Microsoft.Maui.Controls.Shapes; using Rectangle = Microsoft.Maui.Controls.Shapes.Rectangle; -[assembly: Dependency(typeof(WindowsSerializer))] - // Views - -[assembly: ExportRenderer(typeof(Layout), typeof(LayoutRenderer))] -[assembly: ExportRenderer(typeof(BoxView), typeof(BoxViewBorderRenderer))] -[assembly: ExportRenderer(typeof(Image), typeof(ImageRenderer))] -[assembly: ExportRenderer(typeof(ImageButton), typeof(ImageButtonRenderer))] -[assembly: ExportRenderer(typeof(Label), typeof(LabelRenderer))] -[assembly: ExportRenderer(typeof(Button), typeof(ButtonRenderer))] -[assembly: ExportRenderer(typeof(RadioButton), typeof(RadioButtonRenderer))] -[assembly: ExportRenderer(typeof(ListView), typeof(ListViewRenderer))] -[assembly: ExportRenderer(typeof(CarouselView), typeof(CarouselViewRenderer))] -[assembly: ExportRenderer(typeof(IndicatorView), typeof(IndicatorViewRenderer))] -[assembly: ExportRenderer(typeof(CollectionView), typeof(CollectionViewRenderer))] -[assembly: ExportRenderer(typeof(ScrollView), typeof(ScrollViewRenderer))] -[assembly: ExportRenderer(typeof(ProgressBar), typeof(ProgressBarRenderer))] -[assembly: ExportRenderer(typeof(Slider), typeof(SliderRenderer))] -[assembly: ExportRenderer(typeof(Switch), typeof(SwitchRenderer))] -[assembly: ExportRenderer(typeof(SwipeView), typeof(SwipeViewRenderer))] -[assembly: ExportRenderer(typeof(WebView), typeof(WebViewRenderer))] -[assembly: ExportRenderer(typeof(Frame), typeof(FrameRenderer))] -[assembly: ExportRenderer(typeof(ActivityIndicator), typeof(ActivityIndicatorRenderer))] -[assembly: ExportRenderer(typeof(Editor), typeof(EditorRenderer))] -[assembly: ExportRenderer(typeof(Picker), typeof(PickerRenderer))] -[assembly: ExportRenderer(typeof(TimePicker), typeof(TimePickerRenderer))] -[assembly: ExportRenderer(typeof(DatePicker), typeof(DatePickerRenderer))] -[assembly: ExportRenderer(typeof(Stepper), typeof(StepperRenderer))] -[assembly: ExportRenderer(typeof(Entry), typeof(EntryRenderer))] -[assembly: ExportRenderer(typeof(CheckBox), typeof(CheckBoxRenderer))] -[assembly: ExportRenderer(typeof(TableView), typeof(TableViewRenderer))] -[assembly: ExportRenderer(typeof(NativeViewWrapper), typeof(NativeViewWrapperRenderer))] -[assembly: ExportRenderer(typeof(RefreshView), typeof(RefreshViewRenderer))] -[assembly: ExportRenderer(typeof(Path), typeof(PathRenderer))] -[assembly: ExportRenderer(typeof(Ellipse), typeof(EllipseRenderer))] -[assembly: ExportRenderer(typeof(Line), typeof(LineRenderer))] -[assembly: ExportRenderer(typeof(Polygon), typeof(PolygonRenderer))] -[assembly: ExportRenderer(typeof(Polyline), typeof(PolylineRenderer))] -[assembly: ExportRenderer(typeof(Rectangle), typeof(RectangleRenderer))] -[assembly: ExportRenderer(typeof(IndicatorView), typeof(IndicatorViewRenderer))] -[assembly: ExportRenderer(typeof(RadioButton), typeof(RadioButtonRenderer))] - -//ImageSources - -[assembly: ExportImageSourceHandler(typeof(FileImageSource), typeof(FileImageSourceHandler))] -[assembly: ExportImageSourceHandler(typeof(StreamImageSource), typeof(StreamImageSourceHandler))] -[assembly: ExportImageSourceHandler(typeof(UriImageSource), typeof(UriImageSourceHandler))] -[assembly: ExportImageSourceHandler(typeof(FontImageSource), typeof(FontImageSourceHandler))] - -// Pages - -[assembly: ExportRenderer(typeof(Page), typeof(PageRenderer))] -[assembly: ExportRenderer(typeof(NavigationPage), typeof(NavigationPageRenderer))] -[assembly: ExportRenderer(typeof(FlyoutPage), typeof(FlyoutPageRenderer))] -#pragma warning disable CS0618 // Type or member is obsolete -[assembly: ExportRenderer(typeof(MasterDetailPage), typeof(MasterDetailPageRenderer))] -#pragma warning restore CS0618 // Type or member is obsolete -[assembly: ExportRenderer(typeof(CarouselPage), typeof(CarouselPageRenderer))] - -// Cells - -[assembly: ExportCell(typeof(Cell), typeof(TextCellRenderer))] -[assembly: ExportCell(typeof(ImageCell), typeof(ImageCellRenderer))] -[assembly: ExportCell(typeof(EntryCell), typeof(EntryCellRenderer))] -[assembly: ExportCell(typeof(SwitchCell), typeof(SwitchCellRenderer))] -[assembly: ExportCell(typeof(ViewCell), typeof(ViewCellRenderer))] -[assembly: Dependency(typeof(WindowsResourcesProvider))] -[assembly: ExportRenderer(typeof(SearchBar), typeof(SearchBarRenderer))] - -// WINUI3 -//[assembly: ExportRenderer(typeof(TabbedPage), typeof(TabbedPageRenderer))] - -[assembly: ExportRenderer(typeof(EmbeddedFont), typeof(EmbeddedFontLoader))] - [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.Maui.Controls.DualScreen")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.Maui.Controls.Compatibility.Platform.UAP.UnitTests")] diff --git a/src/Compatibility/Core/src/iOS/ExportCellAttribute.cs b/src/Compatibility/Core/src/iOS/ExportCellAttribute.cs deleted file mode 100644 index f351795fcd81..000000000000 --- a/src/Compatibility/Core/src/iOS/ExportCellAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Microsoft.Maui.Controls.Compatibility -{ - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class ExportCellAttribute : HandlerAttribute - { - public ExportCellAttribute(Type handler, Type target) : base(handler, target) - { - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/iOS/ExportImageSourceHandlerAttribute.cs b/src/Compatibility/Core/src/iOS/ExportImageSourceHandlerAttribute.cs deleted file mode 100644 index e279218cd34c..000000000000 --- a/src/Compatibility/Core/src/iOS/ExportImageSourceHandlerAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Microsoft.Maui.Controls.Compatibility -{ - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class ExportImageSourceHandlerAttribute : HandlerAttribute - { - public ExportImageSourceHandlerAttribute(Type handler, Type target) : base(handler, target) - { - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/iOS/ExportRendererAttribute.cs b/src/Compatibility/Core/src/iOS/ExportRendererAttribute.cs deleted file mode 100644 index 60037e9ba7ee..000000000000 --- a/src/Compatibility/Core/src/iOS/ExportRendererAttribute.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; - -#if __MOBILE__ -using UIKit; -#endif - -namespace Microsoft.Maui.Controls.Compatibility -{ - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class ExportRendererAttribute : HandlerAttribute - { -#if __MOBILE__ - public ExportRendererAttribute(Type handler, Type target, UIUserInterfaceIdiom idiom, Type[] supportedVisuals) : base(handler, target, supportedVisuals) - { - Idiomatic = true; - Idiom = idiom; - } - - - public ExportRendererAttribute(Type handler, Type target, UIUserInterfaceIdiom idiom) : this(handler, target, idiom, null) - { - } - - internal UIUserInterfaceIdiom Idiom { get; } -#endif - - public ExportRendererAttribute(Type handler, Type target, Type[] supportedVisuals) : base(handler, target, supportedVisuals) - { - Idiomatic = false; - } - - public ExportRendererAttribute(Type handler, Type target) : this(handler, target, null) - { - } - - internal bool Idiomatic { get; } - - public override bool ShouldRegister() - { -#if __MOBILE__ - return !Idiomatic || Idiom == UIDevice.CurrentDevice.UserInterfaceIdiom; -#else - return !Idiomatic; -#endif - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/iOS/Forms.cs b/src/Compatibility/Core/src/iOS/Forms.cs index 05cd591e02ec..25e840231535 100644 --- a/src/Compatibility/Core/src/iOS/Forms.cs +++ b/src/Compatibility/Core/src/iOS/Forms.cs @@ -276,29 +276,6 @@ internal static void RegisterCompatRenderers() } } - internal static void RegisterCompatRenderers( - Assembly[] assemblies, - Assembly defaultRendererAssembly, - Action viewRegistered) - { - if (IsInitializedRenderers) - return; - - IsInitializedRenderers = true; - - // Only need to do this once - Controls.Internals.Registrar.RegisterAll( - assemblies, - defaultRendererAssembly, - new[] { - typeof(ExportRendererAttribute), - typeof(ExportCellAttribute), - typeof(ExportImageSourceHandlerAttribute), - typeof(ExportFontAttribute) - }, default(InitializationFlags), - viewRegistered); - } - public static event EventHandler ViewInitialized; internal static void SendViewInitialized(this VisualElement self, TNativeView nativeView) diff --git a/src/Compatibility/Core/src/iOS/Properties/AssemblyInfo.cs b/src/Compatibility/Core/src/iOS/Properties/AssemblyInfo.cs index ed43db832d90..fa8582296ff6 100644 --- a/src/Compatibility/Core/src/iOS/Properties/AssemblyInfo.cs +++ b/src/Compatibility/Core/src/iOS/Properties/AssemblyInfo.cs @@ -1,77 +1,9 @@ using System.Reflection; using System.Runtime.CompilerServices; using Microsoft.Maui.Controls; -using Microsoft.Maui.Controls.Compatibility; -using Microsoft.Maui.Controls.Compatibility.Platform.iOS; -using Microsoft.Maui.Controls.Shapes; -using UIKit; -[assembly: ExportRenderer(typeof(BoxView), typeof(BoxRenderer))] -[assembly: ExportRenderer(typeof(Entry), typeof(EntryRenderer))] -[assembly: ExportRenderer(typeof(Editor), typeof(EditorRenderer))] -[assembly: ExportRenderer(typeof(Label), typeof(LabelRenderer))] -[assembly: ExportRenderer(typeof(Image), typeof(ImageRenderer))] -[assembly: ExportRenderer(typeof(Button), typeof(ButtonRenderer))] -[assembly: ExportRenderer(typeof(TableView), typeof(TableViewRenderer))] -[assembly: ExportRenderer(typeof(Slider), typeof(SliderRenderer))] -[assembly: ExportRenderer(typeof(WebView), typeof(WkWebViewRenderer))] -[assembly: ExportRenderer(typeof(SearchBar), typeof(SearchBarRenderer))] -[assembly: ExportRenderer(typeof(Switch), typeof(SwitchRenderer))] -[assembly: ExportRenderer(typeof(SwipeView), typeof(SwipeViewRenderer))] -[assembly: ExportRenderer(typeof(DatePicker), typeof(DatePickerRenderer))] -[assembly: ExportRenderer(typeof(TimePicker), typeof(TimePickerRenderer))] -[assembly: ExportRenderer(typeof(Picker), typeof(PickerRenderer))] -[assembly: ExportRenderer(typeof(Stepper), typeof(StepperRenderer))] -[assembly: ExportRenderer(typeof(ProgressBar), typeof(ProgressBarRenderer))] -[assembly: ExportRenderer(typeof(ScrollView), typeof(ScrollViewRenderer))] -[assembly: ExportRenderer(typeof(ActivityIndicator), typeof(ActivityIndicatorRenderer))] -[assembly: ExportRenderer(typeof(Frame), typeof(FrameRenderer))] -[assembly: ExportRenderer(typeof(ListView), typeof(ListViewRenderer))] -[assembly: ExportRenderer(typeof(CollectionView), typeof(CollectionViewRenderer))] -[assembly: ExportRenderer(typeof(CarouselView), typeof(CarouselViewRenderer))] -[assembly: ExportRenderer(typeof(IndicatorView), typeof(IndicatorViewRenderer))] -[assembly: ExportRenderer(typeof(OpenGLView), typeof(OpenGLViewRenderer))] -[assembly: ExportRenderer(typeof(CheckBox), typeof(CheckBoxRenderer))] -[assembly: ExportRenderer(typeof(Path), typeof(PathRenderer))] -[assembly: ExportRenderer(typeof(Ellipse), typeof(EllipseRenderer))] -[assembly: ExportRenderer(typeof(Line), typeof(LineRenderer))] -[assembly: ExportRenderer(typeof(Polyline), typeof(PolylineRenderer))] -[assembly: ExportRenderer(typeof(Polygon), typeof(PolygonRenderer))] -[assembly: ExportRenderer(typeof(Microsoft.Maui.Controls.Shapes.Rectangle), typeof(RectangleRenderer))] - -[assembly: ExportRenderer(typeof(TabbedPage), typeof(TabbedRenderer))] -[assembly: ExportRenderer(typeof(NavigationPage), typeof(NavigationRenderer))] -[assembly: ExportRenderer(typeof(CarouselPage), typeof(CarouselPageRenderer))] -[assembly: ExportRenderer(typeof(Page), typeof(PageRenderer))] -[assembly: ExportRenderer(typeof(FlyoutPage), typeof(PhoneFlyoutPageRenderer), UIUserInterfaceIdiom.Phone)] -#pragma warning disable CS0618 // Type or member is obsolete -[assembly: ExportRenderer(typeof(MasterDetailPage), typeof(PhoneMasterDetailRenderer), UIUserInterfaceIdiom.Phone)] -#pragma warning restore CS0618 // Type or member is obsolete - -[assembly: ExportRenderer(typeof(RefreshView), typeof(RefreshViewRenderer))] - -#pragma warning disable CS0618 // Type or member is obsolete -[assembly: ExportRenderer(typeof(MasterDetailPage), typeof(TabletMasterDetailRenderer), UIUserInterfaceIdiom.Pad)] -#pragma warning restore CS0618 // Type or member is obsolete -[assembly: ExportRenderer(typeof(FlyoutPage), typeof(TabletFlyoutPageRenderer), UIUserInterfaceIdiom.Pad)] -[assembly: ExportRenderer(typeof(NativeViewWrapper), typeof(NativeViewWrapperRenderer))] -[assembly: ExportRenderer(typeof(Shell), typeof(ShellRenderer))] -[assembly: ExportCell(typeof(Cell), typeof(CellRenderer))] -[assembly: ExportCell(typeof(ImageCell), typeof(ImageCellRenderer))] -[assembly: ExportCell(typeof(EntryCell), typeof(EntryCellRenderer))] -[assembly: ExportCell(typeof(TextCell), typeof(TextCellRenderer))] -[assembly: ExportCell(typeof(ViewCell), typeof(ViewCellRenderer))] -[assembly: ExportCell(typeof(SwitchCell), typeof(SwitchCellRenderer))] -[assembly: ExportRenderer(typeof(Microsoft.Maui.EmbeddedFont), typeof(Microsoft.Maui.EmbeddedFontLoader))] -[assembly: ExportEffect(typeof(ShadowEffect), "ShadowEffect")] -[assembly: ExportImageSourceHandler(typeof(FileImageSource), typeof(FileImageSourceHandler))] -[assembly: ExportImageSourceHandler(typeof(StreamImageSource), typeof(StreamImagesourceHandler))] -[assembly: ExportImageSourceHandler(typeof(UriImageSource), typeof(ImageLoaderSourceHandler))] -[assembly: ExportImageSourceHandler(typeof(FontImageSource), typeof(FontImageSourceHandler))] [assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Compatibility.Platform")] [assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Compatibility.Material")] [assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Compatibility.iOS.UnitTests")] -[assembly: Microsoft.Maui.Controls.Dependency(typeof(Deserializer))] -[assembly: Microsoft.Maui.Controls.Dependency(typeof(ResourcesProvider))] [assembly: ResolutionGroupName("Xamarin")] [assembly: AssemblyMetadata("IsTrimmable", "True")] \ No newline at end of file diff --git a/src/Compatibility/Core/src/iOS/Renderers/PhoneFlyoutPageRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/PhoneFlyoutPageRenderer.cs index d8017da21032..399d3aefd6ab 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/PhoneFlyoutPageRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/PhoneFlyoutPageRenderer.cs @@ -121,6 +121,11 @@ public override void ViewDidLayoutSubviews() { base.ViewDidLayoutSubviews(); + + // TODO MAUI: Is this correct? + if (Element.Width == -1 && Element.Height == -1) + Element.Layout(new Rectangle(Element.X, Element.Y, View.Bounds.Width, View.Bounds.Height)); + LayoutChildren(false); } @@ -376,7 +381,8 @@ void UpdateFlyoutPageContainers() if (Forms.RespondsToSetNeedsUpdateOfHomeIndicatorAutoHidden) SetNeedsUpdateOfHomeIndicatorAutoHidden(); - detailRenderer.ViewController.View.Superview.BackgroundColor = Microsoft.Maui.Graphics.Colors.Black.ToUIColor(); + if (detailRenderer.ViewController.View.Superview != null) + detailRenderer.ViewController.View.Superview.BackgroundColor = Microsoft.Maui.Graphics.Colors.Black.ToUIColor(); ToggleAccessibilityElementsHidden(); } @@ -402,7 +408,7 @@ void UpdateApplyShadow(bool value) public override UIViewController ChildViewControllerForStatusBarHidden() { if (((FlyoutPage)Element).Detail != null) - return (UIViewController)Platform.GetRenderer(((FlyoutPage)Element).Detail); + return Platform.GetRenderer(((FlyoutPage)Element).Detail).ViewController; else return base.ChildViewControllerForStatusBarHidden(); } @@ -412,7 +418,7 @@ public override UIViewController ChildViewControllerForHomeIndicatorAutoHidden get { if (((FlyoutPage)Element).Detail != null) - return (UIViewController)Platform.GetRenderer(((FlyoutPage)Element).Detail); + return Platform.GetRenderer(((FlyoutPage)Element).Detail).ViewController; else return base.ChildViewControllerForStatusBarHidden(); } diff --git a/src/Controls/src/Core/CompatServiceProvider.cs b/src/Controls/src/Core/CompatServiceProvider.cs index 7c5b0f303931..4e0004f8a6e0 100644 --- a/src/Controls/src/Core/CompatServiceProvider.cs +++ b/src/Controls/src/Core/CompatServiceProvider.cs @@ -1,5 +1,7 @@ #nullable enable using System; +using System.Collections.Generic; +using System.Reflection; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Maui.Hosting.Internal; @@ -10,26 +12,13 @@ namespace Microsoft.Maui.Controls static class CompatServiceProvider { static IServiceProvider? _serviceProvider; - static IEmbeddedFontLoader? _embeddedFontLoader; - // TODO MAUI This create seems wrong - public static IServiceProvider ServiceProvider => _serviceProvider ??= CreateCompatServiceProvider(); - - public static IFontRegistrar FontRegistrar => ServiceProvider.GetRequiredService(); + public static IServiceProvider ServiceProvider => _serviceProvider ?? throw new InvalidOperationException("ServiceProvider has not been initialized"); public static IFontManager FontManager => ServiceProvider.GetRequiredService(); - public static ILoggerFactory LoggerFactory => ServiceProvider.GetRequiredService(); - - public static void SetFontLoader(Type loaderType) - { - if (_embeddedFontLoader != null) - return; - - _embeddedFontLoader = (IEmbeddedFontLoader)Activator.CreateInstance(loaderType)!; - if (FontRegistrar is FontRegistrar fr) - fr.SetFontLoader(_embeddedFontLoader); - } + static List<(string filename, string? alias, Assembly assembly)> pendingFonts = + new List<(string filename, string? alias, Assembly assembly)>(); public static void SetServiceProvider(IServiceProvider services) { @@ -37,20 +26,33 @@ public static void SetServiceProvider(IServiceProvider services) throw new InvalidOperationException("The service provider can only be set once."); _serviceProvider = services; - _embeddedFontLoader = _serviceProvider.GetService(); + + lock (pendingFonts) + { + foreach (var pendingFont in pendingFonts) + { + RegisterFont(pendingFont.filename, pendingFont.alias, pendingFont.assembly); + } + + pendingFonts.Clear(); + } } - static IServiceProvider CreateCompatServiceProvider() + public static void RegisterFont(string filename, string? alias, Assembly assembly) { - var collection = new MauiServiceCollection(); - - collection.AddSingleton(); - collection.AddSingleton(svc => new FontRegistrar(_embeddedFontLoader, svc.CreateLogger())); - collection.AddSingleton(svc => new FontManager(svc.GetRequiredService(), svc.CreateLogger())); + if (_serviceProvider == null) + { + lock (pendingFonts) + { + pendingFonts.Add((filename, alias, assembly)); + } - var provider = new MauiServiceProvider(collection, false); + return; + } - return provider; + IFontRegistrar _fontRegistrar = ServiceProvider.GetRequiredService(); + _fontRegistrar.Register(filename, alias, assembly); } + } } \ No newline at end of file diff --git a/src/Controls/src/Core/DependencyService.cs b/src/Controls/src/Core/DependencyService.cs index 201705b4f664..a779dbcb94ec 100644 --- a/src/Controls/src/Core/DependencyService.cs +++ b/src/Controls/src/Core/DependencyService.cs @@ -118,16 +118,10 @@ static void Initialize() } } - internal static void Initialize(Assembly[] assemblies) + public static void Register(Assembly[] assemblies) { - if (s_initialized) - return; - lock (s_initializeLock) { - if (s_initialized) - return; - // Don't use LINQ for performance reasons // Naive implementation can easily take over a second to run foreach (Assembly assembly in assemblies) @@ -145,6 +139,20 @@ internal static void Initialize(Assembly[] assemblies) } } } + } + } + + internal static void Initialize(Assembly[] assemblies) + { + if (s_initialized) + return; + + lock (s_initializeLock) + { + if (s_initialized) + return; + + Register(assemblies); s_initialized = true; } diff --git a/src/Controls/src/Core/Registrar.cs b/src/Controls/src/Core/Registrar.cs index 49bd66bdc5d3..7e6687f69aee 100644 --- a/src/Controls/src/Core/Registrar.cs +++ b/src/Controls/src/Core/Registrar.cs @@ -353,12 +353,12 @@ public static void RegisterAll(Type[] attrTypes, InitializationFlags flags) null); } - public static void RegisterAll( + internal static void RegisterAll( Assembly[] assemblies, Assembly defaultRendererAssembly, Type[] attrTypes, InitializationFlags flags, - Action viewRegistered) + Action<(Type handler, Type target)> viewRegistered) { Profile.FrameBegin(); @@ -396,14 +396,17 @@ public static void RegisterAll( var attribute = a as HandlerAttribute; if (attribute == null && (a is ExportFontAttribute fa)) { - CompatServiceProvider.FontRegistrar.Register(fa.FontFileName, fa.Alias, assembly); + CompatServiceProvider.RegisterFont(fa.FontFileName, fa.Alias, assembly); } else { if (attribute.ShouldRegister()) { Registered.Register(attribute.HandlerType, attribute.TargetType, attribute.SupportedVisuals, attribute.Priority); - viewRegistered?.Invoke(attribute.HandlerType); + + // I realize these names seem wrong from the name of the action but in Xamarin.Forms we were calling + // the View types (Button, Image, etc..) handlers + viewRegistered?.Invoke((attribute.TargetType, attribute.HandlerType)); } } } @@ -428,10 +431,6 @@ public static void RegisterAll( Profile.FrameEnd(frameName); } - var type = Registered.GetHandlerType(typeof(EmbeddedFont)); - if (type != null) - CompatServiceProvider.SetFontLoader(type); - RegisterStylesheets(flags); Profile.FramePartition("DependencyService.Initialize"); DependencyService.Initialize(assemblies); diff --git a/src/Core/src/Fonts/FontRegistrar.cs b/src/Core/src/Fonts/FontRegistrar.cs index 04fad8a240ca..39e0c09c5500 100644 --- a/src/Core/src/Fonts/FontRegistrar.cs +++ b/src/Core/src/Fonts/FontRegistrar.cs @@ -15,19 +15,14 @@ public partial class FontRegistrar : IFontRegistrar readonly Dictionary _fontLookupCache = new(); readonly ILogger? _logger; - IEmbeddedFontLoader? _fontLoader; + IEmbeddedFontLoader _fontLoader; - public FontRegistrar(IEmbeddedFontLoader? fontLoader = null, ILogger? logger = null) + public FontRegistrar(IEmbeddedFontLoader fontLoader, ILogger? logger = null) { _fontLoader = fontLoader; _logger = logger; } - public void SetFontLoader(IEmbeddedFontLoader? fontLoader) - { - _fontLoader = fontLoader; - } - public void Register(string filename, string? alias, Assembly assembly) { _embeddedFonts[filename] = (filename, alias, assembly);