Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start adding in APIs for adding legacy renderers via assembly scanning #1333

Merged
merged 8 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Compatibility/ControlGallery/src/Core/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ public App()
{
_testCloudService = DependencyService.Get<ITestCloudService>();

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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<ProjectReference Include="..\..\..\..\Controls\src\Core\Controls.Core-net6.csproj" />
<ProjectReference Include="..\..\..\..\Controls\src\Xaml\Controls.Xaml-net6.csproj" />
<ProjectReference Include="..\..\..\..\Core\src\Core-net6.csproj" />
<ProjectReference Include="..\..\..\Core\src\Compatibility-net6.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
35 changes: 35 additions & 0 deletions src/Compatibility/ControlGallery/src/Core/Startup.cs
Original file line number Diff line number Diff line change
@@ -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<App>()
.ConfigureMauiHandlers(handlers =>
{
handlers.AddCompatibilityRenderers(Device.GetAssemblies());
})
.ConfigureImageSources(sources =>
{
sources.AddCompatibilityServices(Device.GetAssemblies());
})
.ConfigureFonts(fonts =>
{
fonts.AddCompatibilityFonts(Device.GetAssemblies());
})
.ConfigureServices(services =>
{
DependencyService.Register(Device.GetAssemblies());
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ public static List<Page> GetAllPages()
{
var controls = new List<Page>
{
#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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
17 changes: 5 additions & 12 deletions src/Compatibility/ControlGallery/src/iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ public string GetTestCloudDevice()
}

[Register("AppDelegate")]
public partial class AppDelegate : FormsApplicationDelegate
public partial class AppDelegate : MauiUIApplicationDelegate<Startup>
{
App _app;

public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions)
{
UISwitch.Appearance.OnTintColor = UIColor.Red;
Expand All @@ -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) =>
Expand All @@ -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<NestedNativeControlGalleryPage>(this, NestedNativeControlGalleryPage.ReadyForNativeControlsMessage, AddNativeControls);
MessagingCenter.Subscribe<Bugzilla40911>(this, Bugzilla40911.ReadyToSetUp40911Test, SetUp40911Test);
Expand All @@ -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<NativeBindingGalleryPage>(this, NativeBindingGalleryPage.ReadyForNativeBindingsMessage, AddNativeBindings);

LoadApplication(app);

return base.FinishedLaunching(uiApplication, launchOptions);
}

Expand Down Expand Up @@ -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;
}

Expand Down
12 changes: 0 additions & 12 deletions src/Compatibility/Core/src/Android/ExportCellAttribute.cs

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions src/Compatibility/Core/src/Android/ExportRendererAttribute.cs

This file was deleted.

23 changes: 0 additions & 23 deletions src/Compatibility/Core/src/Android/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,29 +258,6 @@ internal static void RenderersRegistered()
IsInitializedRenderers = true;
}

internal static void RegisterCompatRenderers(
Assembly[] assemblies,
Assembly defaultRendererAssembly,
Action<Type> 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)
Expand Down
65 changes: 0 additions & 65 deletions src/Compatibility/Core/src/Android/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down
12 changes: 11 additions & 1 deletion src/Compatibility/Core/src/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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<Xaml.ResourcesLoader>();
DependencyService.Register<NativeBindingService>();
DependencyService.Register<NativeValueConverterService>();
Expand Down
Loading