From 3e1318fd360252f83b106aba0be669c1f0686e7b Mon Sep 17 00:00:00 2001 From: Kangho Hur Date: Tue, 22 Jun 2021 06:49:16 +0900 Subject: [PATCH] Bump to latest - Apply to start adding in APIs for adding legacy renderers via assembly scanning (#1333) - Update to IMauiContext (#1357) - and so on --- .../Core/src/AppHostBuilderExtensions.cs | 1 + .../Core/src/RendererToHandlerShim.Tizen.cs | 100 --------------- .../Core/src/Tizen/ExportCellAttribute.cs | 12 -- .../Core/src/Tizen/ExportHandlerAttribute.cs | 12 -- .../ExportImageSourceHandlerAttribute.cs | 12 -- .../Core/src/Tizen/ExportRendererAttribute.cs | 36 ------ src/Compatibility/Core/src/Tizen/Forms.cs | 118 ------------------ .../Core/src/Tizen/Properties/AssemblyInfo.cs | 85 +------------ src/Core/src/IMauiContext.cs | 4 +- src/Core/src/Platform/MauiContext.Tizen.cs | 37 ++++++ src/Core/src/Platform/Tizen/MauiContext.cs | 32 ----- 11 files changed, 45 insertions(+), 404 deletions(-) delete mode 100644 src/Compatibility/Core/src/Tizen/ExportCellAttribute.cs delete mode 100644 src/Compatibility/Core/src/Tizen/ExportHandlerAttribute.cs delete mode 100644 src/Compatibility/Core/src/Tizen/ExportImageSourceHandlerAttribute.cs delete mode 100644 src/Compatibility/Core/src/Tizen/ExportRendererAttribute.cs create mode 100644 src/Core/src/Platform/MauiContext.Tizen.cs delete mode 100644 src/Core/src/Platform/Tizen/MauiContext.cs diff --git a/src/Compatibility/Core/src/AppHostBuilderExtensions.cs b/src/Compatibility/Core/src/AppHostBuilderExtensions.cs index d991265767b0..d0b0b8f3237a 100644 --- a/src/Compatibility/Core/src/AppHostBuilderExtensions.cs +++ b/src/Compatibility/Core/src/AppHostBuilderExtensions.cs @@ -40,6 +40,7 @@ using OpenGLViewRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Tizen.DefaultRenderer; using StreamImagesourceHandler = Microsoft.Maui.Controls.Compatibility.Platform.Tizen.StreamImageSourceHandler; using ImageLoaderSourceHandler = Microsoft.Maui.Controls.Compatibility.Platform.Tizen.UriImageSourceHandler; +using DefaultRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Tizen.DefaultRenderer; #endif namespace Microsoft.Maui.Controls.Compatibility.Hosting diff --git a/src/Compatibility/Core/src/RendererToHandlerShim.Tizen.cs b/src/Compatibility/Core/src/RendererToHandlerShim.Tizen.cs index 6cc9c9b6cde9..06de675595f5 100644 --- a/src/Compatibility/Core/src/RendererToHandlerShim.Tizen.cs +++ b/src/Compatibility/Core/src/RendererToHandlerShim.Tizen.cs @@ -29,105 +29,5 @@ public override ERect GetNativeContentGeometry() { return VisualElementRenderer?.GetNativeContentGeometry() ?? new ERect(); } - - //public static IViewHandler CreateShim(object renderer) - //{ - // if (renderer is IViewHandler handler) - // return handler; - - // if (renderer is IVisualElementRenderer ivr) - // return new RendererToHandlerShim(ivr); - - // return new RendererToHandlerShim(); - //} - - //public RendererToHandlerShim() : base(ViewHandler.ViewMapper) - //{ - //} - - //public RendererToHandlerShim(IVisualElementRenderer visualElementRenderer) : this() - //{ - // if (visualElementRenderer != null) - // SetupRenderer(visualElementRenderer); - //} - - //public void SetupRenderer(IVisualElementRenderer visualElementRenderer) - //{ - // VisualElementRenderer = visualElementRenderer; - // VisualElementRenderer.ElementChanged += OnElementChanged; - - // if (VisualElementRenderer.Element is IView view) - // { - // view.Handler = this; - // SetVirtualView(view); - // } - // else if (VisualElementRenderer.Element != null) - // throw new Exception($"{VisualElementRenderer.Element} must implement: {nameof(IView)}"); - //} - - //void OnElementChanged(object sender, VisualElementChangedEventArgs e) - //{ - // if (e.OldElement is IView view) - // view.Handler = null; - - // if (e.NewElement is IView newView) - // { - // newView.Handler = this; - // this.SetVirtualView(newView); - // } - // else if (e.NewElement != null) - // throw new Exception($"{e.NewElement} must implement: {nameof(IView)}"); - //} - - //protected override EvasObject CreateNativeView() - //{ - // return VisualElementRenderer.NativeView; - //} - - //protected override void ConnectHandler(EvasObject nativeView) - //{ - // base.ConnectHandler(nativeView); - // VirtualView.Handler = this; - //} - - //protected override void DisconnectHandler(EvasObject nativeView) - //{ - // Platform.Tizen.Platform.SetRenderer(VisualElementRenderer.Element, VisualElementRenderer); - - // VisualElementRenderer.SetElement(null); - - // base.DisconnectHandler(nativeView); - // VirtualView.Handler = null; - //} - - //public override void SetVirtualView(IView view) - //{ - // if (VisualElementRenderer == null) - // { - // var renderer = Internals.Registrar.Registered.GetHandlerForObject(view) ?? new DefaultRenderer(); - - // SetupRenderer(renderer); - // } - - // if (VisualElementRenderer.Element != view) - // { - // VisualElementRenderer.SetElement((VisualElement)view); - // } - // else - // { - // base.SetVirtualView(view); - // } - - // Platform.Tizen.Platform.SetRenderer(VisualElementRenderer.Element, VisualElementRenderer); - //} - - //public override void UpdateValue(string property) - //{ - // base.UpdateValue(property); - // if (property == "Frame") - // { - // NativeArrange(VisualElementRenderer.Element.Bounds); - // } - //} } } diff --git a/src/Compatibility/Core/src/Tizen/ExportCellAttribute.cs b/src/Compatibility/Core/src/Tizen/ExportCellAttribute.cs deleted file mode 100644 index fd6844112e7a..000000000000 --- a/src/Compatibility/Core/src/Tizen/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) - { - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/ExportHandlerAttribute.cs b/src/Compatibility/Core/src/Tizen/ExportHandlerAttribute.cs deleted file mode 100644 index 17a126abb362..000000000000 --- a/src/Compatibility/Core/src/Tizen/ExportHandlerAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Microsoft.Maui.Controls.Compatibility -{ - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class ExportHandlerAttribute : HandlerAttribute - { - public ExportHandlerAttribute(Type handler, Type target) : base(handler, target) - { - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/ExportImageSourceHandlerAttribute.cs b/src/Compatibility/Core/src/Tizen/ExportImageSourceHandlerAttribute.cs deleted file mode 100644 index fb680b156ef4..000000000000 --- a/src/Compatibility/Core/src/Tizen/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) - { - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/ExportRendererAttribute.cs b/src/Compatibility/Core/src/Tizen/ExportRendererAttribute.cs deleted file mode 100644 index f07feb8da86b..000000000000 --- a/src/Compatibility/Core/src/Tizen/ExportRendererAttribute.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using Microsoft.Maui.Controls.Compatibility.Platform.Tizen; - -namespace Microsoft.Maui.Controls.Compatibility -{ - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class ExportRendererAttribute : HandlerAttribute - { - TargetIdiom Target { get; set; } - - public ExportRendererAttribute(Type handler, Type target) : this(handler, target, null) - { - } - - public ExportRendererAttribute(Type handler, Type target, Type[] supportedVisuals) : base(handler, target, supportedVisuals) - { - } - - public ExportRendererAttribute(Type handler, Type target, TargetIdiom targetIdiom) : this(handler, target, null, targetIdiom) - { - } - - public ExportRendererAttribute(Type handler, Type target, Type[] supportedVisuals, TargetIdiom targetIdiom) : base(handler, target, supportedVisuals) - { - Target = targetIdiom; - } - - public override bool ShouldRegister() - { - if (Target == TargetIdiom.Unsupported) - return true; - - return (Target == Device.Idiom); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Forms.cs b/src/Compatibility/Core/src/Tizen/Forms.cs index f68d0dbe75e8..4d30ddff8211 100644 --- a/src/Compatibility/Core/src/Tizen/Forms.cs +++ b/src/Compatibility/Core/src/Tizen/Forms.cs @@ -467,124 +467,6 @@ static void SetupInit(IMauiContext context, InitializationOptions options = null IsInitialized = true; } - // 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(InitializationOptions options) - { - if (!IsInitializedRenderers) - { - IsInitializedRenderers = true; - if (options != null) - { - s_platformType = options.PlatformType; - s_useMessagingCenter = options.UseMessagingCenter; - UseSkiaSharp = options.UseSkiaSharp; - UseFastLayout = options.UseFastLayout; - - // renderers - if (options.Handlers != null) - { - Registrar.RegisterRenderers(options.Handlers); - } - else - { - // static registrar - if (options.StaticRegistarStrategy != StaticRegistrarStrategy.None) - { - s_staticRegistrarStrategy = options.StaticRegistarStrategy; - StaticRegistrar.RegisterHandlers(options.CustomHandlers); - - if (options.StaticRegistarStrategy == StaticRegistrarStrategy.All) - { - Registrar.RegisterAll(new Type[] - { - typeof(ExportRendererAttribute), - typeof(ExportImageSourceHandlerAttribute), - typeof(ExportCellAttribute), - typeof(ExportHandlerAttribute), - typeof(ExportFontAttribute) - }); - - if (UseSkiaSharp) - RegisterSkiaSharpRenderers(); - } - } - else - { - Registrar.RegisterAll(new Type[] - { - typeof(ExportRendererAttribute), - typeof(ExportImageSourceHandlerAttribute), - typeof(ExportCellAttribute), - typeof(ExportHandlerAttribute), - typeof(ExportFontAttribute) - }); - - if (UseSkiaSharp) - RegisterSkiaSharpRenderers(); - - if (UseFastLayout) - Registrar.Registered.Register(typeof(Layout), typeof(FastLayoutRenderer)); - } - } - - // effects - var effectScopes = options.EffectScopes; - if (effectScopes != null) - { - for (var i = 0; i < effectScopes.Length; i++) - { - var effectScope = effectScopes[0]; - Registrar.RegisterEffects(effectScope.Name, effectScope.Effects); - } - } - - // css - Registrar.RegisterStylesheets(options.Flags); - } - else - { - Registrar.RegisterAll(new Type[] - { - typeof(ExportRendererAttribute), - typeof(ExportImageSourceHandlerAttribute), - typeof(ExportCellAttribute), - typeof(ExportHandlerAttribute), - 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(ExportImageSourceHandlerAttribute), - typeof(ExportCellAttribute), - typeof(ExportHandlerAttribute), - typeof(ExportFontAttribute) - }, default(InitializationFlags), - viewRegistered); - } - static void RegisterSkiaSharpRenderers() { // Register all skiasharp-based rednerers here. diff --git a/src/Compatibility/Core/src/Tizen/Properties/AssemblyInfo.cs b/src/Compatibility/Core/src/Tizen/Properties/AssemblyInfo.cs index 7170bce4726e..54f1710e1f6e 100644 --- a/src/Compatibility/Core/src/Tizen/Properties/AssemblyInfo.cs +++ b/src/Compatibility/Core/src/Tizen/Properties/AssemblyInfo.cs @@ -1,81 +1,6 @@ -using Microsoft.Maui; -using Microsoft.Maui.Controls; -using Microsoft.Maui.Controls.Compatibility; -using Microsoft.Maui.Controls.Compatibility.Platform.Tizen; -using Microsoft.Maui.Controls.Shapes; +using System.Runtime.CompilerServices; +using Microsoft.Maui.Controls.Internals; -[assembly: Dependency(typeof(ResourcesProvider))] -[assembly: Dependency(typeof(Deserializer))] -[assembly: Dependency(typeof(NativeBindingService))] -[assembly: Dependency(typeof(NativeValueConverterService))] - -[assembly: ExportRenderer(typeof(Layout), typeof(LayoutRenderer))] -[assembly: ExportRenderer(typeof(ScrollView), typeof(ScrollViewRenderer))] -[assembly: ExportRenderer(typeof(CarouselPage), typeof(CarouselPageRenderer))] -[assembly: ExportRenderer(typeof(Page), typeof(PageRenderer))] -[assembly: ExportRenderer(typeof(NavigationPage), typeof(NavigationPageRenderer))] -#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(FlyoutPage), typeof(FlyoutPageRenderer))] -[assembly: ExportRenderer(typeof(TabbedPage), typeof(TabbedPageRenderer))] -[assembly: ExportRenderer(typeof(Shell), typeof(ShellRenderer))] - -[assembly: ExportRenderer(typeof(Label), typeof(LabelRenderer))] -[assembly: ExportRenderer(typeof(Button), typeof(ButtonRenderer))] -[assembly: ExportRenderer(typeof(Image), typeof(ImageRenderer))] -[assembly: ExportRenderer(typeof(Slider), typeof(SliderRenderer))] -[assembly: ExportRenderer(typeof(Picker), typeof(PickerRenderer))] -[assembly: ExportRenderer(typeof(Frame), typeof(FrameRenderer))] -[assembly: ExportRenderer(typeof(Stepper), typeof(StepperRenderer))] -[assembly: ExportRenderer(typeof(DatePicker), typeof(DatePickerRenderer))] -[assembly: ExportRenderer(typeof(TimePicker), typeof(TimePickerRenderer))] -[assembly: ExportRenderer(typeof(ProgressBar), typeof(ProgressBarRenderer))] -[assembly: ExportRenderer(typeof(Switch), typeof(SwitchRenderer))] -[assembly: ExportRenderer(typeof(CheckBox), typeof(CheckBoxRenderer))] -[assembly: ExportRenderer(typeof(ListView), typeof(ListViewRenderer))] -[assembly: ExportRenderer(typeof(BoxView), typeof(BoxViewRenderer))] -[assembly: ExportRenderer(typeof(ActivityIndicator), typeof(ActivityIndicatorRenderer))] -[assembly: ExportRenderer(typeof(IndicatorView), typeof(IndicatorViewRenderer))] -[assembly: ExportRenderer(typeof(SearchBar), typeof(SearchBarRenderer))] -[assembly: ExportRenderer(typeof(Entry), typeof(EntryRenderer))] -[assembly: ExportRenderer(typeof(Editor), typeof(EditorRenderer))] -[assembly: ExportRenderer(typeof(TableView), typeof(TableViewRenderer))] -[assembly: ExportRenderer(typeof(NativeViewWrapper), typeof(NativeViewWrapperRenderer))] -[assembly: ExportRenderer(typeof(WebView), typeof(WebViewRenderer))] -[assembly: ExportRenderer(typeof(ImageButton), typeof(ImageButtonRenderer))] -[assembly: ExportRenderer(typeof(StructuredItemsView), typeof(StructuredItemsViewRenderer))] -[assembly: ExportRenderer(typeof(CarouselView), typeof(CarouselViewRenderer))] -[assembly: ExportRenderer(typeof(SwipeView), typeof(SwipeViewRenderer))] -[assembly: ExportRenderer(typeof(RefreshView), typeof(RefreshViewRenderer))] -[assembly: ExportRenderer(typeof(IndicatorView), typeof(IndicatorViewRenderer))] -[assembly: ExportRenderer(typeof(RadioButton), typeof(RadioButtonRenderer))] - -[assembly: ExportImageSourceHandler(typeof(FileImageSource), typeof(FileImageSourceHandler))] -[assembly: ExportImageSourceHandler(typeof(StreamImageSource), typeof(StreamImageSourceHandler))] -[assembly: ExportImageSourceHandler(typeof(UriImageSource), typeof(UriImageSourceHandler))] - -[assembly: ExportCell(typeof(TextCell), typeof(TextCellRenderer))] -[assembly: ExportCell(typeof(ImageCell), typeof(ImageCellRenderer))] -[assembly: ExportCell(typeof(SwitchCell), typeof(SwitchCellRenderer))] -[assembly: ExportCell(typeof(EntryCell), typeof(EntryCellRenderer))] -[assembly: ExportCell(typeof(ViewCell), typeof(ViewCellRenderer))] - -[assembly: ExportRenderer(typeof(Microsoft.Maui.EmbeddedFont), typeof(Microsoft.Maui.EmbeddedFontLoader))] - -[assembly: ExportHandler(typeof(TapGestureRecognizer), typeof(TapGestureHandler))] -[assembly: ExportHandler(typeof(PinchGestureRecognizer), typeof(PinchGestureHandler))] -[assembly: ExportHandler(typeof(PanGestureRecognizer), typeof(PanGestureHandler))] -[assembly: ExportHandler(typeof(SwipeGestureRecognizer), typeof(SwipeGestureHandler))] -[assembly: ExportHandler(typeof(DragGestureRecognizer), typeof(DragGestureHandler))] -[assembly: ExportHandler(typeof(DropGestureRecognizer), typeof(DropGestureHandler))] - -[assembly: ExportRenderer(typeof(Shell), typeof(Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Watch.ShellRenderer), TargetIdiom.Watch)] -[assembly: ExportRenderer(typeof(Shell), typeof(Microsoft.Maui.Controls.Compatibility.Platform.Tizen.TV.TVShellRenderer), TargetIdiom.TV)] - -[assembly: ExportRenderer(typeof(Ellipse), typeof(EllipseRenderer))] -[assembly: ExportRenderer(typeof(Line), typeof(LineRenderer))] -[assembly: ExportRenderer(typeof(Path), typeof(PathRenderer))] -[assembly: ExportRenderer(typeof(Polygon), typeof(PolygonRenderer))] -[assembly: ExportRenderer(typeof(Polyline), typeof(PolylineRenderer))] -[assembly: ExportRenderer(typeof(Rectangle), typeof(RectangleRenderer))] +[assembly: Preserve] +[assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Compatibility.Platform")] +[assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Compatibility.Material")] \ No newline at end of file diff --git a/src/Core/src/IMauiContext.cs b/src/Core/src/IMauiContext.cs index 1dc94ed65923..11b1593bb241 100644 --- a/src/Core/src/IMauiContext.cs +++ b/src/Core/src/IMauiContext.cs @@ -11,7 +11,7 @@ public interface IMauiContext #if __ANDROID__ Android.Content.Context? Context { get; } #elif TIZEN - CoreUIAppContext Context { get; } + CoreUIAppContext? Context { get; } #endif } -} +} \ No newline at end of file diff --git a/src/Core/src/Platform/MauiContext.Tizen.cs b/src/Core/src/Platform/MauiContext.Tizen.cs new file mode 100644 index 000000000000..3a0b26c4b7cc --- /dev/null +++ b/src/Core/src/Platform/MauiContext.Tizen.cs @@ -0,0 +1,37 @@ +using System; + +namespace Microsoft.Maui +{ + public partial class MauiContext + { + readonly WeakReference? _context; + + public MauiContext(CoreUIAppContext context) : this() + { + _context = new WeakReference(context ?? throw new ArgumentNullException(nameof(context))); + } + + public MauiContext(IServiceProvider services, CoreUIAppContext context) : this(services) + { + _context = new WeakReference(context ?? throw new ArgumentNullException(nameof(context))); + } + + public CoreUIAppContext? Context + { + get + { + if (_context == null) + return null; + + CoreUIAppContext? context; + if (_context.TryGetTarget(out context)) + { + return context; + } + + return null; + } + } + + } +} \ No newline at end of file diff --git a/src/Core/src/Platform/Tizen/MauiContext.cs b/src/Core/src/Platform/Tizen/MauiContext.cs deleted file mode 100644 index 7b248d30ecb5..000000000000 --- a/src/Core/src/Platform/Tizen/MauiContext.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using Microsoft.Extensions.DependencyInjection; - -namespace Microsoft.Maui -{ - public class MauiContext : IMauiContext - { - readonly CoreUIAppContext _context; - readonly IServiceProvider? _services; - readonly IMauiHandlersServiceProvider? _mauiHandlersServiceProvider; - - public MauiContext(CoreUIAppContext context) - { - _context = context ?? throw new ArgumentNullException(nameof(context)); - } - - public MauiContext(IServiceProvider services, CoreUIAppContext context) - { - _services = services ?? throw new ArgumentNullException(nameof(services)); - _context = context ?? throw new ArgumentNullException(nameof(context)); - _mauiHandlersServiceProvider = Services.GetRequiredService(); - } - - public CoreUIAppContext Context => _context; - - public IServiceProvider Services => - _services ?? throw new InvalidOperationException($"No service provider was specified during construction."); - - public IMauiHandlersServiceProvider Handlers => - _mauiHandlersServiceProvider ?? throw new InvalidOperationException($"No service provider was specified during construction."); - } -} \ No newline at end of file