diff --git a/.nuspec/Microsoft.Maui.Controls.MultiTargeting.targets b/.nuspec/Microsoft.Maui.Controls.MultiTargeting.targets index bfa81e0fadab..01d6d8ff280f 100644 --- a/.nuspec/Microsoft.Maui.Controls.MultiTargeting.targets +++ b/.nuspec/Microsoft.Maui.Controls.MultiTargeting.targets @@ -113,5 +113,4 @@ WINDOWS_UWP;$(DefineConstants) - diff --git a/.nuspec/Microsoft.Maui.Controls.SingleProject.targets b/.nuspec/Microsoft.Maui.Controls.SingleProject.targets index 15f98664a1a3..628e932bee6d 100644 --- a/.nuspec/Microsoft.Maui.Controls.SingleProject.targets +++ b/.nuspec/Microsoft.Maui.Controls.SingleProject.targets @@ -111,7 +111,7 @@ BeforeTargets="_MauiInjectXamlCssAdditionalFiles;GenerateMSBuildEditorConfigFileShouldRun" Condition=" '$(EnableDefaultItems)' == 'true' and '$(SingleProject)' == 'true' "> - + Microsoft.AspNetCore.Components.Web.JSComponentConfigurationStore! Microsoft.AspNetCore.Components.WebView.Maui.RootComponentsCollection.RootComponentsCollection(Microsoft.AspNetCore.Components.Web.JSComponentConfigurationStore! jsComponents) -> void Microsoft.AspNetCore.Components.WebView.Maui.TizenWebViewManager -Microsoft.AspNetCore.Components.WebView.Maui.TizenWebViewManager.TizenWebViewManager(Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebViewHandler! blazorMauiWebViewHandler, Tizen.WebView.WebView! webview, System.IServiceProvider! provider, Microsoft.AspNetCore.Components.Dispatcher! dispatcher, Microsoft.Extensions.FileProviders.IFileProvider! fileProvider, Microsoft.AspNetCore.Components.Web.JSComponentConfigurationStore! jsComponents, string! contentRootRelativeToAppRoot, string! hostPageRelativePath) -> void +Microsoft.AspNetCore.Components.WebView.Maui.TizenWebViewManager.TizenWebViewManager(Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebViewHandler! blazorMauiWebViewHandler, Tizen.NUI.BaseComponents.WebView! webview, System.IServiceProvider! provider, Microsoft.AspNetCore.Components.Dispatcher! dispatcher, Microsoft.Extensions.FileProviders.IFileProvider! fileProvider, Microsoft.AspNetCore.Components.Web.JSComponentConfigurationStore! jsComponents, string! contentRootRelativeToAppRoot, string! hostPageRelativePath) -> void override Microsoft.AspNetCore.Components.WebView.Maui.TizenWebViewManager.NavigateCore(System.Uri! absoluteUri) -> void override Microsoft.AspNetCore.Components.WebView.Maui.TizenWebViewManager.SendMessage(string! message) -> void -Microsoft.AspNetCore.Components.WebView.Maui.WebViewContainer -Microsoft.AspNetCore.Components.WebView.Maui.WebViewContainer.WebViewContainer(ElmSharp.EvasObject! parent) -> void -Microsoft.AspNetCore.Components.WebView.Maui.WebViewContainer.WebView.get -> Tizen.WebView.WebView! Microsoft.AspNetCore.Components.WebView.UrlLoadingEventArgs Microsoft.AspNetCore.Components.WebView.UrlLoadingEventArgs.Url.get -> System.Uri! Microsoft.AspNetCore.Components.WebView.UrlLoadingEventArgs.UrlLoadingStrategy.get -> Microsoft.AspNetCore.Components.WebView.UrlLoadingStrategy @@ -51,13 +48,13 @@ Microsoft.AspNetCore.Components.WebView.UrlLoadingStrategy.CancelLoad = 2 -> Mic Microsoft.AspNetCore.Components.WebView.UrlLoadingStrategy.OpenExternally = 0 -> Microsoft.AspNetCore.Components.WebView.UrlLoadingStrategy Microsoft.AspNetCore.Components.WebView.UrlLoadingStrategy.OpenInWebView = 1 -> Microsoft.AspNetCore.Components.WebView.UrlLoadingStrategy Microsoft.Extensions.DependencyInjection.BlazorWebViewServiceCollectionExtensions -override Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebViewHandler.CreatePlatformView() -> Microsoft.AspNetCore.Components.WebView.Maui.WebViewContainer! -override Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebViewHandler.ConnectHandler(Microsoft.AspNetCore.Components.WebView.Maui.WebViewContainer! platformView) -> void -override Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebViewHandler.DisconnectHandler(Microsoft.AspNetCore.Components.WebView.Maui.WebViewContainer! platformView) -> void +override Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebViewHandler.CreatePlatformView() -> Tizen.NUI.BaseComponents.WebView! +override Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebViewHandler.ConnectHandler(Tizen.NUI.BaseComponents.WebView! platformView) -> void +override Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebViewHandler.DisconnectHandler(Tizen.NUI.BaseComponents.WebView! platformView) -> void static Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebViewHandler.MapHostPage(Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebViewHandler! handler, Microsoft.AspNetCore.Components.WebView.Maui.IBlazorWebView! webView) -> void static Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebViewHandler.MapRootComponents(Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebViewHandler! handler, Microsoft.AspNetCore.Components.WebView.Maui.IBlazorWebView! webView) -> void static Microsoft.Extensions.DependencyInjection.BlazorWebViewServiceCollectionExtensions.AddBlazorWebViewDeveloperTools(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static Microsoft.Extensions.DependencyInjection.BlazorWebViewServiceCollectionExtensions.AddMauiBlazorWebView(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.AspNetCore.Components.WebView.Maui.IMauiBlazorWebViewBuilder! static Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebViewHandler.BlazorWebViewMapper -> Microsoft.Maui.PropertyMapper! virtual Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.CreateFileProvider(string! contentRootDir) -> Microsoft.Extensions.FileProviders.IFileProvider! -~Microsoft.AspNetCore.Components.WebView.BlazorWebViewInitializedEventArgs.WebView.get -> Tizen.WebView.WebView +~Microsoft.AspNetCore.Components.WebView.BlazorWebViewInitializedEventArgs.WebView.get -> Tizen.NUI.BaseComponents.WebView diff --git a/src/BlazorWebView/src/Maui/Tizen/BlazorWebViewHandler.Tizen.cs b/src/BlazorWebView/src/Maui/Tizen/BlazorWebViewHandler.Tizen.cs index 7b45a654c4f0..139b9932dc6a 100644 --- a/src/BlazorWebView/src/Maui/Tizen/BlazorWebViewHandler.Tizen.cs +++ b/src/BlazorWebView/src/Maui/Tizen/BlazorWebViewHandler.Tizen.cs @@ -1,21 +1,23 @@ using System; +using System.Collections.Generic; using System.IO; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using Microsoft.Maui; using Microsoft.Maui.Dispatching; using Microsoft.Maui.Handlers; -using Tizen.WebView; -using TChromium = Tizen.WebView.Chromium; -using TWebView = Tizen.WebView.WebView; +using Tizen.NUI; +using NWebView = Tizen.NUI.BaseComponents.WebView; namespace Microsoft.AspNetCore.Components.WebView.Maui { /// /// The Tizen for . /// - public partial class BlazorWebViewHandler : ViewHandler + public partial class BlazorWebViewHandler : ViewHandler { + private const string BlazorWebViewIdentifier = "BlazorWebView:"; + private const string UserAgentHeaderKey = "User-Agent"; private const string AppOrigin = "http://0.0.0.0/"; private const string BlazorInitScript = @" window.__receiveMessageCallbacks = []; @@ -42,10 +44,9 @@ public partial class BlazorWebViewHandler : ViewHandler> s_webviewHandlerTable = new Dictionary>(); - private TWebView PlatformWebView => PlatformView.WebView; + private TizenWebViewManager? _webviewManager; private bool RequiredStartupPropertiesSet => //_webview != null && @@ -53,42 +54,89 @@ public partial class BlazorWebViewHandler : ViewHandler - protected override WebViewContainer CreatePlatformView() + protected override NWebView CreatePlatformView() { - TChromium.Initialize(); - MauiApplication.Current.Terminated += (s, e) => TChromium.Shutdown(); - - return new WebViewContainer(PlatformParent); + return new NWebView() + { + MouseEventsEnabled = true, + KeyEventsEnabled = true, + }; } /// - protected override void ConnectHandler(WebViewContainer platformView) + protected override void ConnectHandler(NWebView platformView) { - _interceptRequestCallback = OnRequestInterceptCallback; - PlatformWebView.LoadFinished += OnLoadFinished; - PlatformWebView.AddJavaScriptMessageHandler("BlazorHandler", PostMessageFromJS); - PlatformWebView.SetInterceptRequestCallback(_interceptRequestCallback); - PlatformWebView.GetSettings().JavaScriptEnabled = true; + platformView.PageLoadFinished += OnLoadFinished; + platformView.Context.RegisterHttpRequestInterceptedCallback(OnRequestInterceptStaticCallback); + platformView.AddJavaScriptMessageHandler("BlazorHandler", PostMessageFromJS); + platformView.UserAgent += $" {BlazorWebViewIdentifier}{GetHashCode()}"; + s_webviewHandlerTable[GetHashCode().ToString()] = new WeakReference(this); } /// - protected override void DisconnectHandler(WebViewContainer platformView) + protected override void DisconnectHandler(NWebView platformView) { - PlatformWebView.LoadFinished -= OnLoadFinished; + platformView.PageLoadFinished -= OnLoadFinished; base.DisconnectHandler(platformView); + s_webviewHandlerTable.Remove(GetHashCode().ToString()); + } + + + private void PostMessageFromJS(string message) + { + _webviewManager!.MessageReceivedInternal(new Uri(PlatformView.Url), message); } - private void PostMessageFromJS(JavaScriptMessage message) + private void OnLoadFinished(object? sender, WebViewPageLoadEventArgs e) { - if (message is null) + //FocusManager.Instance.SetCurrentFocusView(NativeView); + var url = PlatformView.Url; + + if (url == AppOrigin) + PlatformView.EvaluateJavaScript(BlazorInitScript); + } + + private static void OnRequestInterceptStaticCallback(WebHttpRequestInterceptor interceptor) + { + if (interceptor.Headers.TryGetValue(UserAgentHeaderKey, out var agent)) { - throw new ArgumentNullException(nameof(message)); + var idx = agent.IndexOf(BlazorWebViewIdentifier); + if (idx >= 0) + { + var webviewKey = agent.Substring(idx + BlazorWebViewIdentifier.Length); + if (s_webviewHandlerTable.TryGetValue(webviewKey, out var weakHandler) + && weakHandler.TryGetTarget(out var handler)) + { + handler.OnRequestInterceptCallback(interceptor); + return; + } + } } + interceptor.Ignore(); + } - if (message.Name.Equals("BlazorHandler", StringComparison.Ordinal)) + private void OnRequestInterceptCallback(WebHttpRequestInterceptor interceptor) + { + var url = interceptor.Url; + if (url.StartsWith(AppOrigin)) { - _webviewManager!.MessageReceivedInternal(new Uri(PlatformWebView.Url), message.GetBodyAsString()); + var allowFallbackOnHostPage = url.EndsWith("/"); + url = QueryStringHelper.RemovePossibleQueryString(url); + if (_webviewManager!.TryGetResponseContentInternal(url, allowFallbackOnHostPage, out var statusCode, out var statusMessage, out var content, out var headers)) + { + var header = $"HTTP/1.0 200 OK\r\n"; + foreach (var item in headers) + { + header += $"{item.Key}:{item.Value}\r\n"; + } + header += "\r\n"; + MemoryStream memstream = new MemoryStream(); + content.CopyTo(memstream); + interceptor.SetResponse(header, memstream.ToArray()); + return; + } } + interceptor.Ignore(); } private void StartWebViewCoreIfPossible() @@ -105,14 +153,14 @@ private void StartWebViewCoreIfPossible() // We assume the host page is always in the root of the content directory, because it's // unclear there's any other use case. We can add more options later if so. - var contentRootDir = Path.GetDirectoryName(HostPage!) ?? string.Empty; - var hostPageRelativePath = Path.GetRelativePath(contentRootDir, HostPage!); + var contentRootDir = System.IO.Path.GetDirectoryName(HostPage!) ?? string.Empty; + var hostPageRelativePath = System.IO.Path.GetRelativePath(contentRootDir, HostPage!); var fileProvider = VirtualView.CreateFileProvider(contentRootDir); _webviewManager = new TizenWebViewManager( this, - PlatformWebView, + PlatformView, Services!, new MauiDispatcher(Services!.GetRequiredService()), fileProvider, @@ -125,7 +173,7 @@ private void StartWebViewCoreIfPossible() VirtualView.BlazorWebViewInitializing(new BlazorWebViewInitializingEventArgs()); VirtualView.BlazorWebViewInitialized(new BlazorWebViewInitializedEventArgs { - WebView = PlatformWebView, + WebView = PlatformView, }); if (RootComponents != null) @@ -139,50 +187,6 @@ private void StartWebViewCoreIfPossible() _webviewManager.Navigate("/"); } - private void OnRequestInterceptCallback(IntPtr context, IntPtr request, IntPtr userdata) - { - if (request == IntPtr.Zero) - { - return; - } - - var url = PlatformWebView.GetInterceptRequestUrl(request); - - if (url.StartsWith(AppOrigin)) - { - var allowFallbackOnHostPage = url.EndsWith("/"); - url = QueryStringHelper.RemovePossibleQueryString(url); - if (_webviewManager!.TryGetResponseContentInternal(url, allowFallbackOnHostPage, out var statusCode, out var statusMessage, out var content, out var headers)) - { - var header = $"HTTP/1.0 200 OK\r\n"; - foreach (var item in headers) - { - header += $"{item.Key}:{item.Value}\r\n"; - } - header += "\r\n"; - - using (MemoryStream memstream = new MemoryStream()) - { - content.CopyTo(memstream); - var body = memstream.ToArray(); - PlatformWebView.SetInterceptRequestResponse(request, header, body, (uint)body.Length); - } - return; - } - } - - PlatformWebView.IgnoreInterceptRequest(request); - } - - private void OnLoadFinished(object? sender, EventArgs e) - { - PlatformWebView.SetFocus(true); - var url = PlatformWebView.Url; - - if (url == AppOrigin) - PlatformWebView.Eval(BlazorInitScript); - } - internal IFileProvider CreateFileProvider(string contentRootDir) { return new TizenMauiAssetFileProvider(contentRootDir); diff --git a/src/BlazorWebView/src/Maui/Tizen/TizenWebViewManager.cs b/src/BlazorWebView/src/Maui/Tizen/TizenWebViewManager.cs index 967fe158cafa..01476c1e901c 100644 --- a/src/BlazorWebView/src/Maui/Tizen/TizenWebViewManager.cs +++ b/src/BlazorWebView/src/Maui/Tizen/TizenWebViewManager.cs @@ -4,7 +4,7 @@ using System.Text.Encodings.Web; using Microsoft.AspNetCore.Components.Web; using Microsoft.Extensions.FileProviders; -using TWebView = Tizen.WebView.WebView; +using NWebView = Tizen.NUI.BaseComponents.WebView; namespace Microsoft.AspNetCore.Components.WebView.Maui { @@ -17,7 +17,7 @@ public class TizenWebViewManager : WebViewManager private const string AppOrigin = "http://0.0.0.0/"; private readonly BlazorWebViewHandler _blazorMauiWebViewHandler; - private readonly TWebView _webview; + private readonly NWebView _webview; private readonly string _contentRootRelativeToAppRoot; /// @@ -31,7 +31,7 @@ public class TizenWebViewManager : WebViewManager /// Describes configuration for adding, removing, and updating root components from JavaScript code. /// Path to the directory containing application content files. /// Path to the host page within the fileProvider. - public TizenWebViewManager(BlazorWebViewHandler blazorMauiWebViewHandler, TWebView webview, IServiceProvider provider, Dispatcher dispatcher, IFileProvider fileProvider, JSComponentConfigurationStore jsComponents, string contentRootRelativeToAppRoot, string hostPageRelativePath) + public TizenWebViewManager(BlazorWebViewHandler blazorMauiWebViewHandler, NWebView webview, IServiceProvider provider, Dispatcher dispatcher, IFileProvider fileProvider, JSComponentConfigurationStore jsComponents, string contentRootRelativeToAppRoot, string hostPageRelativePath) : base(provider, dispatcher, new Uri(AppOrigin), fileProvider, jsComponents, hostPageRelativePath) { _blazorMauiWebViewHandler = blazorMauiWebViewHandler ?? throw new ArgumentNullException(nameof(blazorMauiWebViewHandler)); @@ -58,7 +58,7 @@ protected override void NavigateCore(Uri absoluteUri) protected override void SendMessage(string message) { var messageJSStringLiteral = JavaScriptEncoder.Default.Encode(message); - _webview.Eval($"__dispatchMessageCallback(\"{messageJSStringLiteral}\")"); + _webview.EvaluateJavaScript($"__dispatchMessageCallback(\"{messageJSStringLiteral}\")"); } internal void MessageReceivedInternal(Uri uri, string message) diff --git a/src/BlazorWebView/src/Maui/Tizen/WebViewContainer.cs b/src/BlazorWebView/src/Maui/Tizen/WebViewContainer.cs deleted file mode 100644 index beb14251deee..000000000000 --- a/src/BlazorWebView/src/Maui/Tizen/WebViewContainer.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using Tizen.UIExtensions.ElmSharp; -using ElmSharp; -using TWebView = Tizen.WebView.WebView; - -namespace Microsoft.AspNetCore.Components.WebView.Maui -{ - /// - /// A Tizen WebView browser control container. - /// - public class WebViewContainer : WidgetLayout - { - - /// - /// A Tizen WebView. - /// - public TWebView WebView { get; } - - /// - /// Initializes a new instance of - /// - /// The . - public WebViewContainer(EvasObject parent) : base(parent) - { - WebView = new TWebView(parent); - SetContent(WebView); - AllowFocus(true); - Focused += OnFocused; - Unfocused += OnUnfocused; - } - - void OnFocused(object? sender, EventArgs e) - { - WebView.SetFocus(true); - } - - void OnUnfocused(object? sender, EventArgs e) - { - WebView.SetFocus(false); - } - } -} diff --git a/src/BlazorWebView/src/Maui/Tizen/WebViewExtensions.cs b/src/BlazorWebView/src/Maui/Tizen/WebViewExtensions.cs deleted file mode 100644 index fcd21554eea7..000000000000 --- a/src/BlazorWebView/src/Maui/Tizen/WebViewExtensions.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using TWebView = Tizen.WebView.WebView; - -namespace Microsoft.AspNetCore.Components.WebView.Maui -{ - /// - /// WebViewExtension - /// - internal static class WebViewExtensions - { - public const string ChromiumEwk = "libchromium-ewk.so"; - - public static void SetInterceptRequestCallback(this TWebView webView, InterceptRequestCallback callback) - { - var context = webView.GetContext(); - var handleField = context.GetType().GetField("_handle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); - var contextHandle = (IntPtr?)handleField?.GetValue(context); - if (contextHandle != null) - ewk_context_intercept_request_callback_set(contextHandle.Value, callback, IntPtr.Zero); - } - - public static void SetInspectorStart(this TWebView webView, uint port) - { - var context = webView.GetContext(); - var handleField = context.GetType().GetField("_handle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); - var contextHandle = (IntPtr?)handleField?.GetValue(context); - if (contextHandle != null) - ewk_context_inspector_server_start(contextHandle.Value, port); - } - - public static bool SetInterceptRequestResponse(this TWebView webView, IntPtr request, string header, byte[] body, uint length) - { - return ewk_intercept_request_response_set(request, header, body, length); - } - - public static bool IgnoreInterceptRequest(this TWebView webView, IntPtr request) - { - return ewk_intercept_request_ignore(request); - } - - public static string GetInterceptRequestUrl(this TWebView webView, IntPtr request) - { - return Marshal.PtrToStringAnsi(_ewk_intercept_request_url_get(request)) ?? string.Empty; - } - - [DllImport(ChromiumEwk)] - internal static extern IntPtr ewk_view_context_get(IntPtr obj); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void InterceptRequestCallback(IntPtr context, IntPtr request, IntPtr userData); - - [DllImport(ChromiumEwk)] - internal static extern void ewk_context_intercept_request_callback_set(IntPtr context, InterceptRequestCallback callback, IntPtr userData); - - [DllImport(ChromiumEwk, EntryPoint = "ewk_intercept_request_url_get")] - internal static extern IntPtr _ewk_intercept_request_url_get(IntPtr request); - - [DllImport(ChromiumEwk, EntryPoint = "ewk_intercept_request_http_method_get")] - internal static extern IntPtr _ewk_intercept_request_http_method_get(IntPtr request); - - internal static string ewk_intercept_request_http_method_get(IntPtr request) - { - return Marshal.PtrToStringAnsi(_ewk_intercept_request_http_method_get(request)) ?? string.Empty; - } - - [DllImport(ChromiumEwk)] - public static extern uint ewk_context_inspector_server_start(IntPtr context, uint port); - - [DllImport(ChromiumEwk)] - internal static extern bool ewk_intercept_request_ignore(IntPtr request); - - [DllImport(ChromiumEwk)] - internal static extern bool ewk_intercept_request_response_set(IntPtr request, string header, string body, uint length); - - [DllImport(ChromiumEwk)] - internal static extern bool ewk_intercept_request_response_set(IntPtr request, string header, byte[] body, uint length); - } -} diff --git a/src/BlazorWebView/src/SharedSource/BlazorWebViewInitializedEventArgs.cs b/src/BlazorWebView/src/SharedSource/BlazorWebViewInitializedEventArgs.cs index a7de76a6afd9..4d7c1b27ab1c 100644 --- a/src/BlazorWebView/src/SharedSource/BlazorWebViewInitializedEventArgs.cs +++ b/src/BlazorWebView/src/SharedSource/BlazorWebViewInitializedEventArgs.cs @@ -14,7 +14,7 @@ #elif IOS || MACCATALYST using WebKit; #elif TIZEN -using TWebView = Tizen.WebView.WebView; +using TWebView = Tizen.NUI.BaseComponents.WebView; #endif namespace Microsoft.AspNetCore.Components.WebView diff --git a/src/Compatibility/Core/src/AppHostBuilderExtensions.Tizen.cs b/src/Compatibility/Core/src/AppHostBuilderExtensions.Tizen.cs index 3142d9fcf9e2..16733fe69a85 100644 --- a/src/Compatibility/Core/src/AppHostBuilderExtensions.Tizen.cs +++ b/src/Compatibility/Core/src/AppHostBuilderExtensions.Tizen.cs @@ -27,7 +27,7 @@ static void OnConfigureLifeCycle(ITizenLifecycleBuilder tizen) var options = services.GetService(); if (options == null) { - options = new InitializationOptions(MauiApplication.Current) + options = new InitializationOptions() { DisplayResolutionUnit = TDeviceInfo.DisplayResolutionUnit.ToCompatibility(TDeviceInfo.ViewPortWidth) }; @@ -38,6 +38,7 @@ static void OnConfigureLifeCycle(ITizenLifecycleBuilder tizen) TDeviceInfo.DisplayResolutionUnit = options.DisplayResolutionUnit.ToDeviceInfo(); } options.Flags |= InitializationFlags.SkipRenderers; +#pragma warning disable CS0612 // Type or member is obsolete Forms.Init(state, options); #pragma warning disable CS0612 // Type or member is obsolete }) diff --git a/src/Compatibility/Core/src/AppHostBuilderExtensions.cs b/src/Compatibility/Core/src/AppHostBuilderExtensions.cs index 05ba74189f44..7435028e5c20 100644 --- a/src/Compatibility/Core/src/AppHostBuilderExtensions.cs +++ b/src/Compatibility/Core/src/AppHostBuilderExtensions.cs @@ -36,20 +36,10 @@ #elif TIZEN using Microsoft.Maui.Controls.Compatibility.Platform.Tizen; using Microsoft.Maui.Graphics.Skia; -using BoxRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Tizen.BoxViewRenderer; -using CollectionViewRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Tizen.StructuredItemsViewRenderer; 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; -using FrameRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Tizen.SkiaSharp.FrameRenderer; -using ImageRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Tizen.SkiaSharp.ImageRenderer; -using EllipseRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Tizen.SkiaSharp.EllipseRenderer; -using LineRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Tizen.SkiaSharp.LineRenderer; -using PathRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Tizen.SkiaSharp.PathRenderer; -using PolygonRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Tizen.SkiaSharp.PolygonRenderer; -using PolylineRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Tizen.SkiaSharp.PolylineRenderer; -using RectangleRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Tizen.SkiaSharp.RectangleRenderer; #endif namespace Microsoft.Maui.Controls.Compatibility.Hosting @@ -106,32 +96,11 @@ public static MauiAppBuilder UseMauiCompatibility(this MauiAppBuilder builder) #pragma warning restore CS0618 // Type or member is obsolete #pragma warning restore CS0612 // Type or member is obsolete -#if TIZEN -#pragma warning disable CS0618 // Type or member is obsolete -#pragma warning disable CS0612 // Type or member is obsolete - handlers.TryAddCompatibilityRenderer(typeof(ContentView), typeof(LayoutRenderer)); - handlers.TryAddCompatibilityRenderer(typeof(TabbedPage), typeof(TabbedPageRenderer)); - handlers.TryAddCompatibilityRenderer(typeof(NavigationPage), typeof(NavigationPageRenderer)); - handlers.TryAddCompatibilityRenderer(typeof(FlyoutPage), typeof(FlyoutPageRenderer)); - handlers.TryAddCompatibilityRenderer(typeof(ListView), typeof(ListViewRenderer)); - handlers.TryAddCompatibilityRenderer(typeof(Cell), typeof(CellRenderer)); - handlers.TryAddCompatibilityRenderer(typeof(ImageCell), typeof(ImageCellRenderer)); - handlers.TryAddCompatibilityRenderer(typeof(EntryCell), typeof(EntryCellRenderer)); - handlers.TryAddCompatibilityRenderer(typeof(TextCell), typeof(TextCellRenderer)); - handlers.TryAddCompatibilityRenderer(typeof(ViewCell), typeof(ViewCellRenderer)); - handlers.TryAddCompatibilityRenderer(typeof(SwitchCell), typeof(SwitchCellRenderer)); - handlers.TryAddCompatibilityRenderer(typeof(TableView), typeof(TableViewRenderer)); - handlers.TryAddCompatibilityRenderer(typeof(Frame), typeof(FrameRenderer)); -#pragma warning disable CS0612 // Type or member is obsolete -#pragma warning disable CS0618 // Type or member is obsolete -#endif // Shimmed renderers go directly to the registrar to load Image Handlers Internals.Registrar.Registered.Register(typeof(FileImageSource), typeof(FileImageSourceHandler)); Internals.Registrar.Registered.Register(typeof(StreamImageSource), typeof(StreamImagesourceHandler)); Internals.Registrar.Registered.Register(typeof(UriImageSource), typeof(ImageLoaderSourceHandler)); -#if !TIZEN Internals.Registrar.Registered.Register(typeof(FontImageSource), typeof(FontImageSourceHandler)); -#endif Internals.Registrar.Registered.Register(typeof(Microsoft.Maui.EmbeddedFont), typeof(Microsoft.Maui.EmbeddedFontLoader)); #endif diff --git a/src/Compatibility/Core/src/RendererToHandlerShim.Tizen.cs b/src/Compatibility/Core/src/RendererToHandlerShim.Tizen.cs index 691b94b57da1..dedec31b3bba 100644 --- a/src/Compatibility/Core/src/RendererToHandlerShim.Tizen.cs +++ b/src/Compatibility/Core/src/RendererToHandlerShim.Tizen.cs @@ -3,9 +3,7 @@ using static Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Platform; #pragma warning disable CS0612 // Type or member is obsolete using Microsoft.Maui.Graphics; -using Rect = Microsoft.Maui.Graphics.Rect; -using ERect = ElmSharp.Rect; -using PlatformView = ElmSharp.EvasObject; +using PlatformView = Tizen.NUI.BaseComponents.View; namespace Microsoft.Maui.Controls.Compatibility { @@ -40,17 +38,14 @@ public override void UpdateValue(string property) } } + public override bool NeedsContainer => false; + public override void PlatformArrange(Rect frame) { base.PlatformArrange(frame); VisualElementRenderer.UpdateLayout(); } - public override ERect GetPlatformContentGeometry() - { - return VisualElementRenderer?.GetNativeContentGeometry() ?? new ERect(); - } - protected override void Dispose(bool disposing) { if (disposing) diff --git a/src/Compatibility/Core/src/RendererToHandlerShim.cs b/src/Compatibility/Core/src/RendererToHandlerShim.cs index a4355932412a..3a78c9059f0b 100644 --- a/src/Compatibility/Core/src/RendererToHandlerShim.cs +++ b/src/Compatibility/Core/src/RendererToHandlerShim.cs @@ -21,10 +21,9 @@ #elif TIZEN #pragma warning disable CS0612 // Type or member is obsolete using static Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Platform; -#pragma warning disable CS0612 // Type or member is obsolete -using PlatformView = ElmSharp.EvasObject; +using PlatformView = Tizen.NUI.BaseComponents.View; using Microsoft.Maui.Controls.Compatibility.Platform.Tizen; -using ViewHandler = Microsoft.Maui.Handlers.ViewHandler; +using ViewHandler = Microsoft.Maui.Handlers.ViewHandler; #elif (NETSTANDARD || !PLATFORM) using PlatformView = System.Object; using ViewHandler = Microsoft.Maui.Handlers.ViewHandler; diff --git a/src/Compatibility/Core/src/Tizen/Cells/CellRenderer.cs b/src/Compatibility/Core/src/Tizen/Cells/CellRenderer.cs deleted file mode 100644 index 9ef5ce207515..000000000000 --- a/src/Compatibility/Core/src/Tizen/Cells/CellRenderer.cs +++ /dev/null @@ -1,198 +0,0 @@ -using System.Collections.Generic; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [System.Obsolete(Compatibility.Hosting.MauiAppBuilderExtensions.UseMapperInstead)] - public abstract class CellRenderer : IRegisterable - { - const string HeightProperty = "Height"; - readonly Dictionary> _realizedNativeViews = new Dictionary>(); - - Native.ListView.ItemContext _currentItem; - GenItemClass _itemClass; - - protected CellRenderer(string style) - { - Style = style; - } - - public GenItemClass Class - { - get - { - if (_itemClass == null) - _itemClass = CreateItemClass(Style); - return _itemClass; - } - protected set - { - _itemClass?.Dispose(); - _itemClass = value; - } - } - - public virtual void SetGroupMode(bool enable) - { - } - - public string Style { get; protected set; } - - protected GenItemClass CreateItemClass(string style) - { - return new GenItemClass(style) - { - GetTextHandler = GetText, - GetContentHandler = GetContent, - DeleteHandler = ItemDeleted, - ReusableContentHandler = ReusableContent, - }; - } - - protected virtual bool OnCellPropertyChanged(Cell cell, string property, Dictionary realizedView) - { - if (property == HeightProperty) - { - return true; - } - return false; - } - - protected virtual Span OnGetText(Cell cell, string part) - { - return null; - } - protected virtual EvasObject OnGetContent(Cell cell, string part) - { - return null; - } - - protected virtual void OnCreated(Cell cell, bool isGroup) - { - } - - protected virtual void OnDeleted(Cell cell) - { - } - - protected virtual void OnUnrealizedCell(Cell cell) - { - } - - protected virtual EvasObject OnReusableContent(Cell cell, string part, EvasObject old) - { - return null; - } - - protected double FindCellContentHeight(Cell cell) - { - ViewCell viewCell = cell as ViewCell; - if (viewCell != null) - { - var parentWidth = (cell.Parent as VisualElement).Width; - var view = viewCell.View; - return view.Measure(parentWidth, double.PositiveInfinity).Request.Height; - } - else - return -1; - } - - static Native.Span ToNative(Span span) - { - var nativeSpan = new Native.Span(); - nativeSpan.Text = span.Text; - nativeSpan.ForegroundColor = span.TextColor.ToNative(); - nativeSpan.FontAttributes = span.FontAttributes; - nativeSpan.BackgroundColor = span.BackgroundColor.ToNative(); - nativeSpan.FontSize = span.FontSize; - nativeSpan.FontFamily = span.FontFamily; - return nativeSpan; - } - - public void SendCellPropertyChanged(Cell cell, GenItem item, string property) - { - Dictionary realizedView = null; - _realizedNativeViews.TryGetValue(cell, out realizedView); - - // just to prevent null reference exception in OnCellPropertyChanged - realizedView = realizedView ?? new Dictionary(); - - if (property == Cell.IsEnabledProperty.PropertyName) - { - item.IsEnabled = cell.IsEnabled; - } - // if true was returned, item was updated - // if it's possible to update the cell property without Update(), return false - else if (OnCellPropertyChanged(cell, property, realizedView)) - { - item.Update(); - } - } - - public void SendUnrealizedCell(Cell cell) - { - Dictionary realizedView = null; - _realizedNativeViews.TryGetValue(cell, out realizedView); - realizedView?.Clear(); - OnUnrealizedCell(cell); - } - - public void SendCreatedCell(Cell cell, bool isGroup = false) - { - OnCreated(cell, isGroup); - } - - internal Native.ListView.ItemContext GetCurrentItem() - { - return _currentItem; - } - - string GetText(object data, string part) - { - _currentItem = data as Native.ListView.ItemContext; - var span = OnGetText(_currentItem.Cell, part); - return span != null ? ToNative(span).GetMarkupText() : null; - } - - EvasObject GetContent(object data, string part) - { - _currentItem = data as Native.ListView.ItemContext; - var cell = _currentItem.Cell; - EvasObject nativeView = OnGetContent(cell, part); - UpdateRealizedView(cell, part, nativeView); - return nativeView; - } - - EvasObject ReusableContent(object data, string part, EvasObject old) - { - _currentItem = data as Native.ListView.ItemContext; - var cell = _currentItem.Cell; - EvasObject nativeView = OnReusableContent(cell, part, old); - UpdateRealizedView(cell, part, nativeView); - return nativeView; - } - - void UpdateRealizedView(Cell cell, string part, EvasObject nativeView) - { - if (part != null && nativeView != null) - { - Dictionary realizedView = null; - _realizedNativeViews.TryGetValue(cell, out realizedView); - if (realizedView == null) - { - realizedView = new Dictionary(); - _realizedNativeViews[cell] = realizedView; - } - realizedView[part] = nativeView; - } - } - - void ItemDeleted(object data) - { - _currentItem = data as Native.ListView.ItemContext; - var cell = _currentItem.Cell; - _realizedNativeViews.Remove(cell); - OnDeleted(cell); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Cells/EntryCellRenderer.cs b/src/Compatibility/Core/src/Tizen/Cells/EntryCellRenderer.cs deleted file mode 100644 index 55ab30338cef..000000000000 --- a/src/Compatibility/Core/src/Tizen/Cells/EntryCellRenderer.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using ElmSharp; -using XStackLayout = Microsoft.Maui.Controls.StackLayout; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [System.Obsolete(Compatibility.Hosting.MauiAppBuilderExtensions.UseMapperInstead)] - public class EntryCellRenderer : ViewCellRenderer - { - readonly Dictionary _cacheCandidate = new Dictionary(); - - public EntryCellRenderer() - { - } - - protected override EvasObject OnGetContent(Cell cell, string part) - { - if (part == MainContentPart) - { - var entryCell = cell as EntryCell; - int pixelHeight = Forms.ConvertToScaledPixel(entryCell.RenderHeight); - pixelHeight = pixelHeight > 0 ? pixelHeight : this.GetDefaultHeightPixel(); - - var label = new Label() - { - HorizontalOptions = LayoutOptions.Start, - VerticalOptions = LayoutOptions.Center, - VerticalTextAlignment = TextAlignment.Center, - FontSize = -1 - }; - label.SetBinding(Label.TextProperty, new Binding(EntryCell.LabelProperty.PropertyName)); - label.SetBinding(Label.TextColorProperty, new Binding(EntryCell.LabelColorProperty.PropertyName, converter: new DefaultColorConverter())); - - var entry = new Entry() - { - HorizontalOptions = LayoutOptions.Fill, - VerticalOptions = LayoutOptions.Center, - FontSize = -1, - }; - entry.SetBinding(Entry.TextProperty, new Binding(EntryCell.TextProperty.PropertyName, BindingMode.TwoWay)); - entry.SetBinding(Entry.PlaceholderProperty, new Binding(EntryCell.PlaceholderProperty.PropertyName)); - entry.SetBinding(InputView.KeyboardProperty, new Binding(EntryCell.KeyboardProperty.PropertyName)); - entry.SetBinding(Entry.HorizontalTextAlignmentProperty, new Binding(EntryCell.HorizontalTextAlignmentProperty.PropertyName)); - - var layout = new XStackLayout() - { - Orientation = StackOrientation.Horizontal, - Children = { - label, - entry - } - }; - layout.Parent = cell; - layout.BindingContext = entryCell; - layout.MinimumHeightRequest = Forms.ConvertToScaledDP(pixelHeight); - - var renderer = Platform.GetOrCreateRenderer(layout); - (renderer as ILayoutRenderer)?.RegisterOnLayoutUpdated(); - - var nativeEntry = Platform.GetRenderer(entry)?.NativeView ?? null; - if (nativeEntry != null) - { - nativeEntry.PropagateEvents = false; - } - - var nativeView = renderer.NativeView; - nativeView.MinimumHeight = pixelHeight; - _cacheCandidate[nativeView] = layout; - nativeView.Deleted += (sender, e) => - { - _cacheCandidate.Remove(sender as EvasObject); - }; - - return nativeView; - } - return null; - } - - protected override EvasObject OnReusableContent(Cell cell, string part, EvasObject old) - { - if (!_cacheCandidate.ContainsKey(old)) - { - return null; - } - - var layout = _cacheCandidate[old]; - layout.BindingContext = cell; - int height = Forms.ConvertToScaledPixel(cell.RenderHeight); - height = height > 0 ? height : this.GetDefaultHeightPixel(); - old.MinimumHeight = height; - return old; - } - - class DefaultColorConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - return (value == null || ((Color)value).IsDefault) ? ThemeConstants.EntryCell.ColorClass.DefaultLabelColor : value; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - return value; - } - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Cells/ImageCellRenderer.cs b/src/Compatibility/Core/src/Tizen/Cells/ImageCellRenderer.cs deleted file mode 100644 index d11c12561ded..000000000000 --- a/src/Compatibility/Core/src/Tizen/Cells/ImageCellRenderer.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.Collections.Generic; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [System.Obsolete(Compatibility.Hosting.MauiAppBuilderExtensions.UseMapperInstead)] - public class ImageCellRenderer : TextCellRenderer - { - public ImageCellRenderer() : this(ThemeManager.GetImageCellRendererStyle()) - { - ImagePart = this.GetImagePart(); - } - - protected ImageCellRenderer(string style) : base(style) - { - } - - protected string ImagePart { get; set; } - - protected override EvasObject OnGetContent(Cell cell, string part) - { - if (part == ImagePart) - { - var imgCell = cell as ImageCell; - int pixelSize = Forms.ConvertToScaledPixel(imgCell.RenderHeight); - if (pixelSize <= 0) - { - pixelSize = this.GetDefaultHeightPixel(); - } - - var image = new Native.Image(Forms.NativeParent) - { - MinimumWidth = pixelSize, - MinimumHeight = pixelSize - }; - image.SetAlignment(-1.0, -1.0); // fill - image.SetWeight(1.0, 1.0); // expand - - var task = image.LoadFromImageSourceAsync(imgCell.ImageSource); - return image; - } - else - { - return null; - } - } - - protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary realizedView) - { - if (property == ImageCell.ImageSourceProperty.PropertyName) - { - EvasObject image; - realizedView.TryGetValue(ImagePart, out image); - (image as Native.Image)?.LoadFromImageSourceAsync((cell as ImageCell)?.ImageSource); - return false; - } - return base.OnCellPropertyChanged(cell, property, realizedView); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Cells/SwitchCellRenderer.cs b/src/Compatibility/Core/src/Tizen/Cells/SwitchCellRenderer.cs deleted file mode 100644 index ff1475b201bd..000000000000 --- a/src/Compatibility/Core/src/Tizen/Cells/SwitchCellRenderer.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System.Collections.Generic; -using Microsoft.Maui.Devices; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [System.Obsolete(Compatibility.Hosting.MauiAppBuilderExtensions.UseMapperInstead)] - public class SwitchCellRenderer : CellRenderer - { - readonly Dictionary _cacheCandidate = new Dictionary(); - - protected SwitchCellRenderer(string style) : base(style) - { - } - - public SwitchCellRenderer() : this(ThemeManager.GetSwitchCellRendererStyle()) - { - MainPart = this.GetMainPart(); - SwitchPart = this.GetSwitchPart(); - } - - protected string MainPart { get; set; } - protected string SwitchPart { get; set; } - - protected override Span OnGetText(Cell cell, string part) - { - if (part == MainPart) - { - return new Span() - { - Text = (cell as SwitchCell).Text - }; - } - return null; - } - - protected override EvasObject OnGetContent(Cell cell, string part) - { - if (part == SwitchPart) - { - var toggle = new Switch() - { - BindingContext = cell, - Parent = cell.Parent - }; - toggle.SetBinding(Switch.IsToggledProperty, new Binding(SwitchCell.OnProperty.PropertyName)); - toggle.SetBinding(Switch.OnColorProperty, new Binding(SwitchCell.OnColorProperty.PropertyName)); - var nativeView = Platform.GetOrCreateRenderer(toggle).NativeView; - - if (DeviceInfo.Idiom == DeviceIdiom.Watch) - { - nativeView.MinimumWidth += 8; - } - - //It is a temporary way to prevent that the check of the Cell gets focus until the UX about views in the Cell for TV is defined. - if (DeviceInfo.Idiom == DeviceIdiom.TV) - { - ((Check)nativeView).AllowFocus(false); - } - else - { - nativeView.PropagateEvents = false; - } - - _cacheCandidate[nativeView] = toggle; - nativeView.Deleted += (sender, e) => - { - _cacheCandidate.Remove(sender as EvasObject); - }; - - return nativeView; - } - return null; - } - - protected override EvasObject OnReusableContent(Cell cell, string part, EvasObject old) - { - if (!_cacheCandidate.ContainsKey(old)) - { - return null; - } - _cacheCandidate[old].BindingContext = cell; - return old; - } - - protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary realizedView) - { - if (property == SwitchCell.TextProperty.PropertyName) - { - return true; - } - return base.OnCellPropertyChanged(cell, property, realizedView); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Cells/TextCellRenderer.cs b/src/Compatibility/Core/src/Tizen/Cells/TextCellRenderer.cs deleted file mode 100644 index 4c89702d5e11..000000000000 --- a/src/Compatibility/Core/src/Tizen/Cells/TextCellRenderer.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System.Collections.Generic; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [System.Obsolete(Compatibility.Hosting.MauiAppBuilderExtensions.UseMapperInstead)] - public class TextCellRenderer : CellRenderer - { - bool _groupMode = false; - // TextCell.Detail property is not supported on TV profile due to UX limitation. - public TextCellRenderer() : this(ThemeManager.GetTextCellRendererStyle()) { } - - protected TextCellRenderer(string style) : base(style) - { - MainPart = this.GetMainPart(); - DetailPart = this.GetDetailPart(); - } - - protected string MainPart { get; set; } - protected string DetailPart { get; set; } - - public override void SetGroupMode(bool enable) - { - if (_groupMode == enable) - return; - - _groupMode = enable; - Class = null; - Style = ThemeManager.GetTextCellGroupModeStyle(enable); - DetailPart = this.GetDetailPart(); - } - - protected override Span OnGetText(Cell cell, string part) - { - var textCell = (TextCell)cell; - if (part == MainPart) - { - return OnMainText(textCell); - } - if (part == DetailPart) - { - return OnDetailText(textCell); - } - return null; - } - - protected virtual Span OnMainText(TextCell cell) - { - return new Span() - { - Text = cell.Text, - TextColor = cell.TextColor, - FontSize = -1 - }; - } - - protected virtual Span OnDetailText(TextCell cell) - { - return new Span() - { - Text = cell.Detail, - TextColor = cell.DetailColor, - FontSize = -1 - }; - } - - protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary realizedView) - { - if (property == TextCell.TextProperty.PropertyName || - property == TextCell.TextColorProperty.PropertyName || - property == TextCell.DetailProperty.PropertyName || - property == TextCell.DetailColorProperty.PropertyName) - { - return true; - } - return base.OnCellPropertyChanged(cell, property, realizedView); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Cells/ViewCellRenderer.cs b/src/Compatibility/Core/src/Tizen/Cells/ViewCellRenderer.cs deleted file mode 100644 index 7351d27fe6fb..000000000000 --- a/src/Compatibility/Core/src/Tizen/Cells/ViewCellRenderer.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System.Collections.Generic; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [System.Obsolete(Compatibility.Hosting.MauiAppBuilderExtensions.UseMapperInstead)] - public class ViewCellRenderer : CellRenderer - { - readonly Dictionary _cacheCandidate = new Dictionary(); - public ViewCellRenderer() : base(ThemeManager.GetViewCellRendererStyle()) - { - MainContentPart = this.GetMainContentPart(); - } - - protected string MainContentPart { get; set; } - - protected override EvasObject OnReusableContent(Cell cell, string part, EvasObject old) - { - if (_cacheCandidate.ContainsKey(old)) - { - var viewCell = _cacheCandidate[old]; - var widget = (old as Widget); - if (widget != null) - widget.IsEnabled = true; - viewCell.BindingContext = cell.BindingContext; - return old; - } - return null; - } - - protected override EvasObject OnGetContent(Cell cell, string part) - { - if (part == MainContentPart) - { - var viewCell = (ViewCell)cell; - - var listView = viewCell?.RealParent as ListView; - - // It is a condition for reusable the cell - if (listView != null && - listView.HasUnevenRows == false && - !(listView.ItemTemplate is DataTemplateSelector) && !GetCurrentItem().IsGroupItem) - { - return CreateReusableContent(viewCell); - } - - Platform.GetRenderer(viewCell.View)?.Dispose(); - var renderer = Platform.GetOrCreateRenderer(viewCell.View); - double height = viewCell.RenderHeight; - height = height > 0 ? height : FindCellContentHeight(viewCell); - - renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(height); - (renderer as ILayoutRenderer)?.RegisterOnLayoutUpdated(); - - UpdatePropagateEvent(viewCell.View); - - return renderer.NativeView; - } - return null; - } - - protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary realizedView) - { - if (property == "View") - { - return true; - } - return base.OnCellPropertyChanged(cell, property, realizedView); - } - - EvasObject CreateReusableContent(ViewCell viewCell) - { - var listView = viewCell.RealParent as ListView; - ViewCell duplicatedCell = (ViewCell)listView.ItemTemplate.CreateContent(); - duplicatedCell.BindingContext = viewCell.BindingContext; - duplicatedCell.Parent = listView; - - var renderer = Platform.GetOrCreateRenderer(duplicatedCell.View); - double height = duplicatedCell.RenderHeight; - height = height > 0 ? height : FindCellContentHeight(duplicatedCell); - renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(height); - - _cacheCandidate[renderer.NativeView] = duplicatedCell; - renderer.NativeView.Deleted += (sender, e) => - { - _cacheCandidate.Remove((EvasObject)sender); - }; - (renderer as ILayoutRenderer)?.RegisterOnLayoutUpdated(); - - UpdatePropagateEvent(duplicatedCell.View); - return renderer.NativeView; - } - - void UpdatePropagateEvent(View view) - { - if (!view.IsPlatformEnabled) - return; - foreach (var element in view.Descendants()) - { - if (element is Button || element is Switch) - { - var nativeView = Platform.GetRenderer(element)?.NativeView ?? null; - if (nativeView != null) - { - nativeView.PropagateEvents = false; - } - } - } - } - - } -} diff --git a/src/Compatibility/Core/src/Tizen/DragGestureHandler.cs b/src/Compatibility/Core/src/Tizen/DragGestureHandler.cs deleted file mode 100644 index dc1e4001adb0..000000000000 --- a/src/Compatibility/Core/src/Tizen/DragGestureHandler.cs +++ /dev/null @@ -1,247 +0,0 @@ -using System; -using System.Threading; -using ElmSharp; -using Tizen.Common; -using Microsoft.Maui.Controls.Compatibility.Platform.Tizen.SkiaSharp; -using EGestureType = ElmSharp.GestureLayer.GestureType; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [Obsolete] - public class DragGestureHandler : GestureHandler - { - bool _isApi4; - - DragDropExtensions.Interop.DragIconCreateCallback _iconCallback; - DragDropExtensions.Interop.DragStateCallback _dragDoneCallback; - - static bool s_isDragging; - static CustomDragStateData s_currentDragStateData; - - public DragGestureHandler(IGestureRecognizer recognizer, IVisualElementRenderer renderer) : base(recognizer) - { - _iconCallback = OnIconCallback; - _dragDoneCallback = OnDragDoneCallback; - _isApi4 = DotnetUtil.TizenAPIVersion <= 4; - Renderer = renderer; - } - - public override EGestureType Type => EGestureType.LongTap; - - public IVisualElementRenderer Renderer { get; } - - public static CustomDragStateData CurrentStateData - { - get - { - return s_currentDragStateData; - } - } - - EvasObject NativeView - { - get - { - var native = Renderer.NativeView; - if (Renderer is SkiaSharp.ICanvasRenderer canvasRenderer) - { - native = canvasRenderer.RealNativeView; - } - return native; - } - } - - public void ResetCurrentStateData() - { - s_currentDragStateData = null; - } - - protected override void OnStarted(View sender, object data) - { - } - - protected override void OnMoved(View sender, object data) - { - //Workaround to prevent an error occuring by multiple StartDrag calling in Tizen 6.5 - if (!s_isDragging) - { - ResetCurrentStateData(); - StartDrag(); - } - } - - protected override void OnCompleted(View sender, object data) - { - } - - protected override void OnCanceled(View sender, object data) - { - } - - void StartDrag() - { - if (Recognizer is DragGestureRecognizer dragGestureRecognizer && dragGestureRecognizer.CanDrag) - { - if (Renderer == null) - return; - - if (Renderer.Element is not View view) - return; - - var arg = dragGestureRecognizer.SendDragStarting(view); - - if (arg.Cancel) - return; - - s_currentDragStateData = new CustomDragStateData(); - s_currentDragStateData.DataPackage = arg.Data; - - var target = DragDropExtensions.DragDropContentType.Text; - var strData = string.IsNullOrEmpty(arg.Data.Text) ? " " : arg.Data.Text; - - s_isDragging = true; - - DragDropExtensions.StartDrag(NativeView, - target, - strData, - DragDropExtensions.DragDropActionType.Move, - _iconCallback, - null, - null, - _dragDoneCallback); - } - } - - IntPtr OnIconCallback(IntPtr data, IntPtr window, ref int xoff, ref int yoff) - { - EvasObject icon = null; - EvasObject parent = new CustomWindow(NativeView, window); - - if (s_currentDragStateData.DataPackage.Image != null) - { - icon = GetImageIcon(parent); - } - else if (NativeView is ShapeView) - { - icon = GetShapeView(parent); - } - else - { - icon = GetDefaultIcon(parent); - } - var bound = NativeView.Geometry; - bound.X = 0; - bound.Y = 0; - icon.Geometry = bound; - - if (icon is Native.Label) - { - icon.Resized += (s, e) => - { - var map = new EvasMap(4); - map.PopulatePoints(icon.Geometry, 0); - map.Zoom(0.5, 0.5, 0, 0); - icon.IsMapEnabled = true; - icon.EvasMap = map; - }; - } - else - { - var map = new EvasMap(4); - map.PopulatePoints(icon.Geometry, 0); - map.Zoom(0.5, 0.5, 0, 0); - icon.IsMapEnabled = true; - icon.EvasMap = map; - } - - - return icon; - } - - EvasObject GetDefaultIcon(EvasObject parent) - { - if (!string.IsNullOrEmpty(s_currentDragStateData.DataPackage.Text)) - { - var label = new Native.Label(parent); - label.Text = s_currentDragStateData.DataPackage.Text; - - if (Renderer.Element is Label lb) - label.FontSize = lb.FontSize; - else if (Renderer.Element is Entry et) - label.FontSize = et.FontSize; - else if (Renderer.Element is Editor ed) - label.FontSize = ed.FontSize; - - return label; - } - else - { - var box = new ElmSharp.Rectangle(parent); - box.Color = new ElmSharp.Color(128, 128, 128, 128); - return box; - } - } - - EvasObject GetImageIcon(EvasObject parent) - { - var image = new Native.Image(parent); - _ = image.LoadFromImageSourceAsync(s_currentDragStateData.DataPackage.Image); - return image; - } - - EvasObject GetShapeView(EvasObject parent) - { - var copiedImg = new EvasImage(parent); - copiedImg.IsFilled = true; - - if (NativeView is ShapeView shapeView) - { - var canvas = shapeView.SKCanvasView; - var realHandle = DragDropExtensions.Interop.elm_object_part_content_get(canvas, "elm.swallow.content"); - - DragDropExtensions.Interop.evas_object_image_size_get(realHandle, out int w, out int h); - DragDropExtensions.Interop.evas_object_image_size_set(copiedImg, w, h); - - var imgData = DragDropExtensions.Interop.evas_object_image_data_get(realHandle, false); - DragDropExtensions.Interop.evas_object_image_data_set(copiedImg, imgData); - } - - return copiedImg; - } - - void OnDragDoneCallback(IntPtr data, IntPtr obj) - { - s_isDragging = false; - if (Recognizer is DragGestureRecognizer dragGestureRecognizer && dragGestureRecognizer.CanDrag) - { - dragGestureRecognizer.SendDropCompleted(new DropCompletedEventArgs()); - } - } - - public class CustomWindow : EvasObject - { - IntPtr _handle; - - public CustomWindow(EvasObject parent, IntPtr handle) : base() - { - _handle = handle; - Realize(parent); - } - - public CustomWindow(EvasObject handle) : base(handle) - { - } - - protected override IntPtr CreateHandle(EvasObject parent) - { - return _handle; - } - } - - public class CustomDragStateData - { - public DataPackage DataPackage { get; set; } - public DataPackageOperation AcceptedOperation { get; set; } = DataPackageOperation.Copy; - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/DropGestureHandler.cs b/src/Compatibility/Core/src/Tizen/DropGestureHandler.cs deleted file mode 100644 index 13b73ae158f2..000000000000 --- a/src/Compatibility/Core/src/Tizen/DropGestureHandler.cs +++ /dev/null @@ -1,134 +0,0 @@ -using System; -using System.Linq; -using ElmSharp; -using Tizen.Common; -using EGestureType = ElmSharp.GestureLayer.GestureType; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [Obsolete] - public class DropGestureHandler : GestureHandler - { - bool _isApi4; - - DragDropExtensions.Interop.DragStateCallback _dragEnterCallback; - DragDropExtensions.Interop.DragStateCallback _dragLeaveCallback; - DragDropExtensions.Interop.DropCallback _dropCallback; - - public override EGestureType Type => default(EGestureType); - - public DropGestureHandler(IGestureRecognizer recognizer, IVisualElementRenderer renderer) : base(recognizer) - { - _dragEnterCallback = OnEnterCallback; - _dragLeaveCallback = OnLeaveCallback; - _dropCallback = OnDropCallback; - _isApi4 = DotnetUtil.TizenAPIVersion <= 4; - Renderer = renderer; - } - - public IVisualElementRenderer Renderer { get; } - - EvasObject NativeView - { - get - { - var native = Renderer.NativeView; - if (Renderer is SkiaSharp.ICanvasRenderer canvasRenderer) - { - native = canvasRenderer.RealNativeView; - } - - if (native is Native.Canvas canvas) - { - var child = canvas.Children.LastOrDefault(); - - if (child != null) - { - if (child.PassEvents) - child.PassEvents = false; - - return child; - } - } - return native; - } - } - - - public void AddDropGesture() - { - if (Renderer == null) - return; - - var target = DragDropExtensions.DragDropContentType.Targets; - - DragDropExtensions.AddDropTarget(NativeView, - target, - _dragEnterCallback, - _dragLeaveCallback, null, - _dropCallback); - } - - void OnEnterCallback(IntPtr data, IntPtr obj) - { - var currentStateData = DragGestureHandler.CurrentStateData; - if (currentStateData == null) - return; - - var arg = new DragEventArgs(currentStateData.DataPackage); - - if (Recognizer is DropGestureRecognizer dropRecognizer && dropRecognizer.AllowDrop) - dropRecognizer.SendDragOver(arg); - - DragGestureHandler.CurrentStateData.AcceptedOperation = arg.AcceptedOperation; - } - - void OnLeaveCallback(IntPtr data, IntPtr obj) - { - var currentStateData = DragGestureHandler.CurrentStateData; - if (currentStateData == null) - return; - - var arg = new DragEventArgs(currentStateData.DataPackage); - - if (Recognizer is DropGestureRecognizer dropRecognizer && dropRecognizer.AllowDrop) - dropRecognizer.SendDragLeave(arg); - - DragGestureHandler.CurrentStateData.AcceptedOperation = arg.AcceptedOperation; - } - - bool OnDropCallback(IntPtr data, IntPtr obj, IntPtr selectionData) - { - var currentStateData = DragGestureHandler.CurrentStateData; - - if (currentStateData.DataPackage == null || currentStateData.AcceptedOperation == DataPackageOperation.None) - return false; - - Application.Current?.Dispatcher.Dispatch(async () => - { - if (Recognizer is DropGestureRecognizer dropRecognizer && dropRecognizer.AllowDrop) - await dropRecognizer.SendDrop(new DropEventArgs(currentStateData.DataPackage.View)); - }); - - return true; - } - - #region GestureHandler - protected override void OnStarted(View sender, object data) - { - } - - protected override void OnMoved(View sender, object data) - { - } - - protected override void OnCompleted(View sender, object data) - { - } - - protected override void OnCanceled(View sender, object data) - { - } - #endregion - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Extensions/AccessibilityExtensions.cs b/src/Compatibility/Core/src/Tizen/Extensions/AccessibilityExtensions.cs deleted file mode 100644 index 31d5923c59f0..000000000000 --- a/src/Compatibility/Core/src/Tizen/Extensions/AccessibilityExtensions.cs +++ /dev/null @@ -1,63 +0,0 @@ -using ElmSharp.Accessible; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [System.Obsolete] - public static class AccessibilityExtensions - { - public static string SetAccessibilityName(this IAccessibleObject Control, Element Element, string _defaultAccessibilityName = null) - { - if (Element == null || Control == null) - return _defaultAccessibilityName; - - if (_defaultAccessibilityName == null) - _defaultAccessibilityName = Control.Name; - - Control.Name = (string)Element.GetValue(AutomationProperties.NameProperty) ?? _defaultAccessibilityName; - return _defaultAccessibilityName; - } - - public static string SetAccessibilityDescription(this IAccessibleObject Control, Element Element, string _defaultAccessibilityDescription = null) - { - if (Element == null || Control == null) - return _defaultAccessibilityDescription; - - if (_defaultAccessibilityDescription == null) - _defaultAccessibilityDescription = Control.Description; - - Control.Description = (string)Element.GetValue(AutomationProperties.HelpTextProperty) ?? _defaultAccessibilityDescription; - return _defaultAccessibilityDescription; - } - - public static bool? SetIsAccessibilityElement(this IAccessibleObject Control, Element Element, bool? _defaultIsAccessibilityElement = null) - { - if (Element == null || Control == null) - return _defaultIsAccessibilityElement; - - if (!_defaultIsAccessibilityElement.HasValue) - _defaultIsAccessibilityElement = Control.CanHighlight; - - Control.CanHighlight = (bool)((bool?)Element.GetValue(AutomationProperties.IsInAccessibleTreeProperty) ?? _defaultIsAccessibilityElement); - - // Images are ignored by default on Tizen. So, make accessible in order to enable the gesture and narration - if (Control.CanHighlight && Element is Image) - { - Control.Role = AccessRole.PushButton; - } - return _defaultIsAccessibilityElement; - } - - public static void SetLabeledBy(this IAccessibleObject Control, Element Element) - { - if (Element == null || Control == null) - return; - - var targetElement = (VisualElement)Element.GetValue(AutomationProperties.LabeledByProperty); - AccessibleObject view = (AccessibleObject)Platform.GetRenderer(targetElement)?.NativeView; - if (view != null) - { - Control.AppendRelation(new LabelledBy() { Target = view }); - } - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Extensions/BrushExtensions.cs b/src/Compatibility/Core/src/Tizen/Extensions/BrushExtensions.cs index 4d641e206cc8..1f78c07e5ce3 100644 --- a/src/Compatibility/Core/src/Tizen/Extensions/BrushExtensions.cs +++ b/src/Compatibility/Core/src/Tizen/Extensions/BrushExtensions.cs @@ -1,8 +1,9 @@ using System; using System.Linq; +using Microsoft.Maui.Graphics; using SkiaSharp; using SkiaSharp.Views.Tizen; -using Microsoft.Maui.Graphics; +using EColor = ElmSharp.Color; namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen { @@ -83,7 +84,7 @@ public static SKShader CreateShader(this GradientBrush gradientBrush, SKRect bou public static SKColor ToSolidColor(this SolidColorBrush solidColorBrush) { - return solidColorBrush.Color.IsDefault() ? SKColor.Empty : solidColorBrush.Color.ToNative().ToSKColor(); + return solidColorBrush.Color.IsDefault() ? SKColor.Empty : solidColorBrush.Color.ToNativeEFL().ToSKColor(); } static SKShader CreateLinearGradient(LinearGradientBrush linearGradientBrush, SKRect pathBounds) @@ -91,7 +92,7 @@ static SKShader CreateLinearGradient(LinearGradientBrush linearGradientBrush, SK var startPoint = new SKPoint(pathBounds.Left + (float)linearGradientBrush.StartPoint.X * pathBounds.Width, pathBounds.Top + (float)linearGradientBrush.StartPoint.Y * pathBounds.Height); var endPoint = new SKPoint(pathBounds.Left + (float)linearGradientBrush.EndPoint.X * pathBounds.Width, pathBounds.Top + (float)linearGradientBrush.EndPoint.Y * pathBounds.Height); var orderedGradientStops = linearGradientBrush.GradientStops.OrderBy(x => x.Offset).ToList(); - var gradientColors = orderedGradientStops.Select(x => x.Color.ToNative().ToSKColor()).ToArray(); + var gradientColors = orderedGradientStops.Select(x => x.Color.ToNativeEFL().ToSKColor()).ToArray(); var gradientColorPos = orderedGradientStops.Select(x => x.Offset).ToArray(); return SKShader.CreateLinearGradient(startPoint, endPoint, gradientColors, gradientColorPos, SKShaderTileMode.Clamp); } @@ -101,9 +102,14 @@ static SKShader CreateRadialGradient(RadialGradientBrush radialGradientBrush, SK var center = new SKPoint((float)radialGradientBrush.Center.X * pathBounds.Width + pathBounds.Left, (float)radialGradientBrush.Center.Y * pathBounds.Height + pathBounds.Top); var radius = (float)radialGradientBrush.Radius * Math.Max(pathBounds.Height, pathBounds.Width); var orderedGradientStops = radialGradientBrush.GradientStops.OrderBy(x => x.Offset).ToList(); - var gradientColors = orderedGradientStops.Select(x => x.Color.ToNative().ToSKColor()).ToArray(); + var gradientColors = orderedGradientStops.Select(x => x.Color.ToNativeEFL().ToSKColor()).ToArray(); var gradientColorPos = orderedGradientStops.Select(x => x.Offset).ToArray(); return SKShader.CreateRadialGradient(center, radius, gradientColors, gradientColorPos, SKShaderTileMode.Clamp); } + + public static EColor ToNativeEFL(this Color c) + { + return c == null ? EColor.Default : new EColor((int)(255.0 * c.Red), (int)(255.0 * c.Green), (int)(255.0 * c.Blue), (int)(255.0 * c.Alpha)); + } } } diff --git a/src/Compatibility/Core/src/Tizen/Extensions/ColorExtensions.cs b/src/Compatibility/Core/src/Tizen/Extensions/ColorExtensions.cs index 0f86966258f1..eeddc6a3af62 100644 --- a/src/Compatibility/Core/src/Tizen/Extensions/ColorExtensions.cs +++ b/src/Compatibility/Core/src/Tizen/Extensions/ColorExtensions.cs @@ -1,5 +1,6 @@ using Microsoft.Maui.Graphics; -using EColor = ElmSharp.Color; +using TColor = Tizen.UIExtensions.Common.Color; +using NColor = Tizen.NUI.Color; namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen { @@ -10,18 +11,22 @@ public static class ColorExtensions /// /// ElmSharp.Color instance representing a color which corresponds to the provided Microsoft.Maui.Controls.Compatibility.Color /// The Microsoft.Maui.Controls.Compatibility.Color instance which will be converted to a ElmSharp.Color - public static EColor ToNative(this Color c) + public static TColor ToNative(this Color c) { if (c == null) { // Trying to convert the default color, this may result in black color. - return EColor.Default; + return TColor.Default; } else { - return new EColor((int)(255.0 * c.Red), (int)(255.0 * c.Green), (int)(255.0 * c.Blue), (int)(255.0 * c.Alpha)); + return new TColor(c.Red, c.Green, c.Blue, c.Alpha); } } + public static NColor ToNativeNUI(this Color c) + { + return new NColor((float)c.Red, (float)c.Green, (float)c.Blue, (float)c.Alpha); + } public static Color WithAlpha(this Color color, double alpha) { @@ -32,19 +37,5 @@ public static Color WithPremultiplied(this Color color, double alpha) { return new Color((int)(color.Red * alpha), (int)(color.Green * alpha), (int)(color.Blue * alpha), color.Alpha); } - - /// - /// Returns a string representing the provided ElmSharp.Color instance in a hexagonal notation - /// - /// string value containing the encoded color - /// The ElmSharp.Color class instance which will be serialized - internal static string ToHex(this EColor c) - { - if (c.IsDefault) - { - Log.Warn("Trying to convert the default color to hexagonal notation, it does not works as expected."); - } - return string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", c.R, c.G, c.B, c.A); - } } } diff --git a/src/Compatibility/Core/src/Tizen/Extensions/DensityIndependentPixelExtensions.cs b/src/Compatibility/Core/src/Tizen/Extensions/DensityIndependentPixelExtensions.cs index fb5402569265..c67889f81364 100644 --- a/src/Compatibility/Core/src/Tizen/Extensions/DensityIndependentPixelExtensions.cs +++ b/src/Compatibility/Core/src/Tizen/Extensions/DensityIndependentPixelExtensions.cs @@ -1,7 +1,8 @@ using Microsoft.Maui.Graphics; using Rect = Microsoft.Maui.Graphics.Rect; -using ERect = ElmSharp.Rect; -using ESize = ElmSharp.Size; +using TRect = Tizen.UIExtensions.Common.Rect; +using TSize = Tizen.UIExtensions.Common.Size; +using NSize = Tizen.NUI.Size2D; namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen { @@ -10,24 +11,29 @@ namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen /// public static class DensityIndependentPixelExtensions { - public static Rect ToDP(this ERect rect) + public static Rect ToDP(this TRect rect) { return new Rect(Forms.ConvertToScaledDP(rect.X), Forms.ConvertToScaledDP(rect.Y), Forms.ConvertToScaledDP(rect.Width), Forms.ConvertToScaledDP(rect.Height)); } - public static ERect ToPixel(this Rect rect) + public static TRect ToPixel(this Rect rect) { - return new ERect(Forms.ConvertToScaledPixel(rect.X), Forms.ConvertToScaledPixel(rect.Y), Forms.ConvertToScaledPixel(rect.Width), Forms.ConvertToScaledPixel(rect.Height)); + return new TRect(Forms.ConvertToScaledPixel(rect.X), Forms.ConvertToScaledPixel(rect.Y), Forms.ConvertToScaledPixel(rect.Width), Forms.ConvertToScaledPixel(rect.Height)); } - public static Size ToDP(this ESize size) + public static Size ToDP(this TSize size) { return new Size(Forms.ConvertToScaledDP(size.Width), Forms.ConvertToScaledDP(size.Height)); } - public static ESize ToPixel(this Size size) + public static Size ToDP(this NSize size) { - return new ESize(Forms.ConvertToScaledPixel(size.Width), Forms.ConvertToScaledPixel(size.Height)); + return new Size(Forms.ConvertToScaledDP(size.Width), Forms.ConvertToScaledDP(size.Height)); + } + + public static TSize ToPixel(this Size size) + { + return new TSize(Forms.ConvertToScaledPixel(size.Width), Forms.ConvertToScaledPixel(size.Height)); } } } diff --git a/src/Compatibility/Core/src/Tizen/Extensions/DragDropExtensions.cs b/src/Compatibility/Core/src/Tizen/Extensions/DragDropExtensions.cs deleted file mode 100644 index 77a9ccf0603d..000000000000 --- a/src/Compatibility/Core/src/Tizen/Extensions/DragDropExtensions.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - public static class DragDropExtensions - { - public static void AddDropTarget(EvasObject obj, DragDropContentType contentType, - Interop.DragStateCallback enterCallback, - Interop.DragStateCallback leaveCallback, - Interop.DragPositionCallback positionCallback, - Interop.DropCallback dropCallback) - { - Interop.elm_drop_target_add(obj.RealHandle, contentType, - enterCallback, IntPtr.Zero, - leaveCallback, IntPtr.Zero, - positionCallback, IntPtr.Zero, - dropCallback, IntPtr.Zero); - } - - public static void StartDrag(EvasObject obj, DragDropContentType contentType, - string data, DragDropActionType actionType, - Interop.DragIconCreateCallback iconCallback, - Interop.DragPositionCallback positionCallback, - Interop.DragAcceptCallback acceptCallback, - Interop.DragStateCallback statCallback) - { - var strData = Marshal.StringToHGlobalAnsi(data); - Interop.elm_drag_start(obj.RealHandle, contentType, strData, actionType, - iconCallback, IntPtr.Zero, - positionCallback, IntPtr.Zero, - acceptCallback, IntPtr.Zero, - statCallback, IntPtr.Zero); - } - - public enum DragDropContentType - { - Targets = -1, - None = 0, - Text = 1, - MarkUp = 2, - Image = 4, - VCard = 8, - Html = 16 - } - - public enum DragDropActionType - { - Unknown = 0, - Copy, - Move, - Private, - Ask, - List, - Link, - Description - } - - public class Interop - { - public const string LibElementary = "libelementary.so.1"; - public const string LibEvas = "libevas.so.1"; - - - public delegate IntPtr DragIconCreateCallback(IntPtr data, IntPtr window, ref int xoff, ref int yoff); - public delegate void DragPositionCallback(IntPtr data, IntPtr obj, int x, int y, int actionType); - public delegate void DragAcceptCallback(IntPtr data, IntPtr obj, bool accept); - public delegate void DragStateCallback(IntPtr data, IntPtr obj); - public delegate bool DropCallback(IntPtr data, IntPtr obj, IntPtr selectionData); - - [DllImport(LibElementary)] - internal static extern void elm_drop_target_add(IntPtr obj, - DragDropContentType type, - DragStateCallback enterCallback, - IntPtr enterData, - DragStateCallback leaveCallback, - IntPtr leaveData, - DragPositionCallback positionCallback, - IntPtr positionData, - DropCallback dropcallback, - IntPtr dropData); - - [DllImport(LibElementary)] - internal static extern void elm_drag_start(IntPtr obj, - DragDropContentType contentType, - IntPtr data, - DragDropActionType actionType, - DragIconCreateCallback iconCreateCallback, - IntPtr iconCreateData, - DragPositionCallback dragPositionCallback, - IntPtr dragPositonData, - DragAcceptCallback dragAcceptCallback, - IntPtr dragAcceptData, - DragStateCallback dragStateCallback, - IntPtr dragStateData); - - [DllImport(LibElementary)] - internal static extern IntPtr elm_object_part_content_get(IntPtr obj, string part); - - [DllImport(LibEvas)] - internal static extern IntPtr evas_object_image_data_get(IntPtr obj, bool forWriting); - - [DllImport(LibEvas)] - internal static extern void evas_object_image_data_set(IntPtr obj, IntPtr data); - - [DllImport(LibEvas)] - internal static extern void evas_object_image_size_get(IntPtr obj, out int w, out int h); - - [DllImport(LibEvas)] - internal static extern void evas_object_image_size_set(IntPtr obj, int w, int h); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Extensions/EntryExtensions.cs b/src/Compatibility/Core/src/Tizen/Extensions/EntryExtensions.cs deleted file mode 100644 index 49a2fcd8aa7a..000000000000 --- a/src/Compatibility/Core/src/Tizen/Extensions/EntryExtensions.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using ElmSharp; -using EEntry = ElmSharp.Entry; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - internal static class EntryExtensions - { - internal static InputPanelReturnKeyType ToInputPanelReturnKeyType(this ReturnType returnType) - { - switch (returnType) - { - case ReturnType.Go: - return InputPanelReturnKeyType.Go; - case ReturnType.Next: - return InputPanelReturnKeyType.Next; - case ReturnType.Send: - return InputPanelReturnKeyType.Send; - case ReturnType.Search: - return InputPanelReturnKeyType.Search; - case ReturnType.Done: - return InputPanelReturnKeyType.Done; - case ReturnType.Default: - return InputPanelReturnKeyType.Default; - default: - throw new System.NotImplementedException($"ReturnType {returnType} not supported"); - } - } - public static void GetSelectRegion(this EEntry entry, out int start, out int end) - { - elm_entry_select_region_get(entry.RealHandle, out start, out end); - } - - [DllImport("libelementary.so.1")] - static extern void elm_entry_select_region_get(IntPtr obj, out int start, out int end); - } -} diff --git a/src/Compatibility/Core/src/Tizen/Extensions/EvasMapExtensions.cs b/src/Compatibility/Core/src/Tizen/Extensions/EvasMapExtensions.cs deleted file mode 100644 index b6bf133a42a3..000000000000 --- a/src/Compatibility/Core/src/Tizen/Extensions/EvasMapExtensions.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - public static class EvasMapExtensions - { - public static void Perspective3D(this EvasMap map, int px, int py, int z0, int foc) - { - var mapType = typeof(EvasMap); - var propInfo = mapType.GetProperty("Handle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); - var handle = (IntPtr)propInfo.GetValue(map); - evas_map_util_3d_perspective(handle, px, py, z0, foc); - } - - [DllImport("libevas.so.1")] - static extern void evas_map_util_3d_perspective(IntPtr map, int px, int py, int z0, int foc); - } -} diff --git a/src/Compatibility/Core/src/Tizen/Extensions/ImageExtensions.cs b/src/Compatibility/Core/src/Tizen/Extensions/ImageExtensions.cs index 72602c3966d2..6d55fcb0285a 100644 --- a/src/Compatibility/Core/src/Tizen/Extensions/ImageExtensions.cs +++ b/src/Compatibility/Core/src/Tizen/Extensions/ImageExtensions.cs @@ -1,35 +1,11 @@ using System.Threading.Tasks; -using EImage = ElmSharp.Image; +using NImage = Tizen.NUI.BaseComponents.ImageView; namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen { public static class ImageExtensions { - public static void ApplyAspect(this EImage image, Aspect aspect) - { - Aspect _aspect = aspect; - - switch (_aspect) - { - case Aspect.AspectFit: - image.IsFixedAspect = true; - image.CanFillOutside = false; - break; - case Aspect.AspectFill: - image.IsFixedAspect = true; - image.CanFillOutside = true; - break; - case Aspect.Fill: - image.IsFixedAspect = false; - image.CanFillOutside = false; - break; - default: - Log.Warn("Invalid Aspect value: {0}", _aspect); - break; - } - } - - public static async Task LoadFromImageSourceAsync(this EImage image, ImageSource source) + public static async Task LoadFromImageSourceAsync(this NImage image, ImageSource source) { IImageSourceHandler handler; bool isLoadComplate = false; @@ -37,24 +13,9 @@ public static async Task LoadFromImageSourceAsync(this EImage image, Image { isLoadComplate = await handler.LoadImageAsync(image, source); } - if (!isLoadComplate) - { - //If it fails, call the Load function to remove the previous image. - image.Load(string.Empty); - } - return isLoadComplate; } - public static bool LoadFromFile(this EImage image, string file) - { - if (!string.IsNullOrEmpty(file)) - { - return image.Load(ResourcePath.GetPath(file)); - } - return false; - } - public static bool IsNullOrEmpty(this ImageSource imageSource) => imageSource == null || imageSource.IsEmpty; } diff --git a/src/Compatibility/Core/src/Tizen/Extensions/KeyboardExtensions.cs b/src/Compatibility/Core/src/Tizen/Extensions/KeyboardExtensions.cs deleted file mode 100644 index d07cbba0edba..000000000000 --- a/src/Compatibility/Core/src/Tizen/Extensions/KeyboardExtensions.cs +++ /dev/null @@ -1,80 +0,0 @@ -using ElmSharp; -using EEntry = ElmSharp.Entry; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - public static class KeyboardExtensions - { - /// - /// Creates an instance of ElmSharp.Keyboard reflecting the provided Microsoft.Maui.Controls.Compatibility.Keyboard instance - /// - /// Keyboard type corresponding to the provided Microsoft.Maui.Controls.Compatibility.Keyboard - /// The Microsoft.Maui.Controls.Compatibility.Keyboard class instance to be converted to ElmSharp.Keyboard. - public static Native.Keyboard ToNative(this Keyboard keyboard) - { - if (keyboard == Keyboard.Numeric) - { - return Native.Keyboard.Numeric; - } - else if (keyboard == Keyboard.Telephone) - { - return Native.Keyboard.PhoneNumber; - } - else if (keyboard == Keyboard.Email) - { - return Native.Keyboard.Email; - } - else if (keyboard == Keyboard.Url) - { - return Native.Keyboard.Url; - } - else - { - return Native.Keyboard.Normal; - } - } - - public static AutoCapital ToAutoCapital(this KeyboardFlags keyboardFlags) - { - if (keyboardFlags.HasFlag(KeyboardFlags.CapitalizeSentence)) - { - return AutoCapital.Sentence; - } - else if (keyboardFlags.HasFlag(KeyboardFlags.CapitalizeWord)) - { - return AutoCapital.Word; - } - else if (keyboardFlags.HasFlag(KeyboardFlags.CapitalizeCharacter)) - { - return AutoCapital.All; - } - else - { - return AutoCapital.None; - } - } - - public static InputHints ToInputHints(this Keyboard keyboard, bool isSpellCheckEnabled, bool isTextPredictionEnabled) - { - if (keyboard is CustomKeyboard customKeyboard) - { - return customKeyboard.Flags.HasFlag(KeyboardFlags.Suggestions) || customKeyboard.Flags.HasFlag(KeyboardFlags.Spellcheck) ? InputHints.AutoComplete : InputHints.None; - } - return isSpellCheckEnabled && isTextPredictionEnabled ? InputHints.AutoComplete : InputHints.None; - } - - public static void UpdateKeyboard(this Native.IEntry control, Keyboard keyboard, bool isSpellCheckEnabled, bool isTextPredictionEnabled) - { - control.Keyboard = keyboard.ToNative(); - if (keyboard is CustomKeyboard customKeyboard) - { - (control as EEntry).AutoCapital = customKeyboard.Flags.ToAutoCapital(); - } - else - { - (control as EEntry).AutoCapital = AutoCapital.None; - } - (control as EEntry).InputHint = keyboard.ToInputHints(isSpellCheckEnabled, isTextPredictionEnabled); - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Extensions/LayoutExtensions.cs b/src/Compatibility/Core/src/Tizen/Extensions/LayoutExtensions.cs index cf26d2f53f6e..ff745dccd056 100644 --- a/src/Compatibility/Core/src/Tizen/Extensions/LayoutExtensions.cs +++ b/src/Compatibility/Core/src/Tizen/Extensions/LayoutExtensions.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using ElmSharp; +using NView = Tizen.NUI.BaseComponents.View; namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen { @@ -19,7 +19,7 @@ public static class LayoutExtensions /// The extended class. /// Object to be added. /// Optional delegate which provides measurements for the added object. - public static void Add(this IList children, EvasObject obj, MeasureDelegate measureDelegate = null) + public static void Add(this IList children, NView obj, MeasureDelegate measureDelegate = null) { children.Add(obj.ToView(measureDelegate)); } @@ -30,7 +30,7 @@ public static void Add(this IList children, EvasObject obj, MeasureDelegat /// The Xamarin view which wraps the evas object. /// The extended class. /// Optional delegate which provides measurements for the evas object. - public static View ToView(this EvasObject obj, MeasureDelegate measureDelegate = null) + public static View ToView(this NView obj, MeasureDelegate measureDelegate = null) { return new NativeViewWrapper(obj, measureDelegate); } diff --git a/src/Compatibility/Core/src/Tizen/Extensions/NativeBindingExtensions.cs b/src/Compatibility/Core/src/Tizen/Extensions/NativeBindingExtensions.cs index a833dd5bf914..5cbb35f62b12 100644 --- a/src/Compatibility/Core/src/Tizen/Extensions/NativeBindingExtensions.cs +++ b/src/Compatibility/Core/src/Tizen/Extensions/NativeBindingExtensions.cs @@ -1,33 +1,33 @@ using System; using System.Collections.Generic; using Microsoft.Maui.Controls.Internals; -using EObject = ElmSharp.EvasObject; +using NView = Tizen.NUI.BaseComponents.View; namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen { public static class NativeBindingExtensions { - public static void SetBinding(this EObject view, string propertyName, BindingBase binding, string updateSourceEventName = null) + public static void SetBinding(this NView view, string propertyName, BindingBase binding, string updateSourceEventName = null) { PlatformBindingHelpers.SetBinding(view, propertyName, binding, updateSourceEventName); } - public static void SetBinding(this EObject view, BindableProperty targetProperty, BindingBase binding) + public static void SetBinding(this NView view, BindableProperty targetProperty, BindingBase binding) { PlatformBindingHelpers.SetBinding(view, targetProperty, binding); } - public static void SetValue(this EObject target, BindableProperty targetProperty, object value) + public static void SetValue(this NView target, BindableProperty targetProperty, object value) { PlatformBindingHelpers.SetValue(target, targetProperty, value); } - public static void SetBindingContext(this EObject target, object bindingContext, Func> getChildren = null) + public static void SetBindingContext(this NView target, object bindingContext, Func> getChildren = null) { PlatformBindingHelpers.SetBindingContext(target, bindingContext, getChildren); } - internal static void TransferBindablePropertiesToWrapper(this EObject target, View wrapper) + internal static void TransferBindablePropertiesToWrapper(this NView target, View wrapper) { PlatformBindingHelpers.TransferBindablePropertiesToWrapper(target, wrapper); } diff --git a/src/Compatibility/Core/src/Tizen/Extensions/PageExtensions.cs b/src/Compatibility/Core/src/Tizen/Extensions/PageExtensions.cs deleted file mode 100644 index 490ffb4b2c46..000000000000 --- a/src/Compatibility/Core/src/Tizen/Extensions/PageExtensions.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility -{ - [Obsolete] - public static class PageExtensions - { - public static EvasObject CreateEvasObject(this Page page, EvasObject parent, bool hasAlpha = false) - { - if (!Forms.IsInitialized) - throw new InvalidOperationException("call Forms.Init() before this"); - - if (parent == null) - throw new InvalidOperationException("Window could not be null"); - - if (!(page.RealParent is Application)) - { - Application app = new DefaultApplication(); - app.MainPage = page; - } - - var platform = Platform.Tizen.Platform.CreatePlatform(parent); - platform.HasAlpha = hasAlpha; - platform.SetPage(page); - return platform.GetRootNativeView(); - } - - class DefaultApplication : Application - { - } - } -} - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [Obsolete] - public static class PageExtensions - { - public static EvasObject CreateEvasObject(this ContentPage page, EvasObject parent, bool hasAlpha = false) - { - return Microsoft.Maui.Controls.Compatibility.PageExtensions.CreateEvasObject(page, parent, hasAlpha); - } - - public static void UpdateFocusTreePolicy<[DynamicallyAccessedMembers(BindableProperty.DeclaringTypeMembers)] T>(this MultiPage multiPage) where T : Page - { - foreach (var pageItem in multiPage.Children) - { - if (Platform.GetRenderer(pageItem)?.NativeView is ElmSharp.Widget nativeWidget) - { - if (pageItem == multiPage.CurrentPage) - { - nativeWidget.AllowTreeFocus = true; - continue; - } - nativeWidget.AllowTreeFocus = false; - } - } - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Extensions/ScrollToPositionExtensions.cs b/src/Compatibility/Core/src/Tizen/Extensions/ScrollToPositionExtensions.cs deleted file mode 100644 index 31a1fde1a9af..000000000000 --- a/src/Compatibility/Core/src/Tizen/Extensions/ScrollToPositionExtensions.cs +++ /dev/null @@ -1,28 +0,0 @@ -using EScrollToPosition = ElmSharp.ScrollToPosition; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - public static class ScrollToPositionExtensions - { - public static EScrollToPosition ToNative(this ScrollToPosition position) - { - switch (position) - { - case ScrollToPosition.Center: - return EScrollToPosition.Middle; - - case ScrollToPosition.End: - return EScrollToPosition.Bottom; - - case ScrollToPosition.MakeVisible: - return EScrollToPosition.In; - - case ScrollToPosition.Start: - return EScrollToPosition.Top; - - default: - return EScrollToPosition.Top; - } - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Extensions/TextAlignmentExtensions.cs b/src/Compatibility/Core/src/Tizen/Extensions/TextAlignmentExtensions.cs deleted file mode 100644 index 7abde6d2c244..000000000000 --- a/src/Compatibility/Core/src/Tizen/Extensions/TextAlignmentExtensions.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Microsoft.Extensions.Logging; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - public static class TextAlignmentExtensions - { - public static Native.TextAlignment ToNative(this TextAlignment alignment) - { - switch (alignment) - { - case TextAlignment.Center: - return Native.TextAlignment.Center; - - case TextAlignment.Start: - return Native.TextAlignment.Start; - - case TextAlignment.End: - return Native.TextAlignment.End; - - default: - Application.Current?.FindMauiContext()?.CreateLogger()?.LogWarning("Warning: unrecognized HorizontalTextAlignment value {0}. " + - "Expected: {Start|Center|End}.", alignment); - Application.Current?.FindMauiContext()?.CreateLogger()?.LogDebug("Falling back to platform's default settings."); - return Native.TextAlignment.Auto; - } - } - - public static double ToNativeDouble(this TextAlignment alignment) - { - switch (alignment) - { - case TextAlignment.Center: - return 0.5d; - - case TextAlignment.Start: - return 0; - - case TextAlignment.End: - return 1d; - - default: - Log.Warn("Warning: unrecognized HorizontalTextAlignment value {0}. " + - "Expected: {Start|Center|End}.", alignment); - Log.Debug("Falling back to platform's default settings."); - return 0.5d; - } - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Forms.cs b/src/Compatibility/Core/src/Tizen/Forms.cs index a1bde68e84e0..12b1b1d700d4 100644 --- a/src/Compatibility/Core/src/Tizen/Forms.cs +++ b/src/Compatibility/Core/src/Tizen/Forms.cs @@ -1,20 +1,16 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Linq.Expressions; using System.Reflection; -using ElmSharp; -using ElmSharp.Wearable; -using Tizen.Applications; -using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Controls.Compatibility.Platform.Tizen; -using Microsoft.Maui.Controls.Shapes; +using Microsoft.Maui.Controls.Internals; +using Tizen.Applications; using Microsoft.Maui.Devices; -using ELayout = ElmSharp.Layout; -using TSystemInfo = Tizen.System.Information; -using Size = Microsoft.Maui.Graphics.Size; using Color = Microsoft.Maui.Graphics.Color; +using NView = Tizen.NUI.BaseComponents.View; +using TDeviceInfo = Tizen.UIExtensions.Common.DeviceInfo; +using Size = Microsoft.Maui.Graphics.Size; namespace Microsoft.Maui.Controls.Compatibility { @@ -36,7 +32,6 @@ public class InitializationOptions { public CoreApplication Context { get; set; } public bool UseDeviceIndependentPixel { get; set; } - public bool UseSkiaSharp { get; set; } = true; public HandlerAttribute[] Handlers { get; set; } public Dictionary> CustomHandlers { get; set; } // for static registers public Assembly[] Assemblies { get; set; } @@ -45,7 +40,9 @@ public class InitializationOptions public StaticRegistrarStrategy StaticRegistarStrategy { get; set; } public PlatformType PlatformType { get; set; } public bool UseMessagingCenter { get; set; } = true; - public bool UseFastLayout { get; set; } = false; + + public bool UseSkiaSharp { get; set; } + public DisplayResolutionUnit DisplayResolutionUnit { get; set; } @@ -54,25 +51,19 @@ public struct EffectScope public string Name; public ExportEffectAttribute[] Effects; } - public InitializationOptions() - { - } - public InitializationOptions(CoreApplication application) + public InitializationOptions() { - Context = application; } - public InitializationOptions(CoreApplication application, bool useDeviceIndependentPixel, HandlerAttribute[] handlers) + public InitializationOptions(bool useDeviceIndependentPixel, HandlerAttribute[] handlers) { - Context = application; UseDeviceIndependentPixel = useDeviceIndependentPixel; Handlers = handlers; } - public InitializationOptions(CoreApplication application, bool useDeviceIndependentPixel, params Assembly[] assemblies) + public InitializationOptions(bool useDeviceIndependentPixel, params Assembly[] assemblies) { - Context = application; UseDeviceIndependentPixel = useDeviceIndependentPixel; Assemblies = assemblies; } @@ -92,156 +83,27 @@ public static class Forms #pragma warning disable CS0612 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete { - static Lazy s_profile = new Lazy(() => - { - //TODO : Fix me if elm_config_profile_get() unavailable - return Elementary.GetProfile(); - }); - - static Lazy s_dpi = new Lazy(() => - { - int dpi = 0; - if (s_profile.Value == "tv") - { - // Use fixed DPI value (72) if TV profile - return 72; - } - TSystemInfo.TryGetValue("http://tizen.org/feature/screen.dpi", out dpi); - return dpi; - }); - - static Lazy s_elmScale = new Lazy(() => - { - return s_deviceScale.Value / Elementary.GetScale(); - }); - - static Lazy s_deviceType = new Lazy(() => - { - if (!TSystemInfo.TryGetValue("http://tizen.org/system/device_type", out string deviceType)) - { - // Since, above key("http://tizen.org/system/device_type") is not available on Tizen 4.0, we uses profile to decide the type of device on 4.0. - var profile = GetProfile(); - if (profile == "mobile") - { - deviceType = "Mobile"; - } - else if (profile == "tv") - { - deviceType = "TV"; - } - else if (profile == "wearable") - { - deviceType = "Wearable"; - } - else - { - deviceType = "Unknown"; - } - } - return deviceType; - }); - - static Lazy s_deviceScale = new Lazy(() => - { - // This is the base scale value and varies from profile - return ThemeManager.GetBaseScale(s_deviceType.Value); - }); - - static Lazy s_scalingFactor = new Lazy(() => - { - int width = 0; - int height = 0; - - TSystemInfo.TryGetValue("http://tizen.org/feature/screen.width", out width); - TSystemInfo.TryGetValue("http://tizen.org/feature/screen.height", out height); - - var scalingFactor = 1.0; // scaling is disabled, we're using pixels as Xamarin's geometry units - if (DisplayResolutionUnit.UseVP && DisplayResolutionUnit.ViewportWidth > 0) - { - scalingFactor = width / DisplayResolutionUnit.ViewportWidth; - } - else - { - if (DisplayResolutionUnit.UseDP) - { - scalingFactor = s_dpi.Value / 160.0; - } - - if (DisplayResolutionUnit.UseDeviceScale) - { - var portraitSize = Math.Min(PhysicalScreenSize.Width, PhysicalScreenSize.Height); - if (portraitSize > 2000) - { - scalingFactor *= 4; - } - else if (portraitSize > 1000) - { - scalingFactor *= 2.5; - } - } - } - return scalingFactor; - }); - - static StaticRegistrarStrategy s_staticRegistrarStrategy = StaticRegistrarStrategy.None; - - static PlatformType s_platformType = PlatformType.Defalut; - - static bool s_useMessagingCenter = true; + static IReadOnlyList s_flags; public static event EventHandler ViewInitialized; - public static IMauiContext MauiContext - { - get; - internal set; - } + public static bool IsInitialized { get; private set; } - public static CoreApplication Context - { - get; - internal set; - } + public static StaticRegistrarStrategy StaticRegistrarStrategy { get; private set; } - public static EvasObject NativeParent - { - get; internal set; - } + public static PlatformType PlatformType { get; private set; } - public static ELayout BaseLayout => NativeParent as ELayout; + public static bool UseMessagingCenter { get; private set; } - public static CircleSurface CircleSurface - { - get; internal set; - } + public static DisplayResolutionUnit DisplayResolutionUnit { get; private set; } - [EditorBrowsable(EditorBrowsableState.Never)] - public static Element RotaryFocusObject - { - get; internal set; - } - - public static bool IsInitialized - { - get; - private set; - } - - public static StaticRegistrarStrategy StaticRegistrarStrategy => s_staticRegistrarStrategy; - - public static PlatformType PlatformType => s_platformType; - - public static bool UseMessagingCenter => s_useMessagingCenter; - - public static bool UseSkiaSharp { get; private set; } + public static int ScreenDPI => TDeviceInfo.DPI; - public static bool UseFastLayout { get; private set; } - - public static DisplayResolutionUnit DisplayResolutionUnit { get; private set; } = DisplayResolutionUnit.Pixel(); + public static Size PhysicalScreenSize => DeviceDisplay.MainDisplayInfo.GetScaledScreenSize(); - public static int ScreenDPI => s_dpi.Value; + public static IReadOnlyList Flags => s_flags ?? (s_flags = new string[0]); - public static Size PhysicalScreenSize => DeviceDisplay.MainDisplayInfo.GetScaledScreenSize(); + public static IMauiContext MauiContext { get; internal set;} internal static TizenTitleBarVisibility TitleBarVisibility { @@ -249,7 +111,7 @@ internal static TizenTitleBarVisibility TitleBarVisibility private set; } - internal static void SendViewInitialized(this VisualElement self, EvasObject nativeView) + internal static void SendViewInitialized(this VisualElement self, NView nativeView) { EventHandler viewInitialized = Forms.ViewInitialized; if (viewInitialized != null) @@ -271,7 +133,7 @@ public static void SetTitleBarVisibility(TizenTitleBarVisibility visibility) public static TOut GetHandler(Type type, params object[] args) where TOut : class, IRegisterable { - if (s_staticRegistrarStrategy == StaticRegistrarStrategy.None) + if (StaticRegistrarStrategy == StaticRegistrarStrategy.None) { // Find hander in internal registrar, that is using reflection (default). return Registrar.Registered.GetHandler(type, args); @@ -282,7 +144,7 @@ public static void SetTitleBarVisibility(TizenTitleBarVisibility visibility) TOut ret = StaticRegistrar.Registered.GetHandler(type, args); // 2. If there is no handler, try to find hander in internal registrar, that is using reflection. - if (ret == null && s_staticRegistrarStrategy == StaticRegistrarStrategy.All) + if (ret == null && StaticRegistrarStrategy == StaticRegistrarStrategy.All) { ret = Registrar.Registered.GetHandler(type, args); } @@ -292,7 +154,7 @@ public static void SetTitleBarVisibility(TizenTitleBarVisibility visibility) public static TOut GetHandlerForObject(object obj) where TOut : class, IRegisterable { - if (s_staticRegistrarStrategy == StaticRegistrarStrategy.None) + if (StaticRegistrarStrategy == StaticRegistrarStrategy.None) { // Find hander in internal registrar, that is using reflection (default). return Registrar.Registered.GetHandlerForObject(obj); @@ -303,7 +165,7 @@ public static void SetTitleBarVisibility(TizenTitleBarVisibility visibility) TOut ret = StaticRegistrar.Registered.GetHandlerForObject(obj); // 2. If there is no handler, try to find hander in internal registrar, that is using reflection. - if (ret == null && s_staticRegistrarStrategy == StaticRegistrarStrategy.All) + if (ret == null && StaticRegistrarStrategy == StaticRegistrarStrategy.All) { ret = Registrar.Registered.GetHandlerForObject(obj); } @@ -313,7 +175,7 @@ public static void SetTitleBarVisibility(TizenTitleBarVisibility visibility) public static TOut GetHandlerForObject(object obj, params object[] args) where TOut : class, IRegisterable { - if (s_staticRegistrarStrategy == StaticRegistrarStrategy.None) + if (StaticRegistrarStrategy == StaticRegistrarStrategy.None) { // Find hander in internal registrar, that is using reflection (default). return Registrar.Registered.GetHandlerForObject(obj, args); @@ -324,7 +186,7 @@ public static void SetTitleBarVisibility(TizenTitleBarVisibility visibility) TOut ret = StaticRegistrar.Registered.GetHandlerForObject(obj, args); // 2. If there is no handler, try to find hander in internal registrar, that is using reflection. - if (ret == null && s_staticRegistrarStrategy == StaticRegistrarStrategy.All) + if (ret == null && StaticRegistrarStrategy == StaticRegistrarStrategy.All) { ret = StaticRegistrar.Registered.GetHandlerForObject(obj, args); } @@ -352,8 +214,6 @@ public static void Init(IMauiContext context, InitializationOptions options = nu static void SetupInit(IMauiContext context, InitializationOptions options = null) { MauiContext = context; - Context = options?.Context ?? MauiApplication.Current; - NativeParent = context.GetPlatformParent(); Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim); if (!IsInitialized) @@ -363,9 +223,7 @@ static void SetupInit(IMauiContext context, InitializationOptions options = null TizenSynchronizationContext.Initialize(); } - Elementary.Initialize(); - Elementary.ThemeOverlay(); - Utility.AppendGlobalFontPath(@"/usr/share/fonts"); + Tizen.NUI.FontClient.Instance.AddCustomFontDirectory(@"/usr/share/fonts"); } Device.DefaultRendererAssembly = typeof(Forms).Assembly; @@ -375,18 +233,13 @@ static void SetupInit(IMauiContext context, InitializationOptions options = null if (options != null) { - s_platformType = options.PlatformType; - s_useMessagingCenter = options.UseMessagingCenter; - UseSkiaSharp = options.UseSkiaSharp; - UseFastLayout = options.UseFastLayout; + PlatformType = options.PlatformType; + UseMessagingCenter = options.UseMessagingCenter; } Application.AccentColor = GetAccentColor(); ExpressionSearch.Default = new TizenExpressionSearch(); - if (Context is WatchApplication) - s_platformType = PlatformType.Lightweight; - IsInitialized = true; } @@ -438,21 +291,6 @@ internal static void RegisterCompatRenderers(InitializationOptions maybeOptions } } - static void RegisterSkiaSharpRenderers() - { - // Register all skiasharp-based rednerers here. - Registrar.Registered.Register(typeof(Frame), typeof(Platform.Tizen.SkiaSharp.FrameRenderer)); - Registrar.Registered.Register(typeof(BoxView), typeof(Platform.Tizen.SkiaSharp.BoxViewRenderer)); - Registrar.Registered.Register(typeof(Image), typeof(Platform.Tizen.SkiaSharp.ImageRenderer)); - - Registrar.Registered.Register(typeof(Ellipse), typeof(Platform.Tizen.SkiaSharp.EllipseRenderer)); - Registrar.Registered.Register(typeof(Line), typeof(Platform.Tizen.SkiaSharp.LineRenderer)); - Registrar.Registered.Register(typeof(Path), typeof(Platform.Tizen.SkiaSharp.PathRenderer)); - Registrar.Registered.Register(typeof(Shapes.Polygon), typeof(Platform.Tizen.SkiaSharp.PolygonRenderer)); - Registrar.Registered.Register(typeof(Polyline), typeof(Platform.Tizen.SkiaSharp.PolylineRenderer)); - Registrar.Registered.Register(typeof(Shapes.Rectangle), typeof(Platform.Tizen.SkiaSharp.RectangleRenderer)); - } - static Color GetAccentColor() { // On Windows Phone, this is the complementary color chosen by the user. @@ -482,7 +320,7 @@ static Color GetAccentColor() /// public static int ConvertToPixel(double dp) { - return (int)Math.Round(dp * s_dpi.Value / 160.0); + return (int)Math.Round(dp * TDeviceInfo.DPI / 160.0); } /// @@ -496,7 +334,7 @@ public static int ConvertToPixel(double dp) /// public static int ConvertToScaledPixel(double dp) { - return (int)Math.Round(dp * s_scalingFactor.Value); + return (int)Math.Round(dp * TDeviceInfo.ScalingFactor); } /// @@ -511,7 +349,7 @@ public static double ConvertToScaledDP(int pixel) { if (pixel == int.MaxValue) return double.PositiveInfinity; - return pixel / s_scalingFactor.Value; + return pixel / TDeviceInfo.ScalingFactor; } /// @@ -526,7 +364,7 @@ public static double ConvertToScaledDP(double pixel) { if (pixel == double.PositiveInfinity) return double.PositiveInfinity; - return pixel / s_scalingFactor.Value; + return pixel / TDeviceInfo.ScalingFactor; } /// @@ -536,7 +374,9 @@ public static double ConvertToScaledDP(double pixel) /// public static int ConvertToEflFontPoint(double sp) { - return (int)Math.Round(ConvertToScaledPixel(sp) * s_elmScale.Value); + if (sp == -1) + return -1; + return (int)sp.ToScaledPoint(); } /// @@ -546,7 +386,7 @@ public static int ConvertToEflFontPoint(double sp) /// public static double ConvertToDPFont(int eflPt) { - return ConvertToScaledDP(eflPt / s_elmScale.Value); + return eflPt.ToScaledDP(); } /// @@ -555,23 +395,12 @@ public static double ConvertToDPFont(int eflPt) /// public static string GetProfile() { - return s_profile.Value; + return TDeviceInfo.Profile; } public static string GetDeviceType() { - return s_deviceType.Value; - } - - // for internal use only - [EditorBrowsable(EditorBrowsableState.Never)] - public static void Preload() - { - Elementary.Initialize(); - Elementary.ThemeOverlay(); - var window = new Microsoft.Maui.Controls.Compatibility.Platform.Tizen.PreloadedWindow(); - TSystemInfo.TryGetValue("http://tizen.org/feature/screen.width", out int width); - TSystemInfo.TryGetValue("http://tizen.org/feature/screen.height", out int height); + return TDeviceInfo.DeviceType.ToString(); } } diff --git a/src/Compatibility/Core/src/Tizen/FormsApplication.cs b/src/Compatibility/Core/src/Tizen/FormsApplication.cs index 330de47c62cb..cfb45d68868b 100644 --- a/src/Compatibility/Core/src/Tizen/FormsApplication.cs +++ b/src/Compatibility/Core/src/Tizen/FormsApplication.cs @@ -1,30 +1,19 @@ using System; using System.ComponentModel; -using System.Diagnostics; -using System.Reflection; using System.Threading.Tasks; -using ElmSharp; -using ElmSharp.Wearable; -using Tizen.Applications; using Tizen.Common; -using Microsoft.Maui.Controls.Internals; -using Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native; -using Microsoft.Maui.Devices; -using EWindow = ElmSharp.Window; -using ELayout = ElmSharp.Layout; -using EDisplayRotation = ElmSharp.DisplayRotation; -using Specific = Microsoft.Maui.Controls.PlatformConfiguration.TizenSpecific.Application; +using Tizen.NUI; +using NWindow = Tizen.NUI.Window; namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen { [Obsolete] - public class FormsApplication : CoreUIApplication + public class FormsApplication : NUIApplication { ITizenPlatform _platform; Application _application; - EWindow _window; - bool _useBezelInteration; + NWindow _window; protected FormsApplication() { @@ -34,7 +23,7 @@ protected FormsApplication() /// Gets the main window or null if it's not set. /// /// The main window or null. - public EWindow MainWindow + public NWindow MainWindow { get { @@ -47,18 +36,6 @@ protected set } } - public ELayout BaseLayout - { - get; protected set; - } - - public CircleSurface BaseCircleSurface - { - get; protected set; - } - - public bool UseBezelInteration => _useBezelInteration; - protected override void OnPreCreate() { base.OnPreCreate(); @@ -70,26 +47,7 @@ protected override void OnPreCreate() Environment.SetEnvironmentVariable("XDG_DATA_HOME", Current.DirectoryInfo.Data); } - var type = typeof(EWindow); - // Use reflection to avoid breaking compatibility. ElmSharp.Window.CreateWindow() is has been added since API6. - var methodInfo = type.GetMethod("CreateWindow", BindingFlags.NonPublic | BindingFlags.Static); - EWindow window = null; - if (methodInfo != null) - { - window = (EWindow)methodInfo.Invoke(null, new object[] { "FormsWindow" }); - BaseLayout = (ELayout)window.GetType().GetProperty("BaseLayout")?.GetValue(window); - BaseCircleSurface = (CircleSurface)window.GetType().GetProperty("BaseCircleSurface")?.GetValue(window); - Forms.CircleSurface = BaseCircleSurface; - } - else // in case of Xamarin Preload - { - window = PreloadedWindow.GetInstance() ?? new EWindow("FormsWindow"); - if (window is PreloadedWindow precreated) - { - BaseLayout = precreated.BaseLayout; - } - } - MainWindow = window; + MainWindow = NWindow.Instance; } protected override void OnTerminate() @@ -143,11 +101,6 @@ public async void LoadApplication(Application application) application.SendStart(); application.PropertyChanged += new PropertyChangedEventHandler(this.AppOnPropertyChanged); SetPage(_application.MainPage); - if (DeviceInfo.Idiom == DeviceIdiom.Watch) - { - _useBezelInteration = Specific.GetUseBezelInteraction(_application); - UpdateOverlayContent(); - } } void AppOnPropertyChanged(object sender, PropertyChangedEventArgs args) @@ -156,30 +109,6 @@ void AppOnPropertyChanged(object sender, PropertyChangedEventArgs args) { SetPage(_application.MainPage); } - else if (DeviceInfo.Idiom == DeviceIdiom.Watch) - { - if (Specific.UseBezelInteractionProperty.PropertyName == args.PropertyName) - { - _useBezelInteration = Specific.GetUseBezelInteraction(_application); - } - else if (Specific.OverlayContentProperty.PropertyName == args.PropertyName) - { - UpdateOverlayContent(); - } - } - } - - void UpdateOverlayContent() - { - EvasObject nativeView = null; - var content = Specific.GetOverlayContent(_application); - if (content != null) - { - var renderer = Platform.GetOrCreateRenderer(content); - (renderer as ILayoutRenderer)?.RegisterOnLayoutUpdated(); - nativeView = renderer?.NativeView; - } - Forms.BaseLayout.SetOverlayPart(nativeView); } void SetPage(Page page) @@ -188,59 +117,38 @@ void SetPage(Page page) { throw new InvalidOperationException("Call Forms.Init (UIApplication) before this"); } - - _platform.HasAlpha = MainWindow.Alpha; _platform.SetPage(page); } void InitializeWindow() { - Debug.Assert(MainWindow != null, "EWindow cannot be null"); - - MainWindow.Active(); MainWindow.Show(); - // in case of no use of preloaded window - if (BaseLayout == null) + MainWindow.KeyEvent += (s, e) => { - var conformant = new Conformant(MainWindow); - conformant.Show(); - - var layout = new ApplicationLayout(conformant); - - layout.Show(); - - BaseLayout = layout; - - if (DeviceInfo.Idiom == DeviceIdiom.Watch) + if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape")) { - BaseCircleSurface = new CircleSurface(conformant); - Forms.CircleSurface = BaseCircleSurface; - } - conformant.SetContent(BaseLayout); - } - - MainWindow.AvailableRotations = EDisplayRotation.Degree_0 | EDisplayRotation.Degree_90 | EDisplayRotation.Degree_180 | EDisplayRotation.Degree_270; - MainWindow.Deleted += (s, e) => - { - Exit(); - }; + if (global::Tizen.UIExtensions.NUI.Popup.HasOpenedPopup) + { + global::Tizen.UIExtensions.NUI.Popup.CloseLast(); + return; + } - MainWindow.BackButtonPressed += (sender, e) => - { - if (_platform != null) - { - if (!_platform.SendBackButtonPressed()) + if (!(_platform?.SendBackButtonPressed() ?? false)) { Exit(); } } }; - _platform = Platform.CreatePlatform(BaseLayout); - BaseLayout.SetContent(_platform.GetRootNativeView()); - _platform.RootNativeViewChanged += (s, e) => BaseLayout.SetContent(e.RootNativeView); + MainWindow.AddAvailableOrientation(NWindow.WindowOrientation.Landscape); + MainWindow.AddAvailableOrientation(NWindow.WindowOrientation.LandscapeInverse); + MainWindow.AddAvailableOrientation(NWindow.WindowOrientation.Portrait); + MainWindow.AddAvailableOrientation(NWindow.WindowOrientation.PortraitInverse); + + _platform = new DefaultPlatform(); + MainWindow.GetDefaultLayer().Add(_platform.GetRootNativeView()); } public void Run() diff --git a/src/Compatibility/Core/src/Tizen/Gesture/GestureDetector.cs b/src/Compatibility/Core/src/Tizen/Gesture/GestureDetector.cs new file mode 100644 index 000000000000..cbfee6afff8f --- /dev/null +++ b/src/Compatibility/Core/src/Tizen/Gesture/GestureDetector.cs @@ -0,0 +1,105 @@ +using System.Collections.Generic; + +namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen +{ + public class GestureDetector + { + Dictionary _handlers = new Dictionary(); + + IVisualElementRenderer _renderer; + + bool _isEnabled = true; + + public GestureDetector(IVisualElementRenderer renderer) + { + _renderer = renderer; + } + + public bool IsEnabled + { + get => _isEnabled; + set + { + if (_isEnabled != value) + { + _isEnabled = value; + UpdateIsEnabled(); + } + } + } + + public void AddGestures(IEnumerable gestures) + { + foreach (var gesture in gestures) + { + AddGesture(gesture); + } + } + + public void AddGesture(IGestureRecognizer gesture) + { + var handler = CreateHandler(gesture); + if (handler == null) + return; + + _handlers.Add(gesture, handler); + + if (IsEnabled) + handler.Attach(_renderer); + } + + public void RemoveGestures(IEnumerable gestures) + { + foreach (var gesture in gestures) + { + RemoveGesture(gesture); + } + } + + public void RemoveGesture(IGestureRecognizer gesture) + { + if (_handlers.TryGetValue(gesture, out GestureHandler handler)) + { + _handlers.Remove(gesture); + handler.Dispose(); + } + } + + public void Clear() + { + foreach (var handler in _handlers) + { + handler.Value.Dispose(); + } + _handlers.Clear(); + } + + void UpdateIsEnabled() + { + if (IsEnabled) + { + foreach (var handler in _handlers.Values) + { + handler.Attach(_renderer); + } + } + else + { + foreach (var handler in _handlers.Values) + { + handler.Detach(); + } + } + } + + GestureHandler CreateHandler(IGestureRecognizer recognizer) + { + if (recognizer is TapGestureRecognizer) + return new TapGestureHandler(recognizer); + if (recognizer is PanGestureRecognizer) + return new PanGestureHandler(recognizer); + return Forms.GetHandlerForObject(recognizer, recognizer); + } + + } +} diff --git a/src/Compatibility/Core/src/Tizen/Gesture/GestureHandler.cs b/src/Compatibility/Core/src/Tizen/Gesture/GestureHandler.cs new file mode 100644 index 000000000000..fab70c699269 --- /dev/null +++ b/src/Compatibility/Core/src/Tizen/Gesture/GestureHandler.cs @@ -0,0 +1,54 @@ +using System; +using NGestureDetector = Tizen.NUI.GestureDetector; + +namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen +{ + public abstract class GestureHandler : IRegisterable, IDisposable + { + bool _disposedValue; + + public IGestureRecognizer Recognizer { get; private set; } + + public NGestureDetector NativeDetector { get; } + + protected IVisualElementRenderer Renderer { get; private set; } + protected View View => Renderer.Element as View; + + public void Attach(IVisualElementRenderer renderer) + { + Renderer = renderer; + NativeDetector.Attach(Renderer.NativeView); + } + + public void Detach() + { + NativeDetector.Detach(Renderer.NativeView); + } + + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + + protected abstract NGestureDetector CreateNativeDetector(IGestureRecognizer recognizer); + + protected GestureHandler(IGestureRecognizer recognizer) + { + Recognizer = recognizer; + NativeDetector = CreateNativeDetector(recognizer); + } + + protected virtual void Dispose(bool disposing) + { + if (!_disposedValue) + { + if (disposing) + { + NativeDetector.Dispose(); + } + _disposedValue = true; + } + } + } +} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Gesture/PanGestureHandler.cs b/src/Compatibility/Core/src/Tizen/Gesture/PanGestureHandler.cs new file mode 100644 index 000000000000..ec2a1e435ce1 --- /dev/null +++ b/src/Compatibility/Core/src/Tizen/Gesture/PanGestureHandler.cs @@ -0,0 +1,53 @@ +using NGestureDetector = Tizen.NUI.GestureDetector; +using PanGestureDetector = Tizen.NUI.PanGestureDetector; +using GestureStateType = Tizen.NUI.Gesture.StateType; + +namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen +{ + public class PanGestureHandler : GestureHandler + { + int _gestureId = 0; + + double _totalX; + double _totalY; + + public PanGestureHandler(IGestureRecognizer recognizer) : base(recognizer) + { + NativeDetector.Detected += OnDetected; + } + + new IPanGestureController Recognizer => base.Recognizer as IPanGestureController; + new PanGestureDetector NativeDetector => base.NativeDetector as PanGestureDetector; + + protected override NGestureDetector CreateNativeDetector(IGestureRecognizer recognizer) + { + return new PanGestureDetector(); + } + + void OnDetected(object source, PanGestureDetector.DetectedEventArgs e) + { + if (e.PanGesture.State == GestureStateType.Started) + { + _gestureId++; + _totalX = 0; + _totalY = 0; + Recognizer.SendPanStarted(View, _gestureId); + } + else if (e.PanGesture.State == GestureStateType.Continuing) + { + _totalX += e.PanGesture.Displacement.X; + _totalY += e.PanGesture.Displacement.Y; + Recognizer.SendPan(View, Forms.ConvertToScaledDP(_totalX), Forms.ConvertToScaledDP(_totalY), _gestureId); + } + else if (e.PanGesture.State == GestureStateType.Cancelled) + { + Recognizer.SendPanCanceled(View, _gestureId); + } + else if (e.PanGesture.State == GestureStateType.Finished) + { + Recognizer.SendPanCompleted(View, _gestureId); + } + } + + } +} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Gesture/TapGestureHandler.cs b/src/Compatibility/Core/src/Tizen/Gesture/TapGestureHandler.cs new file mode 100644 index 000000000000..c4da708f91a9 --- /dev/null +++ b/src/Compatibility/Core/src/Tizen/Gesture/TapGestureHandler.cs @@ -0,0 +1,29 @@ +using System; +using NGestureDetector = Tizen.NUI.GestureDetector; +using TapGestureDetector = Tizen.NUI.TapGestureDetector; + +namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen +{ + public class TapGestureHandler : GestureHandler + { + public TapGestureHandler(IGestureRecognizer recognizer) : base(recognizer) + { + NativeDetector.Detected += OnTapped; + } + + new TapGestureRecognizer Recognizer => base.Recognizer as TapGestureRecognizer; + new TapGestureDetector NativeDetector => base.NativeDetector as TapGestureDetector; + + protected override NGestureDetector CreateNativeDetector(IGestureRecognizer recognizer) + { + return new TapGestureDetector((uint)(recognizer as TapGestureRecognizer).NumberOfTapsRequired); + } + + void OnTapped(object source, TapGestureDetector.DetectedEventArgs e) + { + if (e.TapGesture.NumberOfTaps == Recognizer.NumberOfTapsRequired) + Recognizer.SendTapped(View); + } + + } +} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/GestureDetector.cs b/src/Compatibility/Core/src/Tizen/GestureDetector.cs deleted file mode 100644 index a5c7fca2630b..000000000000 --- a/src/Compatibility/Core/src/Tizen/GestureDetector.cs +++ /dev/null @@ -1,602 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Maui.Devices; -using ElmSharp; -using EGestureType = ElmSharp.GestureLayer.GestureType; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [Obsolete] - internal class GestureDetector - { - readonly IDictionary> _handlerCache; - - readonly IVisualElementRenderer _renderer; - GestureLayer _gestureLayer; - double _doubleTapTime = 0; - double _longTapTime = 0; - bool _inputTransparent = false; - bool _isEnabled; - - View View => _renderer.Element as View; - - public bool IsEnabled - { - get - { - return _isEnabled; - } - set - { - _isEnabled = value; - UpdateGestureLayerEnabled(); - } - } - - public bool InputTransparent - { - get - { - return _inputTransparent; - } - set - { - _inputTransparent = value; - UpdateGestureLayerEnabled(); - } - } - - public GestureDetector(IVisualElementRenderer renderer) - { - _handlerCache = new Dictionary>(); - _renderer = renderer; - _isEnabled = View.IsEnabled; - _inputTransparent = View.InputTransparent; - } - - public void Clear() - { - // this will clear all callbacks in ElmSharp GestureLayer - _gestureLayer?.Unrealize(); - _gestureLayer = null; - foreach (var handlers in _handlerCache.Values) - { - foreach (var handler in handlers) - { - handler.PropertyChanged -= OnGestureRecognizerPropertyChanged; - } - } - _handlerCache.Clear(); - - if (DeviceInfo.Idiom == DeviceIdiom.TV) - { - _renderer.NativeView.KeyDown -= OnKeyDown; - } - } - - public void AddGestures(IEnumerable recognizers) - { - if (_gestureLayer == null) - { - CreateGestureLayer(); - } - - foreach (var item in recognizers) - AddGesture(item); - } - - public void RemoveGestures(IEnumerable recognizers) - { - foreach (var item in recognizers) - RemoveGesture(item); - } - - void CreateGestureLayer() - { - _gestureLayer = new GestureLayer(_renderer.NativeView); - _gestureLayer.Attach(_renderer.NativeView); - _gestureLayer.Deleted += (s, e) => - { - _gestureLayer = null; - Clear(); - }; - UpdateGestureLayerEnabled(); - - if (DeviceInfo.Idiom == DeviceIdiom.TV) - { - _renderer.NativeView.KeyDown += OnKeyDown; - } - } - - void UpdateGestureLayerEnabled() - { - if (_gestureLayer != null) - { - _gestureLayer.IsEnabled = !_inputTransparent && _isEnabled; - } - } - - void AddGesture(IGestureRecognizer recognizer) - { - var handler = CreateHandler(recognizer); - if (handler == null) - return; - - var gestureType = handler.Type; - var timeout = handler.Timeout; - var cache = _handlerCache; - - if (!cache.ContainsKey(gestureType)) - { - cache[gestureType] = new List(); - } - - handler.PropertyChanged += OnGestureRecognizerPropertyChanged; - cache[gestureType].Add(handler); - - if (cache[gestureType].Count == 1) - { - switch (gestureType) - { - case EGestureType.Tap: - case EGestureType.TripleTap: - AddTapGesture(gestureType); - break; - - case EGestureType.DoubleTap: - AddDoubleTapGesture(gestureType, timeout); - break; - - case EGestureType.LongTap: - AddLongTapGesture(gestureType, timeout); - break; - - case EGestureType.Line: - AddLineGesture(gestureType); - break; - - case EGestureType.Flick: - AddFlickGesture(gestureType, timeout); - break; - - case EGestureType.Rotate: - AddRotateGesture(gestureType); - break; - - case EGestureType.Momentum: - AddMomentumGesture(gestureType); - break; - - case EGestureType.Zoom: - AddPinchGesture(gestureType); - break; - - default: - break; - } - } - - if (handler is DropGestureHandler dropGestureHandler) - { - dropGestureHandler.AddDropGesture(); - } - } - - void RemoveGesture(IGestureRecognizer recognizer) - { - var cache = _handlerCache; - var handler = LookupHandler(recognizer); - var gestureType = cache.FirstOrDefault(x => x.Value.Contains(handler)).Key; - - handler.PropertyChanged -= OnGestureRecognizerPropertyChanged; - cache[gestureType].Remove(handler); - - if (cache[gestureType].Count == 0) - { - switch (gestureType) - { - case EGestureType.Tap: - case EGestureType.DoubleTap: - case EGestureType.TripleTap: - case EGestureType.LongTap: - RemoveTapGesture(gestureType); - break; - - case EGestureType.Line: - RemoveLineGesture(); - break; - - case EGestureType.Flick: - RemoveFlickGesture(); - break; - - case EGestureType.Rotate: - RemoveRotateGesture(); - break; - - case EGestureType.Momentum: - RemoveMomentumGesture(); - break; - - case EGestureType.Zoom: - RemovePinchGesture(); - break; - - default: - break; - } - } - } - - void AddLineGesture(EGestureType type) - { - _gestureLayer.SetLineCallback(GestureLayer.GestureState.Start, (data) => { OnGestureStarted(type, data); }); - _gestureLayer.SetLineCallback(GestureLayer.GestureState.Move, (data) => { OnGestureMoved(type, data); }); - _gestureLayer.SetLineCallback(GestureLayer.GestureState.End, (data) => { OnGestureCompleted(type, data); }); - _gestureLayer.SetLineCallback(GestureLayer.GestureState.Abort, (data) => { OnGestureCanceled(type, data); }); - } - - void AddPinchGesture(EGestureType type) - { - _gestureLayer.SetZoomCallback(GestureLayer.GestureState.Start, (data) => { OnGestureStarted(type, data); }); - _gestureLayer.SetZoomCallback(GestureLayer.GestureState.Move, (data) => { OnGestureMoved(type, data); }); - _gestureLayer.SetZoomCallback(GestureLayer.GestureState.End, (data) => { OnGestureCompleted(type, data); }); - _gestureLayer.SetZoomCallback(GestureLayer.GestureState.Abort, (data) => { OnGestureCanceled(type, data); }); - } - - void AddTapGesture(EGestureType type) - { - _gestureLayer.SetTapCallback(type, GestureLayer.GestureState.Start, (data) => { OnGestureStarted(type, data); }); - _gestureLayer.SetTapCallback(type, GestureLayer.GestureState.End, (data) => { OnGestureCompleted(type, data); }); - _gestureLayer.SetTapCallback(type, GestureLayer.GestureState.Abort, (data) => { OnGestureCanceled(type, data); }); - } - - void AddDoubleTapGesture(EGestureType type, double timeout) - { - if (timeout > 0) - _gestureLayer.DoubleTapTimeout = timeout; - - _gestureLayer.SetTapCallback(type, GestureLayer.GestureState.Start, (data) => { OnDoubleTapStarted(type, data); }); - _gestureLayer.SetTapCallback(type, GestureLayer.GestureState.End, (data) => { OnDoubleTapCompleted(type, data); }); - _gestureLayer.SetTapCallback(type, GestureLayer.GestureState.Abort, (data) => { OnGestureCanceled(type, data); }); - } - - void AddLongTapGesture(EGestureType type, double timeout) - { - if (timeout > 0) - _gestureLayer.LongTapTimeout = timeout; - - _gestureLayer.SetTapCallback(type, GestureLayer.GestureState.Start, (data) => { OnLongTapStarted(type, data); }); - _gestureLayer.SetTapCallback(type, GestureLayer.GestureState.Move, (data) => { OnLongTapMoved(type, data); }); - _gestureLayer.SetTapCallback(type, GestureLayer.GestureState.End, (data) => { OnLongTapCompleted(type, data); }); - _gestureLayer.SetTapCallback(type, GestureLayer.GestureState.Abort, (data) => { OnGestureCanceled(type, data); }); - } - - void AddFlickGesture(EGestureType type, double timeout) - { - if (timeout > 0) - _gestureLayer.FlickTimeLimit = (int)(timeout * 1000); - - // Task to correct wrong coordinates information when applying EvasMap(Xamarin ex: Translation, Scale, Rotate property) - // Always change to the absolute coordinates of the pointer. - int startX = 0; - int startY = 0; - _gestureLayer.SetFlickCallback(GestureLayer.GestureState.Start, (data) => - { - startX = _gestureLayer.EvasCanvas.Pointer.X; - startY = _gestureLayer.EvasCanvas.Pointer.Y; - data.X1 = startX; - data.Y1 = startY; - OnGestureStarted(type, data); - }); - _gestureLayer.SetFlickCallback(GestureLayer.GestureState.Move, (data) => - { - data.X1 = startX; - data.Y1 = startY; - data.X2 = _gestureLayer.EvasCanvas.Pointer.X; - data.Y2 = _gestureLayer.EvasCanvas.Pointer.Y; - OnGestureMoved(type, data); - }); - _gestureLayer.SetFlickCallback(GestureLayer.GestureState.End, (data) => - { - data.X1 = startX; - data.Y1 = startY; - data.X2 = _gestureLayer.EvasCanvas.Pointer.X; - data.Y2 = _gestureLayer.EvasCanvas.Pointer.Y; - OnGestureCompleted(type, data); - }); - _gestureLayer.SetFlickCallback(GestureLayer.GestureState.Abort, (data) => { OnGestureCanceled(type, data); }); - } - - void AddRotateGesture(EGestureType type) - { - _gestureLayer.SetRotateCallback(GestureLayer.GestureState.Start, (data) => { OnGestureStarted(type, data); }); - _gestureLayer.SetRotateCallback(GestureLayer.GestureState.Move, (data) => { OnGestureMoved(type, data); }); - _gestureLayer.SetRotateCallback(GestureLayer.GestureState.End, (data) => { OnGestureCompleted(type, data); }); - _gestureLayer.SetRotateCallback(GestureLayer.GestureState.Abort, (data) => { OnGestureCanceled(type, data); }); - } - - void AddMomentumGesture(EGestureType type) - { - // Task to correct wrong coordinates information when applying EvasMap(Xamarin ex: Translation, Scale, Rotate property) - // Always change to the absolute coordinates of the pointer. - int startX = 0; - int startY = 0; - _gestureLayer.SetMomentumCallback(GestureLayer.GestureState.Start, (data) => - { - startX = _gestureLayer.EvasCanvas.Pointer.X; - startY = _gestureLayer.EvasCanvas.Pointer.Y; - OnGestureStarted(type, data); - }); - _gestureLayer.SetMomentumCallback(GestureLayer.GestureState.Move, (data) => - { - data.X1 = startX; - data.Y1 = startY; - data.X2 = _gestureLayer.EvasCanvas.Pointer.X; - data.Y2 = _gestureLayer.EvasCanvas.Pointer.Y; - OnGestureMoved(type, data); - }); - _gestureLayer.SetMomentumCallback(GestureLayer.GestureState.End, (data) => { OnGestureCompleted(type, data); }); - _gestureLayer.SetMomentumCallback(GestureLayer.GestureState.Abort, (data) => { OnGestureCanceled(type, data); }); - } - - void RemoveLineGesture() - { - _gestureLayer.SetLineCallback(GestureLayer.GestureState.Start, null); - _gestureLayer.SetLineCallback(GestureLayer.GestureState.Move, null); - _gestureLayer.SetLineCallback(GestureLayer.GestureState.End, null); - _gestureLayer.SetLineCallback(GestureLayer.GestureState.Abort, null); - } - - void RemovePinchGesture() - { - _gestureLayer.SetZoomCallback(GestureLayer.GestureState.Start, null); - _gestureLayer.SetZoomCallback(GestureLayer.GestureState.Move, null); - _gestureLayer.SetZoomCallback(GestureLayer.GestureState.End, null); - _gestureLayer.SetZoomCallback(GestureLayer.GestureState.Abort, null); - } - - void RemoveTapGesture(EGestureType type) - { - _gestureLayer.SetTapCallback(type, GestureLayer.GestureState.Start, null); - _gestureLayer.SetTapCallback(type, GestureLayer.GestureState.End, null); - _gestureLayer.SetTapCallback(type, GestureLayer.GestureState.Abort, null); - } - - void RemoveFlickGesture() - { - _gestureLayer.SetFlickCallback(GestureLayer.GestureState.Start, null); - _gestureLayer.SetFlickCallback(GestureLayer.GestureState.Move, null); - _gestureLayer.SetFlickCallback(GestureLayer.GestureState.End, null); - _gestureLayer.SetFlickCallback(GestureLayer.GestureState.Abort, null); - } - - void RemoveRotateGesture() - { - _gestureLayer.SetRotateCallback(GestureLayer.GestureState.Start, null); - _gestureLayer.SetRotateCallback(GestureLayer.GestureState.Move, null); - _gestureLayer.SetRotateCallback(GestureLayer.GestureState.End, null); - _gestureLayer.SetRotateCallback(GestureLayer.GestureState.Abort, null); - } - - void RemoveMomentumGesture() - { - _gestureLayer.SetMomentumCallback(GestureLayer.GestureState.Start, null); - _gestureLayer.SetMomentumCallback(GestureLayer.GestureState.Move, null); - _gestureLayer.SetMomentumCallback(GestureLayer.GestureState.End, null); - _gestureLayer.SetMomentumCallback(GestureLayer.GestureState.Abort, null); - } - - #region GestureCallback - - void OnGestureStarted(EGestureType type, object data) - { - var cache = _handlerCache; - if (cache.ContainsKey(type)) - { - foreach (var handler in cache[type]) - { - (handler as IGestureController)?.SendStarted(View, data); - } - } - } - - void OnGestureMoved(EGestureType type, object data) - { - var cache = _handlerCache; - if (cache.ContainsKey(type)) - { - foreach (var handler in cache[type]) - { - (handler as IGestureController)?.SendMoved(View, data); - } - } - } - - void OnGestureCompleted(EGestureType type, object data) - { - var cache = _handlerCache; - if (cache.ContainsKey(type)) - { - foreach (var handler in cache[type]) - { - (handler as IGestureController)?.SendCompleted(View, data); - } - } - } - - void OnGestureCanceled(EGestureType type, object data) - { - var cache = _handlerCache; - if (cache.ContainsKey(type)) - { - foreach (var handler in cache[type]) - { - (handler as IGestureController)?.SendCanceled(View, data); - } - } - } - - void OnDoubleTapStarted(EGestureType type, object data) - { - _doubleTapTime = ((GestureLayer.TapData)data).Timestamp; - OnGestureStarted(type, data); - } - - void OnDoubleTapCompleted(EGestureType type, object data) - { - _doubleTapTime = ((GestureLayer.TapData)data).Timestamp - _doubleTapTime; - var cache = _handlerCache; - - if (cache.ContainsKey(type)) - { - foreach (var handler in cache[type]) - { - if ((handler.Timeout * 1000) >= _longTapTime) - (handler as IGestureController)?.SendCompleted(View, data); - else - (handler as IGestureController)?.SendCanceled(View, data); - } - } - } - - void OnLongTapStarted(EGestureType type, object data) - { - _longTapTime = ((GestureLayer.TapData)data).Timestamp; - OnGestureStarted(type, data); - } - - void OnLongTapMoved(EGestureType type, object data) - { - OnGestureMoved(type, data); - } - - void OnLongTapCompleted(EGestureType type, object data) - { - _longTapTime = ((GestureLayer.TapData)data).Timestamp - _longTapTime; - var cache = _handlerCache; - - if (cache.ContainsKey(type)) - { - foreach (var handler in cache[type]) - { - if ((handler.Timeout * 1000) <= _longTapTime) - (handler as IGestureController)?.SendCompleted(View, data); - else - (handler as IGestureController)?.SendCanceled(View, data); - } - } - } - - #endregion GestureCallback - - GestureHandler CreateHandler(IGestureRecognizer recognizer) - { - if (recognizer is TapGestureRecognizer) - { - return new TapGestureHandler(recognizer); - } - else if (recognizer is PinchGestureRecognizer) - { - return new PinchGestureHandler(recognizer); - } - else if (recognizer is PanGestureRecognizer) - { - return new PanGestureHandler(recognizer); - } - else if (recognizer is SwipeGestureRecognizer) - { - return new SwipeGestureHandler(recognizer); - } - else if (recognizer is DragGestureRecognizer) - { - return new DragGestureHandler(recognizer, _renderer); - } - else if (recognizer is DropGestureRecognizer) - { - return new DropGestureHandler(recognizer, _renderer); - } - return Forms.GetHandlerForObject(recognizer, recognizer); - } - - GestureHandler LookupHandler(IGestureRecognizer recognizer) - { - var cache = _handlerCache; - - foreach (var handlers in cache.Values) - { - foreach (var handler in handlers) - { - if (handler.Recognizer == recognizer) - return handler; - } - } - return null; - } - - void UpdateTapGesture(GestureHandler handler) - { - RemoveGesture(handler.Recognizer); - AddGesture(handler.Recognizer); - - if (handler.Timeout > _gestureLayer.DoubleTapTimeout) - _gestureLayer.DoubleTapTimeout = handler.Timeout; - } - - void UpdateLongTapGesture(GestureHandler handler) - { - if (handler.Timeout > 0 && handler.Timeout < _gestureLayer.LongTapTimeout) - _gestureLayer.LongTapTimeout = handler.Timeout; - } - - void UpdateFlickGesture(GestureHandler handler) - { - if (handler.Timeout > _gestureLayer.FlickTimeLimit) - _gestureLayer.FlickTimeLimit = (int)(handler.Timeout * 1000); - } - - void OnGestureRecognizerPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) - { - var handler = sender as GestureHandler; - if (handler != null) - { - switch (handler.Type) - { - case EGestureType.Tap: - case EGestureType.DoubleTap: - case EGestureType.TripleTap: - UpdateTapGesture(handler); - break; - - case EGestureType.LongTap: - UpdateLongTapGesture(handler); - break; - - case EGestureType.Flick: - UpdateFlickGesture(handler); - break; - - default: - break; - } - } - } - - void OnKeyDown(object sender, EvasKeyEventArgs e) - { - if (e.KeyName == "Return" && _gestureLayer.IsEnabled) - { - var cache = _handlerCache; - if (cache.ContainsKey(EGestureType.Tap)) - { - foreach (var handler in cache[EGestureType.Tap]) - { - (handler as IGestureController)?.SendStarted(View, null); - (handler as IGestureController)?.SendCompleted(View, null); - } - } - } - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/GestureHandler.cs b/src/Compatibility/Core/src/Tizen/GestureHandler.cs deleted file mode 100644 index 0df0a9928058..000000000000 --- a/src/Compatibility/Core/src/Tizen/GestureHandler.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.ComponentModel; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [Obsolete] - public abstract class GestureHandler : IGestureController, INotifyPropertyChanged, IRegisterable - { - public IGestureRecognizer Recognizer { get; private set; } - - public abstract GestureLayer.GestureType Type { get; } - - public virtual double Timeout { get; } - - protected GestureHandler(IGestureRecognizer recognizer) - { - Recognizer = recognizer; - Recognizer.PropertyChanged += OnRecognizerPropertyChanged; - } - - public event PropertyChangedEventHandler PropertyChanged; - - protected abstract void OnStarted(View sender, object data); - - protected abstract void OnMoved(View sender, object data); - - protected abstract void OnCompleted(View sender, object data); - - protected abstract void OnCanceled(View sender, object data); - - void IGestureController.SendStarted(View sender, object data) - { - OnStarted(sender, data); - } - - void IGestureController.SendCompleted(View sender, object data) - { - OnCompleted(sender, data); - } - - void IGestureController.SendMoved(View sender, object data) - { - OnMoved(sender, data); - } - - void IGestureController.SendCanceled(View sender, object data) - { - OnCanceled(sender, data); - } - - protected virtual void OnRecognizerPropertyChanged(object sender, PropertyChangedEventArgs e) - { - PropertyChanged?.Invoke(this, e); - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs b/src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs index fe07cba3ba82..8cb11efa8040 100644 --- a/src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs +++ b/src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs @@ -3,10 +3,7 @@ using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Controls.Platform; using Microsoft.Maui.Graphics; -using Microsoft.Maui.Handlers; -using Rect = Microsoft.Maui.Graphics.Rect; -using ERect = ElmSharp.Rect; -using EvasObject = ElmSharp.EvasObject; +using NView = Tizen.NUI.BaseComponents.View; namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen { @@ -26,7 +23,7 @@ public HandlerToRendererShim(IPlatformViewHandler vh) public VisualElement Element { get; private set; } - public EvasObject NativeView => ViewHandler.ContainerView ?? ViewHandler.PlatformView; + public NView NativeView => ViewHandler.ContainerView ?? ViewHandler.PlatformView; public event EventHandler ElementChanged; public event EventHandler ElementPropertyChanged; @@ -64,16 +61,6 @@ public void SetElement(VisualElement element) if (ViewHandler.VirtualView != element) ViewHandler.SetVirtualView((IView)element); - if (element.RealParent is IView view && view.Handler is IPlatformViewHandler nvh) - { - ViewHandler.SetParent(nvh); - } - else - { - ViewHandler.SetParent(new MockParentHandler(element.RealParent as VisualElement)); - } - - NativeView.Deleted += OnNativeDeleted; ElementChanged?.Invoke(this, new VisualElementChangedEventArgs(oldElement, Element)); } @@ -106,94 +93,5 @@ public void UpdateLayout() { ViewHandler.PlatformArrange(Element.Bounds); } - - public ERect GetNativeContentGeometry() - { - return NativeView.Geometry; - } - - class MockParentHandler : IPlatformViewHandler - { - - public MockParentHandler(VisualElement parent) - { - RealParent = parent; - } - - VisualElement RealParent { get; } - - public bool ForceContainer { get; set; } - - IVisualElementRenderer Renderer => RealParent != null ? Platform.GetRenderer(RealParent) : null; - public EvasObject PlatformView => Renderer.NativeView; - - public EvasObject ContainerView => PlatformView; - - public IPlatformViewHandler Parent => null; - - public IView VirtualView => Renderer.Element as IView; - - public IMauiContext MauiContext => null; - - object IElementHandler.PlatformView => PlatformView; - - object IViewHandler.ContainerView => PlatformView; - - bool IViewHandler.HasContainer { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - - Maui.IElement IElementHandler.VirtualView => throw new NotImplementedException(); - - public void DisconnectHandler() { } - - public void Dispose() - { - } - - public Size GetDesiredSize(double widthConstraint, double heightConstraint) - { - throw new NotImplementedException(); - } - - public ERect GetPlatformContentGeometry() - { - return Renderer?.GetNativeContentGeometry() ?? new ERect(0, 0, 0, 0); - } - - public void PlatformArrange(Rect frame) - { - throw new NotImplementedException(); - } - - public void SetMauiContext(IMauiContext mauiContext) - { - throw new NotImplementedException(); - } - - public void SetParent(IPlatformViewHandler parent) - { - throw new NotImplementedException(); - } - - public void SetVirtualView(IView view) - { - throw new NotImplementedException(); - } - - public void UpdateValue(string property) - { - throw new NotImplementedException(); - } - - public void SetVirtualView(Maui.IElement view) - { - throw new NotImplementedException(); - } - - public void Invoke(string command, object args) - { - throw new NotImplementedException(); - } - } - } } diff --git a/src/Compatibility/Core/src/Tizen/IGestureController.cs b/src/Compatibility/Core/src/Tizen/IGestureController.cs deleted file mode 100644 index 7882064e1bff..000000000000 --- a/src/Compatibility/Core/src/Tizen/IGestureController.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - public interface IGestureController - { - void SendStarted(View sender, object data); - - void SendMoved(View sender, object data); - - void SendCompleted(View sender, object data); - - void SendCanceled(View sender, object data); - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/IMEApplication.cs b/src/Compatibility/Core/src/Tizen/IMEApplication.cs deleted file mode 100644 index 96c07ef7802f..000000000000 --- a/src/Compatibility/Core/src/Tizen/IMEApplication.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using ElmSharp; -using Tizen.Uix.InputMethod; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [Obsolete] - public class IMEApplication : FormsApplication - { - public EditorWindow EditorWindow - { - get { return MainWindow as EditorWindow; } - } - - protected IMEApplication() - { - } - - protected override void OnPreCreate() - { - Application.ClearCurrent(); - - /* - * Since the IMEWindow class acquires window handle from InputMethod module and - * the handle is created internally when calling InputMethodEditor.Create() function, - * this needs to be called BEFORE creating new IMEWindow instance. - */ - InputMethodEditor.Create(); - MainWindow = InputMethodEditor.GetMainWindow(); - MainWindow.IndicatorMode = IndicatorMode.Hide; - } - - protected override void OnTerminate() - { - InputMethodEditor.Destroy(); - base.OnTerminate(); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/IRotaryInteraction.cs b/src/Compatibility/Core/src/Tizen/IRotaryInteraction.cs deleted file mode 100644 index 16e34cfbdd97..000000000000 --- a/src/Compatibility/Core/src/Tizen/IRotaryInteraction.cs +++ /dev/null @@ -1,9 +0,0 @@ -using ElmSharp.Wearable; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - public interface IRotaryInteraction - { - IRotaryActionWidget RotaryWidget { get; } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/LightweightPlatform.cs b/src/Compatibility/Core/src/Tizen/LightweightPlatform.cs deleted file mode 100644 index 71e404694419..000000000000 --- a/src/Compatibility/Core/src/Tizen/LightweightPlatform.cs +++ /dev/null @@ -1,216 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using ElmSharp; -using Microsoft.Maui.Controls.Internals; -using Microsoft.Maui.Devices; -using EColor = ElmSharp.Color; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [Obsolete] - public class LightweightPlatform : ITizenPlatform, INavigation, IDisposable - { - NavigationModel _navModel = new NavigationModel(); - Native.Canvas _viewStack; - readonly PopupManager _popupManager; - bool _hasAlpha; - readonly EColor _defaultPlatformColor; - - public LightweightPlatform(EvasObject parent) - { - Forms.NativeParent = parent; - _defaultPlatformColor = DeviceInfo.Idiom == DeviceIdiom.Phone ? EColor.White : EColor.Transparent; - _viewStack = new Native.Canvas(parent) - { - BackgroundColor = _defaultPlatformColor, - }; - _viewStack.SetAlignment(-1, -1); - _viewStack.SetWeight(1.0, 1.0); - _viewStack.LayoutUpdated += OnLayout; - _viewStack.Show(); - - if (Forms.UseMessagingCenter) - { - _popupManager = new PopupManager(this); - } - } - -#pragma warning disable 0067 - public event EventHandler RootNativeViewChanged; -#pragma warning restore 0067 - - public bool HasAlpha - { - get => _hasAlpha; - set - { - _hasAlpha = value; - _viewStack.BackgroundColor = _hasAlpha ? EColor.Transparent : _defaultPlatformColor; - } - } - - IPageController CurrentPageController => _navModel.CurrentPage as IPageController; - - IReadOnlyList INavigation.ModalStack => _navModel.Modals.ToList(); - - IReadOnlyList INavigation.NavigationStack => new List(); - - public void SetPage(Page page) - { - ResetChildren(); - _navModel = new NavigationModel(); - if (page == null) - return; - - _navModel.Push(page, null); - - ((Application)page.RealParent).NavigationProxy.Inner = this; - - var renderer = Platform.CreateRenderer(page); - renderer.NativeView.Geometry = _viewStack.Geometry; - _viewStack.Children.Add(renderer.NativeView); - - CurrentPageController?.SendAppearing(); - } - - public bool SendBackButtonPressed() - { - return _navModel?.CurrentPage?.SendBackButtonPressed() ?? false; - } - - public EvasObject GetRootNativeView() - { - return _viewStack; - } - - public bool PageIsChildOfPlatform(Page page) - { - var parent = page.AncestorToRoot(); - return _navModel.Modals.FirstOrDefault() == page || _navModel.Roots.Contains(parent); - } - - public void Dispose() - { - Dispose(true); - } - - protected virtual void Dispose(bool disposing) - { - if (disposing) - { - _popupManager?.Dispose(); - _viewStack?.Unrealize(); - } - } - - Task INavigation.PopModalAsync() - { - return (this as INavigation).PopModalAsync(true); - } - - Task INavigation.PopModalAsync(bool animated) - { - Page page = _navModel.PopModal(); - (page as IPageController)?.SendDisappearing(); - - var renderer = Platform.GetRenderer(page); - _viewStack.Children.Remove(renderer.NativeView); - renderer.Dispose(); - - _viewStack.Children.LastOrDefault()?.Show(); - - CurrentPageController?.SendAppearing(); - return Task.FromResult(page); - } - - Task INavigation.PushModalAsync(Page modal) - { - return (this as INavigation).PushModalAsync(modal, true); - } - - Task INavigation.PushModalAsync(Page page, bool animated) - { - var previousPage = CurrentPageController; - previousPage?.SendDisappearing(); - - _navModel.PushModal(page); - - var lastTop = _viewStack.Children.LastOrDefault(); - - var renderer = Platform.GetOrCreateRenderer(page); - renderer.NativeView.Geometry = _viewStack.Geometry; - - _viewStack.Children.Add(renderer.NativeView); - if (lastTop != null) - { - lastTop.Hide(); - renderer.NativeView.StackAbove(lastTop); - } - - // Verify that the modal is still on the stack - if (_navModel.CurrentPage == page) - CurrentPageController.SendAppearing(); - return Task.CompletedTask; - } - - void INavigation.InsertPageBefore(Page page, Page before) - { - throw new InvalidOperationException("InsertPageBefore is not supported globally on Tizen, please use a NavigationPage."); - } - - Task INavigation.PopAsync() - { - return ((INavigation)this).PopAsync(true); - } - - Task INavigation.PopAsync(bool animated) - { - throw new InvalidOperationException("PopAsync is not supported globally on Tizen, please use a NavigationPage."); - } - - Task INavigation.PopToRootAsync() - { - return ((INavigation)this).PopToRootAsync(true); - } - - Task INavigation.PopToRootAsync(bool animated) - { - throw new InvalidOperationException("PopToRootAsync is not supported globally on Tizen, please use a NavigationPage."); - } - - Task INavigation.PushAsync(Page root) - { - return ((INavigation)this).PushAsync(root, true); - } - - Task INavigation.PushAsync(Page root, bool animated) - { - throw new InvalidOperationException("PushAsync is not supported globally on Tizen, please use a NavigationPage."); - } - - void INavigation.RemovePage(Page page) - { - throw new InvalidOperationException("RemovePage is not supported globally on Tizen, please use a NavigationPage."); - } - - void OnLayout(object sender, Native.LayoutEventArgs e) - { - foreach (var child in _viewStack.Children) - { - child.Geometry = _viewStack.Geometry; - } - } - - void ResetChildren() - { - var children = _viewStack.Children.ToList(); - _viewStack.Children.Clear(); - foreach (var child in children) - { - child.Unrealize(); - } - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/BatchableExtensions.cs b/src/Compatibility/Core/src/Tizen/Native/BatchableExtensions.cs deleted file mode 100644 index f931ddc1280c..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/BatchableExtensions.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System.Runtime.CompilerServices; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - internal static class BatchableExtensions - { - static readonly ConditionalWeakTable s_counters = new ConditionalWeakTable(); - - public static void BatchBegin(this IBatchable target) - { - BatchCount value = null; - - if (s_counters.TryGetValue(target, out value)) - { - value.Count++; - } - else - { - s_counters.Add(target, new BatchCount()); - } - } - - public static void BatchCommit(this IBatchable target) - { - BatchCount value = null; - if (s_counters.TryGetValue(target, out value)) - { - value.Count--; - if (value.Count == 0) - { - target.OnBatchCommitted(); - } - else if (value.Count < 0) - { - Log.Error("Called BatchCommit() without BatchBegin()."); - value.Count = 0; - } - } - else - { - Log.Error("Called BatchCommit() without BatchBegin()."); - } - } - - public static bool IsBatched(this IBatchable target) - { - BatchCount value = null; - - if (s_counters.TryGetValue(target, out value)) - { - return value.Count != 0; - } - else - { - return false; - } - } - - class BatchCount - { - public int Count = 1; - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/BorderRectangle.cs b/src/Compatibility/Core/src/Tizen/Native/BorderRectangle.cs deleted file mode 100644 index db0dcdb2c3bc..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/BorderRectangle.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using System.Collections.Generic; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class BorderRectangle : RoundRectangle - { - public BorderRectangle(EvasObject parent) : base(parent) { } - - public int BorderWidth { get; set; } - - protected override void DrawPoints() - { - ClearPoints(); - if (BorderWidth > 0) - { - IReadOnlyList radius = GetRadius(); - DrawRect(radius[0], radius[1], radius[2], radius[3], - 0, 0, Width, Height); - DrawRect(Math.Max(radius[0] - BorderWidth, 0), - Math.Max(radius[1] - BorderWidth, 0), - Math.Max(radius[2] - BorderWidth, 0), - Math.Max(radius[3] - BorderWidth, 0), - BorderWidth, BorderWidth, Width - BorderWidth * 2, Height - BorderWidth * 2); - } - } - - protected void DrawRect(int topLeft, int topRight, int bottomLeft, int bottomRight, int startX, int startY, int width, int height) - { - int[] radius = new int[4]; - int maxR = Math.Min(width / 2, height / 2); - radius[0] = Math.Min(topLeft, maxR); - radius[1] = Math.Min(topRight, maxR); - radius[2] = Math.Min(bottomLeft, maxR); - radius[3] = Math.Min(bottomRight, maxR); - - Graphics.Point first = new Graphics.Point(-1, -1); - for (int i = 0; i <= radius[0]; i++) - { - int x = i; - int dx = radius[0] - x; - int y = radius[0] - (int)Math.Sqrt((radius[0] * radius[0]) - (dx * dx)); - AddRelativePoint(startX + x, startY + y); - if (first.X < 0 && first.Y < 0) - { - first.X = startX + x; - first.Y = startY + y; - } - } - - AddRelativePoint(startX + width - radius[1], startY); - - for (int i = width - radius[1]; i <= width; i++) - { - int x = i; - int dx = radius[1] - (width - x); - int y = radius[1] - (int)Math.Sqrt((radius[1] * radius[1]) - (dx * dx)); - AddRelativePoint(startX + x, startY + y); - } - - AddRelativePoint(startX + width, startY + height - radius[3]); - - for (int i = width; i >= width - radius[3]; i--) - { - int x = i; - int dx = radius[3] - (width - x); - int y = height - radius[3] + (int)Math.Sqrt((radius[3] * radius[3]) - (dx * dx)); - AddRelativePoint(startX + x, startY + y); - } - - AddRelativePoint(startX + radius[2], startY + height); - - for (int i = radius[2]; i >= 0; i--) - { - int x = i; - int dx = radius[2] - x; - int y = height - radius[2] + (int)Math.Sqrt((radius[2] * radius[2]) - (dx * dx)); - AddRelativePoint(startX + x, startY + y); - } - AddRelativePoint((int)first.X, (int)first.Y); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/Box.cs b/src/Compatibility/Core/src/Tizen/Native/Box.cs deleted file mode 100644 index 10e6d240f74e..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Box.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using ElmSharp; -using EBox = ElmSharp.Box; -using ERect = ElmSharp.Rect; - -#if __MATERIAL__ -using Tizen.NET.MaterialComponents; -#endif - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ -#if __MATERIAL__ - public class MaterialBox : MCard - { - public MaterialBox(EvasObject parent) : base(parent) - { - SetLayoutCallback(() => { NotifyOnLayout(); }); - } -#else - /// - /// Extends the ElmSharp.Box class with functionality useful to Microsoft.Maui.Controls.Compatibility renderer. - /// - /// - /// This class overrides the layout mechanism. Instead of using the native layout, - /// LayoutUpdated event is sent. - /// - public class Box : EBox - { - public Box(EvasObject parent) : base(parent) - { - SetLayoutCallback(() => { NotifyOnLayout(); }); - } -#endif - - /// - /// Notifies that the layout has been updated. - /// - public event EventHandler LayoutUpdated; - - /// - /// Triggers the LayoutUpdated event. - /// - /// - /// This method is called whenever there is a possibility that the size and/or position has been changed. - /// - void NotifyOnLayout() - { - if (null != LayoutUpdated) - { - LayoutUpdated(this, new LayoutEventArgs() { Geometry = Geometry }); - } - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/Button.cs b/src/Compatibility/Core/src/Tizen/Native/Button.cs deleted file mode 100644 index f53ecefb664d..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Button.cs +++ /dev/null @@ -1,282 +0,0 @@ -using System; -using ElmSharp; -using EButton = ElmSharp.Button; -using EColor = ElmSharp.Color; -using ESize = ElmSharp.Size; -using TSButtonStyle = Microsoft.Maui.Controls.PlatformConfiguration.TizenSpecific.ButtonStyle; - -#if __MATERIAL__ -using Tizen.NET.MaterialComponents; -#endif - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ -#if __MATERIAL__ - public class MaterialButton : MButton, IMeasurable, IBatchable, IButton - { - public MaterialButton(EvasObject parent) : base(parent) - { - } -#else - /// - /// Extends the EButton control, providing basic formatting features, - /// i.e. font color, size, additional image. - /// - public class Button : EButton, IMeasurable, IBatchable, IButton - { - /// - /// Initializes a new instance of the class. - /// - /// Parent evas object. - public Button(EvasObject parent) : base(parent) - { - } -#endif - /// - /// Holds the formatted text of the button. - /// - readonly Span _span = new Span(); - - /// - /// Optional image, if set will be drawn on the button. - /// - Image _image; - - /// - /// Gets or sets the button's text. - /// - /// The text. - public override string Text - { - get - { - return _span.Text; - } - - set - { - if (value != _span.Text) - { - _span.Text = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the color of the text. - /// - /// The color of the text. - public EColor TextColor - { - get - { - return _span.ForegroundColor; - } - - set - { - if (!_span.ForegroundColor.Equals(value)) - { - _span.ForegroundColor = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the color of the text background. - /// - /// The color of the text background. - public EColor TextBackgroundColor - { - get - { - return _span.BackgroundColor; - } - - set - { - if (!_span.BackgroundColor.Equals(value)) - { - _span.BackgroundColor = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the font family. - /// - /// The font family. - public string FontFamily - { - get - { - return _span.FontFamily; - } - - set - { - if (value != _span.FontFamily) - { - _span.FontFamily = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the font attributes. - /// - /// The font attributes. - public FontAttributes FontAttributes - { - get - { - return _span.FontAttributes; - } - - set - { - if (value != _span.FontAttributes) - { - _span.FontAttributes = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the size of the font. - /// - /// The size of the font. - public double FontSize - { - get - { - return _span.FontSize; - } - - set - { - if (value != _span.FontSize) - { - _span.FontSize = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the image to be displayed next to the button's text. - /// - /// The image displayed on the button. - public Image Image - { - get - { - return _image; - } - - set - { - if (value != _image) - { - ApplyImage(value); - } - } - } - - /// - /// Implementation of the IMeasurable.Measure() method. - /// - public virtual ESize Measure(int availableWidth, int availableHeight) - { - if (Style == TSButtonStyle.Circle) - { - return new ESize(MinimumWidth, MinimumHeight); - } - else - { - if (Image != null) - MinimumWidth += Image.Geometry.Width; - - var rawSize = this.GetTextBlockNativeSize(); - return new ESize(rawSize.Width + MinimumWidth, Math.Max(MinimumHeight, rawSize.Height)); - } - } - - void IBatchable.OnBatchCommitted() - { - ApplyTextAndStyle(); - } - - /// - /// Applies the button's text and its style. - /// - void ApplyTextAndStyle() - { - if (!this.IsBatched()) - { - SetInternalTextAndStyle(_span.GetDecoratedText(), _span.GetStyle()); - } - } - - /// - /// Sets the button's internal text and its style. - /// - /// Formatted text, supports HTML tags. - /// Style applied to the formattedText. - void SetInternalTextAndStyle(string formattedText, string textStyle) - { - bool isVisible = true; - if (string.IsNullOrEmpty(formattedText)) - { - formattedText = null; - textStyle = null; - isVisible = false; - } - base.Text = formattedText; - this.SetTextBlockStyle(textStyle); - this.SendTextVisibleSignal(isVisible); - } - - /// - /// Applies the image to be displayed on the button. If value is null, - /// image will be removed. - /// - /// Image to be displayed or null. - void ApplyImage(Image image) - { - _image = image; - - SetInternalImage(); - } - - /// - /// Sets the internal image. If value is null, image will be removed. - /// - void SetInternalImage() - { - this.SetIconPart(_image); - } - - /// - /// Update the button's style - /// - /// The style of button - public void UpdateStyle(string style) - { - if (Style != style) - { - Style = style; - if (Style == TSButtonStyle.Default) - _span.HorizontalTextAlignment = TextAlignment.Auto; - else - _span.HorizontalTextAlignment = TextAlignment.Center; - ApplyTextAndStyle(); - } - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Native/Canvas.cs b/src/Compatibility/Core/src/Tizen/Native/Canvas.cs deleted file mode 100644 index c90634a29d2b..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Canvas.cs +++ /dev/null @@ -1,131 +0,0 @@ -using System.Collections.Generic; -using System.Collections.Specialized; -using ElmSharp; - -#if __MATERIAL__ -using Tizen.NET.MaterialComponents; -#endif - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ -#if __MATERIAL__ - public class MaterialCanvas : MaterialBox, IContainable - { - public MaterialCanvas(EvasObject parent) : base(parent) - { - Initilize(); - } - -#else - /// - /// A Canvas provides a class which can be a container for other controls. - /// - /// - /// This class is used as a container view for Layouts from Microsoft.Maui.Controls.Compatibility.Platform.Tizen framework. - /// It is used for implementing xamarin pages and layouts. - /// - public class Canvas : Box, IContainable - { - /// - /// Initializes a new instance of the class. - /// - /// Canvas doesn't support replacing its children, this will be ignored. - /// Parent of this instance. - public Canvas(EvasObject parent) : base(parent) - { - Initilize(); - } -#endif - - /// - /// The list of Views. - /// - readonly ObservableCollection _children = new ObservableCollection(); - - /// - /// Gets list of native elements that are placed in the canvas. - /// - public new IList Children - { - get - { - return _children; - } - } - - /// - /// Provides destruction for native element and contained elements. - /// - protected override void OnUnrealize() - { - foreach (var child in _children) - { - child.Unrealize(); - } - - base.OnUnrealize(); - } - - /// - /// Initializes a new instance of the the class - /// - void Initilize() - { - _children.CollectionChanged += (o, e) => - { - if (e.Action == NotifyCollectionChangedAction.Add) - { - foreach (var v in e.NewItems) - { - var view = v as EvasObject; - if (null != view) - { - OnAdd(view); - } - } - } - else if (e.Action == NotifyCollectionChangedAction.Remove) - { - foreach (var v in e.OldItems) - { - var view = v as EvasObject; - if (null != view) - { - OnRemove(view); - } - } - } - else if (e.Action == NotifyCollectionChangedAction.Reset) - { - OnRemoveAll(); - } - }; - } - - /// - /// Adds a new child to a container. - /// - /// Native element which will be added - void OnAdd(EvasObject view) - { - PackEnd(view); - } - - /// - /// Removes a child from a container. - /// - /// Child element to be removed from canvas - void OnRemove(EvasObject view) - { - UnPack(view); - } - - /// - /// Removes all children from a canvas. - /// - void OnRemoveAll() - { - UnPackAll(); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/CollectionView/CarouselView.cs b/src/Compatibility/Core/src/Tizen/Native/CollectionView/CarouselView.cs deleted file mode 100644 index a1207c500fad..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/CollectionView/CarouselView.cs +++ /dev/null @@ -1,23 +0,0 @@ -using ElmSharp; -using EScroller = ElmSharp.Scroller; -using ESize = ElmSharp.Size; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class CarouselView : CollectionView, ICollectionViewController - { - public CarouselView(EvasObject parent) : base(parent) - { - SelectionMode = CollectionViewSelectionMode.Single; - Scroll.ScrollBlock = ScrollBlock.None; - SnapPointsType = SnapPointsType.MandatorySingle; - } - - public EScroller Scroll => base.Scroller; - - ESize ICollectionViewController.GetItemSize(int widthConstraint, int heightConstraint) - { - return AllocatedSize; - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/CollectionView/CollectionView.cs b/src/Compatibility/Core/src/Tizen/Native/CollectionView/CollectionView.cs deleted file mode 100644 index 46dbbefb1d95..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/CollectionView/CollectionView.cs +++ /dev/null @@ -1,793 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Linq; -using Microsoft.Maui.Devices; -using ElmSharp; -using ElmSharp.Wearable; -using EBox = ElmSharp.Box; -using EPoint = ElmSharp.Point; -using ERect = ElmSharp.Rect; -using EScroller = ElmSharp.Scroller; -using ESize = ElmSharp.Size; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class CollectionView : EBox, ICollectionViewController, IRotaryInteraction - { - RecyclerPool _pool = new RecyclerPool(); - ICollectionViewLayoutManager _layoutManager; - ItemAdaptor _adaptor; - EBox _innerLayout; - EvasObject _emptyView; - - Dictionary _viewHolderIndexTable = new Dictionary(); - ViewHolder _lastSelectedViewHolder; - int _selectedItemIndex = -1; - CollectionViewSelectionMode _selectionMode = CollectionViewSelectionMode.None; - - bool _requestLayoutItems = false; - SnapPointsType _snapPoints; - ESize _itemSize = new ESize(-1, -1); - - EvasObject _headerView; - EvasObject _footerView; - SmartEvent _scrollAnimationStop; - SmartEvent _scrollAnimationStart; - bool _isScrollAnimationStarted; - bool _allowFocusOnItem; - - public event EventHandler Scrolled; - - public CollectionView(EvasObject parent) : base(parent) - { - AllowFocus(true); - SetLayoutCallback(OnLayout); - Scroller = CreateScroller(parent); - Scroller.Show(); - PackEnd(Scroller); - Scroller.Scrolled += OnScrolled; - - _scrollAnimationStart = new SmartEvent(Scroller, ThemeConstants.Scroller.Signals.StartScrollAnimation); - _scrollAnimationStart.On += OnScrollStarted; - - _scrollAnimationStop = new SmartEvent(Scroller, ThemeConstants.Scroller.Signals.StopScrollAnimation); - _scrollAnimationStop.On += OnScrollStopped; - - Scroller.DragStart += OnDragStart; - Scroller.KeyDown += OnKeyDown; - - _innerLayout = new EBox(parent); - _innerLayout.SetLayoutCallback(OnInnerLayout); - _innerLayout.Show(); - Scroller.SetContent(_innerLayout); - } - - public IRotaryActionWidget RotaryWidget { get => Scroller as IRotaryActionWidget; } - - public CollectionViewSelectionMode SelectionMode - { - get => _selectionMode; - set - { - _selectionMode = value; - UpdateSelectionMode(); - } - } - - public int SelectedItemIndex - { - get => _selectedItemIndex; - set - { - if (_selectedItemIndex != value) - { - _selectedItemIndex = value; - UpdateSelectedItemIndex(); - } - } - } - - public SnapPointsType SnapPointsType - { - get => _snapPoints; - set - { - _snapPoints = value; - UpdateSnapPointsType(_snapPoints); - } - } - - protected EScroller Scroller { get; } - - public ICollectionViewLayoutManager LayoutManager - { - get => _layoutManager; - set - { - OnLayoutManagerChanging(); - _layoutManager = value; - OnLayoutManagerChanged(); - } - } - - public ItemAdaptor Adaptor - { - get => _adaptor; - set - { - OnAdaptorChanging(); - _adaptor = value; - OnAdaptorChanged(); - } - } - - public ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy - { - get => Scroller.VerticalScrollBarVisiblePolicy; - set => Scroller.VerticalScrollBarVisiblePolicy = value; - } - - public ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy - { - get => Scroller.HorizontalScrollBarVisiblePolicy; - set => Scroller.HorizontalScrollBarVisiblePolicy = value; - } - - public ScrollToPosition FocusedItemScrollPosition { get; set; } - - int ICollectionViewController.Count - { - get - { - if (Adaptor == null || Adaptor is IEmptyAdaptor) - return 0; - return Adaptor.Count; - } - } - - EPoint ICollectionViewController.ParentPosition => new EPoint - { - X = Scroller.Geometry.X - Scroller.CurrentRegion.X, - Y = Scroller.Geometry.Y - Scroller.CurrentRegion.Y - }; - - protected ESize AllocatedSize { get; set; } - - ERect ViewPort => Scroller.CurrentRegion; - - public void ScrollTo(int index, ScrollToPosition position = ScrollToPosition.MakeVisible, bool animate = true) - { - var itemBound = LayoutManager.GetItemBound(index); - int itemStart; - int itemEnd; - int scrollStart; - int scrollEnd; - int itemPadding = 0; - int itemSize; - int viewportSize; - - if (LayoutManager.IsHorizontal) - { - itemStart = itemBound.Left; - itemEnd = itemBound.Right; - itemSize = itemBound.Width; - scrollStart = Scroller.CurrentRegion.Left; - scrollEnd = Scroller.CurrentRegion.Right; - viewportSize = AllocatedSize.Width; - } - else - { - itemStart = itemBound.Top; - itemEnd = itemBound.Bottom; - itemSize = itemBound.Height; - scrollStart = Scroller.CurrentRegion.Top; - scrollEnd = Scroller.CurrentRegion.Bottom; - viewportSize = AllocatedSize.Height; - } - - if (position == ScrollToPosition.MakeVisible) - { - if (itemStart < scrollStart) - { - position = ScrollToPosition.Start; - } - else if (itemEnd > scrollEnd) - { - position = ScrollToPosition.End; - } - else - { - // already visible - return; - } - } - - if (itemSize < viewportSize) - { - switch (position) - { - case ScrollToPosition.Center: - itemPadding = (viewportSize - itemSize) / 2; - break; - case ScrollToPosition.End: - itemPadding = (viewportSize - itemSize); - break; - } - itemSize = viewportSize; - } - - if (LayoutManager.IsHorizontal) - { - itemBound.X -= itemPadding; - itemBound.Width = itemSize; - } - else - { - itemBound.Y -= itemPadding; - itemBound.Height = itemSize; - } - - Scroller.ScrollTo(itemBound, animate); - } - - public void ScrollTo(object item, ScrollToPosition position = ScrollToPosition.MakeVisible, bool animate = true) - { - ScrollTo(Adaptor.GetItemIndex(item), position, animate); - } - - public void ItemMeasureInvalidated(int index) - { - // If a first item size was updated, need to reset _itemSize - if (index == 0) - { - _itemSize = new ESize(-1, -1); - } - LayoutManager?.ItemMeasureInvalidated(index); - } - - void ICollectionViewController.RequestLayoutItems() => RequestLayoutItems(); - - ESize ICollectionViewController.GetItemSize() - { - return (this as ICollectionViewController).GetItemSize(LayoutManager.IsHorizontal ? AllocatedSize.Width * 100 : AllocatedSize.Width, LayoutManager.IsHorizontal ? AllocatedSize.Height : AllocatedSize.Height * 100); - } - - ESize ICollectionViewController.GetItemSize(int widthConstraint, int heightConstraint) - { - if (Adaptor == null) - { - return new ESize(0, 0); - } - - if (_itemSize.Width > 0 && _itemSize.Height > 0) - { - return _itemSize; - } - - _itemSize = Adaptor.MeasureItem(widthConstraint, heightConstraint); - _itemSize.Width = Math.Max(_itemSize.Width, 10); - _itemSize.Height = Math.Max(_itemSize.Height, 10); - - if (_snapPoints != SnapPointsType.None) - { - Scroller.SetPageSize(_itemSize.Width, _itemSize.Height); - } - return _itemSize; - } - - ESize ICollectionViewController.GetItemSize(int index, int widthConstraint, int heightConstraint) - { - if (Adaptor == null) - { - return new ESize(0, 0); - } - return Adaptor.MeasureItem(index, widthConstraint, heightConstraint); - } - - protected virtual ViewHolder CreateViewHolder() - { - return new ViewHolder(this); - } - - ViewHolder ICollectionViewController.RealizeView(int index) - { - if (Adaptor == null) - return null; - - var holder = _pool.GetRecyclerView(Adaptor.GetViewCategory(index)); - if (holder != null) - { - holder.Show(); - } - else - { - var content = Adaptor.CreateNativeView(index, this); - holder = CreateViewHolder(); - holder.RequestSelected += OnRequestItemSelection; - holder.StateUpdated += OnItemStateChanged; - holder.Content = content; - holder.ViewCategory = Adaptor.GetViewCategory(index); - _innerLayout.PackEnd(holder); - } - - holder.AllowItemFocus = _allowFocusOnItem; - - Adaptor.SetBinding(holder.Content, index); - _viewHolderIndexTable[holder] = index; - if (index == SelectedItemIndex) - { - OnRequestItemSelection(holder, EventArgs.Empty); - } - return holder; - } - - void OnItemStateChanged(object sender, EventArgs e) - { - ViewHolder holder = (ViewHolder)sender; - if (holder.Content != null) - { - Adaptor?.UpdateViewState(holder.Content, holder.State); - } - - if (holder.State == ViewHolderState.Focused && FocusedItemScrollPosition != ScrollToPosition.MakeVisible) - { - - Application.Current.Dispatcher.Dispatch(() => - { - if (holder.State == ViewHolderState.Focused && _viewHolderIndexTable.TryGetValue(holder, out int itemIndex)) - { - ScrollTo(itemIndex, FocusedItemScrollPosition, true); - } - }); - } - } - - void OnRequestItemSelection(object sender, EventArgs e) - { - if (SelectionMode == CollectionViewSelectionMode.None) - return; - - if (_lastSelectedViewHolder != null) - { - _lastSelectedViewHolder.ResetState(); - } - - _lastSelectedViewHolder = sender as ViewHolder; - if (_lastSelectedViewHolder != null) - { - _lastSelectedViewHolder.State = ViewHolderState.Selected; - if (_viewHolderIndexTable.TryGetValue(_lastSelectedViewHolder, out int index)) - { - _selectedItemIndex = index; - Adaptor?.SendItemSelected(index); - } - } - } - - void ICollectionViewController.UnrealizeView(ViewHolder view) - { - _viewHolderIndexTable.Remove(view); - Adaptor.UnBinding(view.Content); - view.ResetState(); - view.Hide(); - - _pool.AddRecyclerView(view); - if (_lastSelectedViewHolder == view) - { - _lastSelectedViewHolder = null; - } - } - - void ICollectionViewController.ContentSizeUpdated() - { - OnInnerLayout(); - } - - protected virtual EScroller CreateScroller(EvasObject parent) - { - if (DeviceInfo.Idiom == DeviceIdiom.Watch) - { - return new CircleScroller(parent, Forms.CircleSurface); - } - else - { - return new EScroller(parent); - } - } - - void UpdateSelectedItemIndex() - { - if (SelectionMode == CollectionViewSelectionMode.None) - return; - - ViewHolder holder = null; - foreach (var item in _viewHolderIndexTable) - { - if (item.Value == SelectedItemIndex) - { - holder = item.Key; - break; - } - } - OnRequestItemSelection(holder, EventArgs.Empty); - } - - void UpdateSelectionMode() - { - if (SelectionMode == CollectionViewSelectionMode.None) - { - if (_lastSelectedViewHolder != null) - { - _lastSelectedViewHolder.ResetState(); - _lastSelectedViewHolder = null; - } - _selectedItemIndex = -1; - } - } - - void OnLayoutManagerChanging() - { - _layoutManager?.Reset(); - } - - void OnLayoutManagerChanged() - { - if (_layoutManager == null) - return; - - _itemSize = new ESize(-1, -1); - _layoutManager.CollectionView = this; - _layoutManager.SizeAllocated(AllocatedSize); - UpdateSnapPointsType(SnapPointsType); - if (Adaptor != null) - { - LayoutManager?.SetHeader(_headerView, Adaptor.MeasureHeader(AllocatedSize.Width, AllocatedSize.Height)); - LayoutManager?.SetFooter(_footerView, Adaptor.MeasureFooter(AllocatedSize.Width, AllocatedSize.Height)); - } - RequestLayoutItems(); - } - - void OnAdaptorChanging() - { - if (Adaptor is IEmptyAdaptor) - { - RemoveEmptyView(); - } - else - { - if (_headerView != null) - { - _innerLayout.UnPack(_headerView); - _headerView.Unrealize(); - } - if (_footerView != null) - { - _innerLayout.UnPack(_footerView); - _footerView.Unrealize(); - } - } - _headerView = null; - _footerView = null; - - _layoutManager?.Reset(); - if (Adaptor != null) - { - _pool.Clear(Adaptor); - (Adaptor as INotifyCollectionChanged).CollectionChanged -= OnCollectionChanged; - Adaptor.CollectionView = null; - } - } - - void OnAdaptorChanged() - { - if (_adaptor == null) - return; - - _itemSize = new ESize(-1, -1); - Adaptor.CollectionView = this; - (Adaptor as INotifyCollectionChanged).CollectionChanged += OnCollectionChanged; - - UpdateSnapPointsType(SnapPointsType); - LayoutManager?.ItemSourceUpdated(); - RequestLayoutItems(); - - if (Adaptor is IEmptyAdaptor) - { - CreateEmptyView(); - } - else - { - _headerView = Adaptor.GetHeaderView(this); - if (_headerView != null) - { - _innerLayout.PackEnd(_headerView); - } - _footerView = Adaptor.GetFooterView(this); - if (_footerView != null) - { - _innerLayout.PackEnd(_footerView); - } - LayoutManager?.SetHeader(_headerView, Adaptor.MeasureHeader(AllocatedSize.Width, AllocatedSize.Height)); - LayoutManager?.SetFooter(_footerView, Adaptor.MeasureFooter(AllocatedSize.Width, AllocatedSize.Height)); - } - } - - void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - // CollectionChanged could be called when Apaptor was changed on CollectionChanged event - if (Adaptor is IEmptyAdaptor) - { - return; - } - - if (e.Action == NotifyCollectionChangedAction.Add) - { - int idx = e.NewStartingIndex; - if (idx == -1) - { - idx = Adaptor.Count - e.NewItems.Count; - } - foreach (var item in e.NewItems) - { - foreach (var viewHolder in _viewHolderIndexTable.Keys.ToList()) - { - if (_viewHolderIndexTable[viewHolder] >= idx) - { - _viewHolderIndexTable[viewHolder]++; - } - } - LayoutManager.ItemInserted(idx++); - } - } - else if (e.Action == NotifyCollectionChangedAction.Remove) - { - int idx = e.OldStartingIndex; - - // Can't tracking remove if there is no data of old index - if (idx == -1) - { - LayoutManager.ItemSourceUpdated(); - } - else - { - foreach (var item in e.OldItems) - { - LayoutManager.ItemRemoved(idx); - foreach (var viewHolder in _viewHolderIndexTable.Keys.ToList()) - { - if (_viewHolderIndexTable[viewHolder] > idx) - { - _viewHolderIndexTable[viewHolder]--; - } - } - } - } - } - else if (e.Action == NotifyCollectionChangedAction.Move) - { - LayoutManager.ItemRemoved(e.OldStartingIndex); - LayoutManager.ItemInserted(e.NewStartingIndex); - } - else if (e.Action == NotifyCollectionChangedAction.Replace) - { - // Can't tracking if there is no information old data - if (e.OldItems.Count > 1 || e.NewStartingIndex == -1) - { - LayoutManager.ItemSourceUpdated(); - } - else - { - LayoutManager.ItemUpdated(e.NewStartingIndex); - } - } - else if (e.Action == NotifyCollectionChangedAction.Reset) - { - LayoutManager.Reset(); - LayoutManager.ItemSourceUpdated(); - } - RequestLayoutItems(); - } - - ERect _lastGeometry; - void OnLayout() - { - if (_lastGeometry == Geometry) - { - return; - } - - _lastGeometry = Geometry; - Scroller.Geometry = Geometry; - Scroller.ScrollBlock = ScrollBlock.None; - AllocatedSize = Geometry.Size; - _itemSize = new ESize(-1, -1); - - if (_adaptor != null && _layoutManager != null) - { - _layoutManager?.SizeAllocated(Geometry.Size); - - _layoutManager?.LayoutItems(ViewPort); - _layoutManager?.SetHeader(_headerView, Adaptor.MeasureHeader(AllocatedSize.Width, AllocatedSize.Height)); - _layoutManager?.SetFooter(_footerView, Adaptor.MeasureFooter(AllocatedSize.Width, AllocatedSize.Height)); - Scroller.ScrollBlock = LayoutManager.IsHorizontal ? ScrollBlock.Vertical : ScrollBlock.Horizontal; - Scroller.HorizontalStepSize = _layoutManager.GetScrollBlockSize(); - Scroller.VerticalStepSize = _layoutManager.GetScrollBlockSize(); - UpdateSnapPointsType(SnapPointsType); - Application.Current.Dispatcher.Dispatch(SendScrolledEvent); - } - } - - void RequestLayoutItems() - { - if (AllocatedSize.Width <= 0 || AllocatedSize.Height <= 0) - return; - - if (!_requestLayoutItems) - { - _requestLayoutItems = true; - Application.Current.Dispatcher.Dispatch(() => - { - _requestLayoutItems = false; - if (_adaptor != null && _layoutManager != null) - { - OnInnerLayout(); - _layoutManager?.LayoutItems(ViewPort, true); - } - }); - } - } - - void OnInnerLayout() - { - // OnInnerLayout was called when child item was added - // so, need to check scroll canvas size - var size = _layoutManager.GetScrollCanvasSize(); - _innerLayout.MinimumWidth = size.Width; - _innerLayout.MinimumHeight = size.Height; - } - - int _previousHorizontalOffset = 0; - int _previousVerticalOffset = 0; - - void OnScrollStarted(object sender, EventArgs e) - { - _isScrollAnimationStarted = true; - } - - void OnScrollStopped(object sender, EventArgs e) - { - SendScrolledEvent(); - _isScrollAnimationStarted = false; - } - - void OnScrolled(object sender, EventArgs e) - { - _layoutManager.LayoutItems(ViewPort); - if (!_isScrollAnimationStarted) - { - SendScrolledEvent(); - } - } - - void OnKeyDown(object sender, EvasKeyEventArgs e) - { - _allowFocusOnItem = true; - UpdateAllowFocusOnItem(_allowFocusOnItem); - } - - void OnDragStart(object sender, EventArgs e) - { - _allowFocusOnItem = false; - UpdateAllowFocusOnItem(_allowFocusOnItem); - } - - void SendScrolledEvent() - { - var args = new ItemsViewScrolledEventArgs(); - args.FirstVisibleItemIndex = _layoutManager.GetVisibleItemIndex(ViewPort.X, ViewPort.Y); - args.CenterItemIndex = _layoutManager.GetVisibleItemIndex(ViewPort.X + (ViewPort.Width / 2), ViewPort.Y + (ViewPort.Height / 2)); - args.LastVisibleItemIndex = _layoutManager.GetVisibleItemIndex(ViewPort.X + ViewPort.Width, ViewPort.Y + ViewPort.Height); - args.HorizontalOffset = ViewPort.X; - args.HorizontalDelta = ViewPort.X - _previousHorizontalOffset; - args.VerticalOffset = ViewPort.Y; - args.VerticalDelta = ViewPort.Y - _previousVerticalOffset; - - Scrolled?.Invoke(this, args); - - _previousHorizontalOffset = ViewPort.X; - _previousVerticalOffset = ViewPort.Y; - } - - void UpdateSnapPointsType(SnapPointsType snapPoints) - { - if (LayoutManager == null) - return; - - int itemSize = 0; - switch (snapPoints) - { - case SnapPointsType.None: - Scroller.HorizontalPageScrollLimit = 0; - Scroller.VerticalPageScrollLimit = 0; - itemSize = 0; - break; - case SnapPointsType.MandatorySingle: - Scroller.HorizontalPageScrollLimit = 1; - Scroller.VerticalPageScrollLimit = 1; - itemSize = LayoutManager.GetScrollBlockSize(); - break; - case SnapPointsType.Mandatory: - Scroller.HorizontalPageScrollLimit = 0; - Scroller.VerticalPageScrollLimit = 0; - itemSize = LayoutManager.GetScrollBlockSize(); - break; - } - - if (LayoutManager.IsHorizontal) - { - Scroller.SetPageSize(itemSize, 0); - } - else - { - Scroller.SetPageSize(0, itemSize); - } - } - - void CreateEmptyView() - { - _emptyView = Adaptor.CreateNativeView(this); - _emptyView.Show(); - Adaptor.SetBinding(_emptyView, 0); - _emptyView.Geometry = Geometry; - _emptyView.MinimumHeight = Geometry.Height; - _emptyView.MinimumWidth = Geometry.Width; - - Scroller.SetContent(_emptyView, true); - _innerLayout.Hide(); - } - - void RemoveEmptyView() - { - _innerLayout.Show(); - Scroller.SetContent(_innerLayout, true); - Adaptor.RemoveNativeView(_emptyView); - _emptyView = null; - } - - void UpdateAllowFocusOnItem(bool allowFocus) - { - foreach (var holer in _viewHolderIndexTable) - { - holer.Key.AllowItemFocus = allowFocus; - } - } - } - - public interface ICollectionViewController - { - EPoint ParentPosition { get; } - - ViewHolder RealizeView(int index); - - void UnrealizeView(ViewHolder view); - - void RequestLayoutItems(); - - int Count { get; } - - ESize GetItemSize(); - - ESize GetItemSize(int widthConstraint, int heightConstraint); - - ESize GetItemSize(int index, int widthConstraint, int heightConstraint); - - void ContentSizeUpdated(); - } - - public enum CollectionViewSelectionMode - { - None, - Single, - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/CollectionView/EmptyItemAdaptor.cs b/src/Compatibility/Core/src/Tizen/Native/CollectionView/EmptyItemAdaptor.cs deleted file mode 100644 index f194c7e3a678..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/CollectionView/EmptyItemAdaptor.cs +++ /dev/null @@ -1,103 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using ElmSharp; -using ESize = ElmSharp.Size; -using XLabel = Microsoft.Maui.Controls.Label; -using XStackLayout = Microsoft.Maui.Controls.StackLayout; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - [System.Obsolete] - public class EmptyItemAdaptor : ItemTemplateAdaptor, IEmptyAdaptor - { - static DataTemplate s_defaultEmptyTemplate = new DataTemplate(typeof(EmptyView)); - - StructuredItemsView _structuredItemsView; - public EmptyItemAdaptor(ItemsView itemsView, IEnumerable items, DataTemplate template) : base(itemsView, items, template) - { - _structuredItemsView = itemsView as StructuredItemsView; - } - - public static EmptyItemAdaptor Create(ItemsView itemsView) - { - DataTemplate template = null; - if (itemsView.EmptyView is View emptyView) - { - template = new DataTemplate(() => - { - return emptyView; - }); - } - else - { - template = itemsView.EmptyViewTemplate ?? s_defaultEmptyTemplate; - } - var empty = new List - { - itemsView.EmptyView ?? new object() - }; - return new EmptyItemAdaptor(itemsView, empty, template); - } - - public override ESize MeasureItem(int widthConstraint, int heightConstraint) - { - return new ESize(widthConstraint, heightConstraint); - } - - public override EvasObject CreateNativeView(int index, EvasObject parent) - { - View emptyView = null; - if (ItemTemplate is DataTemplateSelector selector) - { - emptyView = selector.SelectTemplate(this[index], Element).CreateContent() as View; - } - else - { - emptyView = ItemTemplate.CreateContent() as View; - } - - var header = CreateHeaderView(); - var footer = CreateFooterView(); - var layout = new XStackLayout(); - - if (header != null) - { - layout.Children.Add(header); - } - layout.Children.Add(emptyView); - if (footer != null) - { - layout.Children.Add(footer); - } - - layout.Parent = Element; - var renderer = Platform.GetOrCreateRenderer(layout); - (renderer as ILayoutRenderer)?.RegisterOnLayoutUpdated(); - return renderer.NativeView; - } - - public override void RemoveNativeView(EvasObject native) - { - native.Unrealize(); - } - - class EmptyView : XStackLayout - { - public EmptyView() - { - HorizontalOptions = LayoutOptions.Fill; - VerticalOptions = LayoutOptions.Fill; - Children.Add( - new XLabel - { - Text = "No items found", - VerticalOptions = LayoutOptions.Center, - HorizontalOptions = LayoutOptions.Center, - HorizontalTextAlignment = Maui.TextAlignment.Center, - VerticalTextAlignment = Maui.TextAlignment.Center, - } - ); - } - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/CollectionView/GridLayoutManager.cs b/src/Compatibility/Core/src/Tizen/Native/CollectionView/GridLayoutManager.cs deleted file mode 100644 index 595b532a4585..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/CollectionView/GridLayoutManager.cs +++ /dev/null @@ -1,708 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using ElmSharp; -using ERect = ElmSharp.Rect; -using ESize = ElmSharp.Size; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class GridLayoutManager : ICollectionViewLayoutManager - { - ESize _allocatedSize; - ESize _scrollCanvasSize; - bool _isLayouting; - ERect _last; - Dictionary _realizedItem = new Dictionary(); - - List _itemSizes; - List _cached; - List _accumulatedItemSizes; - bool _hasUnevenRows; - int _baseItemSize; - - ESize _headerSize; - EvasObject _header; - ESize _footerSize; - EvasObject _footer; - - - public GridLayoutManager(bool isHorizontal, int span = 1) : this(isHorizontal, span, ItemSizingStrategy.MeasureFirstItem) { } - - public GridLayoutManager(bool isHorizontal, int span, ItemSizingStrategy sizingStrategy) : this(isHorizontal, span, sizingStrategy, 0, 0) { } - - public GridLayoutManager(bool isHorizontal, int span, ItemSizingStrategy sizingStrategy, int verticalSpacing, int horizontalSpacing) - { - IsHorizontal = isHorizontal; - Span = span; - _hasUnevenRows = sizingStrategy == ItemSizingStrategy.MeasureAllItems; - VerticalItemSpacing = verticalSpacing; - HorizontalItemSpacing = horizontalSpacing; - } - - public int Span { get; private set; } - - public bool IsHorizontal { get; } - - public int VerticalItemSpacing { get; } - - public int HorizontalItemSpacing { get; } - - public ICollectionViewController CollectionView { get; set; } - - public void SizeAllocated(ESize size) - { - Reset(); - _allocatedSize = size; - InitializeMeasureCache(); - } - - public ESize GetScrollCanvasSize() - { - if (CollectionView.Count == 0 || _allocatedSize.Width <= 0 || _allocatedSize.Height <= 0) - return _allocatedSize; - - if (_scrollCanvasSize.Width > 0 && _scrollCanvasSize.Height > 0) - return _scrollCanvasSize; - - int totalItemSize = 0; - - if (_hasUnevenRows) - { - totalItemSize = _accumulatedItemSizes[_accumulatedItemSizes.Count - 1] + FooterSizeWithSpacing; - } - else - { - totalItemSize = (int)Math.Ceiling(CollectionView.Count / (double)Span) * (BaseItemSize + ItemSpacing) - ItemSpacing + ItemStartPoint + FooterSizeWithSpacing; - } - - if (IsHorizontal) - { - _scrollCanvasSize = new ESize(totalItemSize, _allocatedSize.Height); - } - else - { - _scrollCanvasSize = new ESize(_allocatedSize.Width, totalItemSize); - } - - return _scrollCanvasSize; - } - - public int GetScrollBlockSize() - { - return BaseItemSize + ItemSpacing; - } - - int BaseItemSize - { - get - { - if (_baseItemSize == 0) - { - if (_allocatedSize.Width <= 0 || _allocatedSize.Height <= 0) - return 0; - - var itembound = CollectionView.GetItemSize(ItemWidthConstraint, ItemHeightConstraint); - _baseItemSize = IsHorizontal ? itembound.Width : itembound.Height; - } - return _baseItemSize; - } - } - - int ItemSpacing => IsHorizontal ? HorizontalItemSpacing : VerticalItemSpacing; - - // It is a rule, if you want to fit with a content natural size, constraint should be infinity - int ItemWidthConstraint => IsHorizontal ? int.MaxValue : ColumnSize; - int ItemHeightConstraint => IsHorizontal ? ColumnSize : int.MaxValue; - - int ColumnSize - { - get - { - return (IsHorizontal ? _allocatedSize.Height / Span : _allocatedSize.Width / Span) - ((Span - 1) * ColumnSpacing / Span); - } - } - - int ColumnSpacing => IsHorizontal ? VerticalItemSpacing : HorizontalItemSpacing; - - int FooterSize => IsHorizontal ? _footerSize.Width : _footerSize.Height; - - int HeaderSize => IsHorizontal ? _headerSize.Width : _headerSize.Height; - - int ItemStartPoint - { - get - { - var startPoint = HeaderSize; - if (startPoint > 0) - { - startPoint += ItemSpacing; - } - return startPoint; - } - } - - int FooterSizeWithSpacing - { - get - { - var size = FooterSize; - if (size > 0) - { - size += ItemSpacing; - } - return size; - } - } - - bool ShouldRearrange(ERect viewport) - { - if (_isLayouting) - return false; - if (_last.Size != viewport.Size) - return true; - - var diff = IsHorizontal ? Math.Abs(_last.X - viewport.X) : Math.Abs(_last.Y - viewport.Y); - if (diff > BaseItemSize) - return true; - - return false; - } - - public void LayoutItems(ERect bound, bool force) - { - if (_allocatedSize.Width <= 0 || _allocatedSize.Height <= 0) - return; - - // TODO : need to optimization. it was frequently called with similar bound value. - if (!ShouldRearrange(bound) && !force) - { - return; - } - - _isLayouting = true; - _last = bound; - - int padding = Span; - int startIndex = Math.Max(GetStartIndex(bound) - padding, 0); - int endIndex = Math.Min(GetEndIndex(bound) + padding, CollectionView.Count - 1); - - foreach (var index in _realizedItem.Keys.ToList()) - { - if (index < startIndex || index > endIndex) - { - CollectionView.UnrealizeView(_realizedItem[index].View); - _realizedItem.Remove(index); - } - } - - var parent = CollectionView.ParentPosition; - for (int i = startIndex; i <= endIndex; i++) - { - EvasObject itemView = null; - if (!_realizedItem.ContainsKey(i)) - { - var view = CollectionView.RealizeView(i); - - _realizedItem[i] = new RealizedItem - { - View = view, - Index = i, - }; - itemView = view; - } - else - { - itemView = _realizedItem[i].View; - } - - var itemBound = GetItemBound(i); - itemBound.X += parent.X; - itemBound.Y += parent.Y; - itemView.Geometry = itemBound; - } - _isLayouting = false; - } - - public void UpdateSpan(int span) - { - Span = span; - InitializeMeasureCache(); - CollectionView.RequestLayoutItems(); - } - - public void ItemInserted(int inserted) - { - var items = _realizedItem.Keys.OrderByDescending(key => key); - foreach (var index in items) - { - if (index >= inserted) - { - _realizedItem[index + 1] = _realizedItem[index]; - } - } - if (_realizedItem.ContainsKey(inserted)) - { - _realizedItem.Remove(inserted); - } - else - { - var last = items.LastOrDefault(); - if (last >= inserted) - { - _realizedItem.Remove(last); - } - } - - UpdateInsertedSize(inserted); - - _scrollCanvasSize = new ESize(0, 0); - } - - public void ItemRemoved(int removed) - { - if (_realizedItem.ContainsKey(removed)) - { - CollectionView.UnrealizeView(_realizedItem[removed].View); - _realizedItem.Remove(removed); - } - - var items = _realizedItem.Keys.OrderBy(key => key); - foreach (var index in items) - { - if (index > removed) - { - _realizedItem[index - 1] = _realizedItem[index]; - } - } - - var last = items.LastOrDefault(); - if (last > removed) - { - _realizedItem.Remove(last); - } - - UpdateRemovedSize(removed); - _scrollCanvasSize = new ESize(0, 0); - } - - public void ItemUpdated(int index) - { - if (_realizedItem.ContainsKey(index)) - { - var bound = _realizedItem[index].View.Geometry; - CollectionView.UnrealizeView(_realizedItem[index].View); - var view = CollectionView.RealizeView(index); - _realizedItem[index].View = view; - view.Geometry = bound; - } - } - - public ERect GetItemBound(int index) - { - int rowIndex = index / Span; - int columnIndex = index % Span; - var columnSize = ColumnSize; - - int rowStartPoint = 0; - int columnStartPoint = 0; - int itemSize = 0; - - if (!_hasUnevenRows) - { - itemSize = BaseItemSize; - rowStartPoint = ItemStartPoint + rowIndex * (BaseItemSize + ItemSpacing); - columnStartPoint = columnIndex * (columnSize + ColumnSpacing); - } - else if (_cached[index]) - { - var updatedMaxItemSize = GetMaxItemSize(index); - itemSize = _itemSizes[index]; - rowStartPoint = _accumulatedItemSizes[rowIndex] - updatedMaxItemSize + (updatedMaxItemSize - itemSize) / 2; - columnStartPoint = columnIndex * (columnSize + ColumnSpacing); - } - else - { - var oldMaxItemSize = GetMaxItemSize(index); - - var measured = CollectionView.GetItemSize(index, ItemWidthConstraint, ItemHeightConstraint); - itemSize = IsHorizontal ? measured.Width : measured.Height; - - if (itemSize != _itemSizes[index]) - { - _itemSizes[index] = itemSize; - } - - var updatedMaxItemSize = GetMaxItemSize(index); - if (oldMaxItemSize != updatedMaxItemSize) - { - UpdateAccumulatedItemSize(rowIndex, updatedMaxItemSize - oldMaxItemSize); - int columnStart = (index / Span) * Span; - for (int toUpdate = columnStart; toUpdate < index; toUpdate++) - { - if (_realizedItem.ContainsKey(toUpdate)) - { - var updated = _realizedItem[toUpdate].View.Geometry; - if (IsHorizontal) - { - updated.X += (updatedMaxItemSize - oldMaxItemSize) / 2; - } - else - { - updated.Y += (updatedMaxItemSize - oldMaxItemSize) / 2; - } - _realizedItem[toUpdate].View.Geometry = updated; - } - } - CollectionView.ContentSizeUpdated(); - } - rowStartPoint = _accumulatedItemSizes[rowIndex] - updatedMaxItemSize + (updatedMaxItemSize - itemSize) / 2; - columnStartPoint = columnIndex * (columnSize + ColumnSpacing); - - _cached[index] = true; - } - - return IsHorizontal ? - new ERect(rowStartPoint, columnStartPoint, itemSize, columnSize) : - new ERect(columnStartPoint, rowStartPoint, columnSize, itemSize); - } - - public void Reset() - { - foreach (var realizedItem in _realizedItem.Values.ToList()) - { - CollectionView.UnrealizeView(realizedItem.View); - } - _realizedItem.Clear(); - _scrollCanvasSize = new ESize(0, 0); - } - - public void ItemSourceUpdated() - { - InitializeMeasureCache(); - } - - public void ItemMeasureInvalidated(int index) - { - if (_hasUnevenRows) - { - if (_cached.Count > index) - _cached[index] = false; - - if (_realizedItem.ContainsKey(index)) - { - CollectionView.RequestLayoutItems(); - } - } - else if (index == 0) // MeasureFirstItem - { - // Reset item size to measure updated size - InitializeMeasureCache(); - CollectionView.RequestLayoutItems(); - } - } - - public int GetVisibleItemIndex(int x, int y) - { - int index = 0; - if (x < 0 || y < 0 || _accumulatedItemSizes == null) - return index; - if (_scrollCanvasSize.Width < x || _scrollCanvasSize.Height < y) - return CollectionView.Count - 1; - - int first = 0; - if (!_hasUnevenRows) - { - first = Math.Min(Math.Max(0, ((IsHorizontal ? x : y) - ItemStartPoint) / (BaseItemSize + ItemSpacing)), ((CollectionView.Count - 1) / Span)); - } - else - { - first = _accumulatedItemSizes.FindIndex(current => (IsHorizontal ? x : y) <= current); - if (first == -1) - first = (CollectionView.Count - 1) / Span; - } - - int second = (IsHorizontal ? y : x) / (ColumnSize + ColumnSpacing); - if (second == Span) - second -= 1; - - index = (first * Span) + second; - - if (index < CollectionView.Count) - return index; - return CollectionView.Count - 1; - } - - public void SetHeader(EvasObject header, ESize size) - { - bool contentSizeChanged = false; - if (IsHorizontal) - { - if (_headerSize.Width != size.Width) - contentSizeChanged = true; - } - else - { - if (_headerSize.Height != size.Height) - contentSizeChanged = true; - } - - _header = header; - _headerSize = size; - - if (contentSizeChanged) - { - InitializeMeasureCache(); - CollectionView.ContentSizeUpdated(); - } - - var position = CollectionView.ParentPosition; - if (_header != null) - { - var bound = new ERect(position.X, position.Y, _headerSize.Width, _headerSize.Height); - if (IsHorizontal) - { - bound.Height = _allocatedSize.Height; - } - else - { - bound.Width = _allocatedSize.Width; - } - _header.Geometry = bound; - } - } - - public void SetFooter(EvasObject footer, ESize size) - { - bool contentSizeChanged = false; - if (IsHorizontal) - { - if (_footerSize.Width != size.Width) - contentSizeChanged = true; - } - else - { - if (_footerSize.Height != size.Height) - contentSizeChanged = true; - } - - _footer = footer; - _footerSize = size; - - if (contentSizeChanged) - { - InitializeMeasureCache(); - CollectionView.ContentSizeUpdated(); - } - - UpdateFooterPosition(); - } - - void UpdateFooterPosition() - { - if (_footer == null) - return; - - var position = CollectionView.ParentPosition; - if (IsHorizontal) - { - position.X += (GetScrollCanvasSize().Width - _footerSize.Width); - } - else - { - position.Y += (GetScrollCanvasSize().Height - _footerSize.Height); - } - - var bound = new ERect(position.X, position.Y, _footerSize.Width, _footerSize.Height); - if (IsHorizontal) - { - bound.Height = _allocatedSize.Height; - } - else - { - bound.Width = _allocatedSize.Width; - } - _footer.Geometry = bound; - } - - void InitializeMeasureCache() - { - _baseItemSize = 0; - _scrollCanvasSize = new ESize(0, 0); - _last = new ERect(0, 0, 0, 0); - - if (!_hasUnevenRows) - return; - - if (_allocatedSize.Width <= 0 || _allocatedSize.Height <= 0) - return; - - int n = CollectionView.Count; - _itemSizes = new List(); - _cached = new List(); - _accumulatedItemSizes = new List(); - - for (int i = 0; i < n; i++) - { - _cached.Add(false); - _itemSizes.Add(BaseItemSize); - if (i % Span == 0) - { - int accIndex = i / Span; - _accumulatedItemSizes.Add((accIndex > 0 ? (_accumulatedItemSizes[accIndex - 1] + ItemSpacing) : ItemStartPoint) + _itemSizes[i]); - } - } - } - - void BuildAccumulatedSize() - { - _accumulatedItemSizes = new List(); - int n = _itemSizes.Count; - for (int i = 0; i < n; i++) - { - int accIndex = i / Span; - int prevSize = accIndex > 0 ? (_accumulatedItemSizes[accIndex - 1] + ItemSpacing) : 0; - if (i % Span == 0) - { - _accumulatedItemSizes.Add(prevSize); - } - int columnMax = _accumulatedItemSizes[accIndex] - prevSize; - if (columnMax < _itemSizes[i]) - { - _accumulatedItemSizes[accIndex] += (_itemSizes[i] - columnMax); - } - } - } - - void UpdateInsertedSize(int inserted) - { - if (!_hasUnevenRows) - return; - - _cached.Insert(inserted, false); - _itemSizes.Insert(inserted, BaseItemSize); - BuildAccumulatedSize(); - } - - void UpdateRemovedSize(int removed) - { - if (!_hasUnevenRows) - return; - - _itemSizes.RemoveAt(removed); - _cached.RemoveAt(removed); - BuildAccumulatedSize(); - } - - void UpdateAccumulatedItemSize(int index, int diff) - { - for (int i = index; i < _accumulatedItemSizes.Count; i++) - { - _accumulatedItemSizes[i] += diff; - } - - if (_scrollCanvasSize.Width > 0 && _scrollCanvasSize.Height > 0) - { - if (IsHorizontal) - { - _scrollCanvasSize.Width += diff; - } - else - { - _scrollCanvasSize.Height += diff; - } - } - UpdateFooterPosition(); - } - - int GetMaxItemSize(int index) - { - int columnStart = (index / Span) * Span; - int columnEnd = columnStart + Span - 1; - int max = 0; - for (int i = columnStart; i <= columnEnd && i < _itemSizes.Count; i++) - { - max = Math.Max(max, _itemSizes[i]); - } - return max; - } - - int GetStartIndex(ERect bound, int itemSize) - { - return (ViewPortStartPoint(bound) - ItemStartPoint) / itemSize * Span; - } - - int GetStartIndex(ERect bound) - { - if (!_hasUnevenRows) - { - return GetStartIndex(bound, BaseItemSize + ItemSpacing); - } - - return FindFirstGreaterOrEqualTo(_accumulatedItemSizes, ViewPortStartPoint(bound)) * Span; - } - - int GetEndIndex(ERect bound, int itemSize) - { - return (int)Math.Ceiling(ViewPortEndPoint(bound) / (double)itemSize) * Span - 1; - } - - int GetEndIndex(ERect bound) - { - if (!_hasUnevenRows) - { - return GetEndIndex(bound, BaseItemSize + ItemSpacing); - } - var tmp = FindFirstGreaterOrEqualTo(_accumulatedItemSizes, ViewPortEndPoint(bound)); - - return (FindFirstGreaterOrEqualTo(_accumulatedItemSizes, ViewPortEndPoint(bound)) + 1) * Span - 1; - } - - int ViewPortStartPoint(ERect viewPort) - { - return IsHorizontal ? viewPort.X : viewPort.Y; - } - - int ViewPortEndPoint(ERect viewPort) - { - return ViewPortStartPoint(viewPort) + ViewPortSize(viewPort); - } - - int ViewPortSize(ERect viewPort) - { - return IsHorizontal ? viewPort.Width : viewPort.Height; - } - - static int FindFirstGreaterOrEqualTo(IList data, int value) - { - if (data.Count == 0) - return 0; - - int start = 0; - int end = data.Count - 1; - while (start < end) - { - int mid = (start + end) / 2; - if (data[mid] < value) - { - start = mid + 1; - } - else - { - end = mid - 1; - } - } - if (data[start] < value) - { - start++; - } - return start; - } - - class RealizedItem - { - public ViewHolder View { get; set; } - public int Index { get; set; } - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/CollectionView/ICollectionViewLayoutManager.cs b/src/Compatibility/Core/src/Tizen/Native/CollectionView/ICollectionViewLayoutManager.cs deleted file mode 100644 index 6a30aed26f38..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/CollectionView/ICollectionViewLayoutManager.cs +++ /dev/null @@ -1,41 +0,0 @@ -using ElmSharp; -using ERect = ElmSharp.Rect; -using ESize = ElmSharp.Size; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public interface ICollectionViewLayoutManager - { - ICollectionViewController CollectionView { get; set; } - - bool IsHorizontal { get; } - - void SizeAllocated(ESize size); - - ESize GetScrollCanvasSize(); - - void LayoutItems(ERect bound, bool force = false); - - ERect GetItemBound(int index); - - void ItemInserted(int index); - - void ItemRemoved(int index); - - void ItemUpdated(int index); - - void ItemSourceUpdated(); - - void Reset(); - - void ItemMeasureInvalidated(int index); - - int GetVisibleItemIndex(int x, int y); - - int GetScrollBlockSize(); - - void SetHeader(EvasObject header, ESize size); - - void SetFooter(EvasObject footer, ESize size); - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/CollectionView/IndicatorView.cs b/src/Compatibility/Core/src/Tizen/Native/CollectionView/IndicatorView.cs deleted file mode 100644 index 593c4a698454..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/CollectionView/IndicatorView.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.Maui.Devices; -using ElmSharp; -using Index = ElmSharp.Index; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class IndicatorView : Index - { - const int OddMiddleItem = 10; - const int EvenMiddleItem = 11; - List _list = new List(); - - public IndicatorView(EvasObject parent) : base(parent) - { - AutoHide = false; - IsHorizontal = true; - this.SetStyledIndex(); - } - - public event EventHandler SelectedPosition; - - public void UpdateSelectedIndex(int index) - { - if (index > -1 && index < _list.Count) - { - _list[index].Select(true); - } - } - - public void AppendIndex(int count = 1) - { - for (int i = 0; i < count; i++) - { - var item = Append(null); - item.Selected += OnSelected; - _list.Add(item); - } - if (DeviceInfo.Idiom == DeviceIdiom.Watch) - ApplyStyle(); - } - - public void ClearIndex() - { - foreach (var item in _list) - { - item.Selected -= OnSelected; - } - _list.Clear(); - Clear(); - } - - void ApplyStyle() - { - foreach (var item in _list) - { - item.SetIndexItemStyle(_list.Count, _list.IndexOf(item), EvenMiddleItem, OddMiddleItem); - } - } - - void OnSelected(object sender, EventArgs e) - { - var index = _list.IndexOf((IndexItem)sender); - SelectedPosition?.Invoke(this, new SelectedPositionChangedEventArgs(index)); - UpdateSelectedIndex(index); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/CollectionView/ItemAdaptor.cs b/src/Compatibility/Core/src/Tizen/Native/CollectionView/ItemAdaptor.cs deleted file mode 100644 index 2ced6753b575..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/CollectionView/ItemAdaptor.cs +++ /dev/null @@ -1,123 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.Specialized; -using ElmSharp; -using ESize = ElmSharp.Size; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public interface IEmptyAdaptor { } - - public abstract class ItemAdaptor : INotifyCollectionChanged - { - IList _itemsSource; - - public CollectionView CollectionView { get; set; } - - protected ItemAdaptor(IEnumerable items) - { - SetItemsSource(items); - } - - public event EventHandler ItemSelected; - - public virtual void SendItemSelected(int index) - { - ItemSelected?.Invoke(this, new SelectedItemChangedEventArgs(this[index], index)); - } - - public virtual void UpdateViewState(EvasObject view, ViewHolderState state) - { - } - - public void RequestItemSelected(object item) - { - if (CollectionView != null) - { - CollectionView.SelectedItemIndex = _itemsSource.IndexOf(item); - } - } - - protected void SetItemsSource(IEnumerable items) - { - switch (items) - { - case IList list: - _itemsSource = list; - _observableCollection = list as INotifyCollectionChanged; - break; - case IEnumerable generic: - _itemsSource = new List(generic); - break; - case IEnumerable _: - _itemsSource = new List(); - foreach (var item in items) - { - _itemsSource.Add(item); - } - break; - } - } - - public object this[int index] - { - get - { - return _itemsSource[index]; - } - } - - public int Count => _itemsSource.Count; - - INotifyCollectionChanged _observableCollection; - event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged - { - add - { - if (_observableCollection != null) - { - _observableCollection.CollectionChanged += value; - } - } - remove - { - if (_observableCollection != null) - { - _observableCollection.CollectionChanged -= value; - } - } - } - - public int GetItemIndex(object item) - { - return _itemsSource.IndexOf(item); - } - - public virtual object GetViewCategory(int index) - { - return this; - } - - public abstract EvasObject CreateNativeView(EvasObject parent); - - public abstract EvasObject CreateNativeView(int index, EvasObject parent); - - public abstract EvasObject GetHeaderView(EvasObject parent); - - public abstract EvasObject GetFooterView(EvasObject parent); - - public abstract void RemoveNativeView(EvasObject native); - - public abstract void SetBinding(EvasObject view, int index); - public abstract void UnBinding(EvasObject view); - - public abstract ESize MeasureItem(int widthConstraint, int heightConstraint); - - public abstract ESize MeasureItem(int index, int widthConstraint, int heightConstraint); - - public abstract ESize MeasureHeader(int widthConstraint, int heightConstraint); - - public abstract ESize MeasureFooter(int widthConstraint, int heightConstraint); - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/CollectionView/ItemTemplateAdaptor.cs b/src/Compatibility/Core/src/Tizen/Native/CollectionView/ItemTemplateAdaptor.cs deleted file mode 100644 index 20d73bbb5876..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/CollectionView/ItemTemplateAdaptor.cs +++ /dev/null @@ -1,341 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Globalization; -using ElmSharp; -using ESize = ElmSharp.Size; -using XLabel = Microsoft.Maui.Controls.Label; -using XColor = Microsoft.Maui.Graphics.Color; -using XStackLayout = Microsoft.Maui.Controls.StackLayout; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - [Obsolete] - public class ItemDefaultTemplateAdaptor : ItemTemplateAdaptor - { - class ToTextConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - return value?.ToString() ?? string.Empty; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); - } - - public ItemDefaultTemplateAdaptor(ItemsView itemsView) : base(itemsView) - { - ItemTemplate = new DataTemplate(() => - { - var label = new XLabel - { - TextColor = XColor.FromRgb(0, 0, 0), - }; - label.SetBinding(XLabel.TextProperty, new Binding(".", converter: new ToTextConverter())); - - return new XStackLayout - { - BackgroundColor = XColor.FromRgb(255, 255, 255), - Padding = 30, - Children = - { - label - } - }; - }); - } - } - - [Obsolete] - public class ItemTemplateAdaptor : ItemAdaptor - { - Dictionary _nativeFormsTable = new Dictionary(); - Dictionary _dataBindedViewTable = new Dictionary(); - protected View _headerCache; - protected View _footerCache; - - public ItemTemplateAdaptor(ItemsView itemsView) : this(itemsView, itemsView.ItemsSource, itemsView.ItemTemplate) { } - - protected ItemTemplateAdaptor(Element itemsView, IEnumerable items, DataTemplate template) : base(items) - { - ItemTemplate = template; - Element = itemsView; - IsSelectable = itemsView is SelectableItemsView; - } - - protected DataTemplate ItemTemplate { get; set; } - - protected Element Element { get; set; } - - protected virtual bool IsSelectable { get; } - - public View GetTemplatedView(EvasObject evasObject) - { - return _nativeFormsTable[evasObject]; - } - - public View GetTemplatedView(int index) - { - - if (Count > index && _dataBindedViewTable.TryGetValue(this[index], out View view)) - { - return view; - } - return null; - } - - public override object GetViewCategory(int index) - { - if (ItemTemplate is DataTemplateSelector selector) - { - return selector.SelectTemplate(this[index], Element); - } - return base.GetViewCategory(index); - } - - public override EvasObject CreateNativeView(int index, EvasObject parent) - { - View view = null; - if (ItemTemplate is DataTemplateSelector selector) - { - view = selector.SelectTemplate(this[index], Element).CreateContent() as View; - } - else - { - view = ItemTemplate.CreateContent() as View; - } - var renderer = Platform.GetOrCreateRenderer(view); - var native = renderer.NativeView; - - view.Parent = Element; - (renderer as ILayoutRenderer)?.RegisterOnLayoutUpdated(); - - _nativeFormsTable[native] = view; - return native; - } - - public override EvasObject CreateNativeView(EvasObject parent) - { - return CreateNativeView(0, parent); - } - - public override EvasObject GetHeaderView(EvasObject parent) - { - _headerCache = CreateHeaderView(); - if (_headerCache != null) - { - _headerCache.Parent = Element; - var renderer = Platform.GetOrCreateRenderer(_headerCache); - (renderer as ILayoutRenderer)?.RegisterOnLayoutUpdated(); - return renderer.NativeView; - } - return null; - } - - public override EvasObject GetFooterView(EvasObject parent) - { - _footerCache = CreateFooterView(); - if (_footerCache != null) - { - _footerCache.Parent = Element; - var renderer = Platform.GetOrCreateRenderer(_footerCache); - (renderer as ILayoutRenderer)?.RegisterOnLayoutUpdated(); - return renderer.NativeView; - } - return null; - } - - public override void RemoveNativeView(EvasObject native) - { - UnBinding(native); - if (_nativeFormsTable.TryGetValue(native, out View view)) - { - Platform.GetRenderer(view)?.Dispose(); - _nativeFormsTable.Remove(native); - } - } - - public override void SetBinding(EvasObject native, int index) - { - if (_nativeFormsTable.TryGetValue(native, out View view)) - { - ResetBindedView(view); - view.BindingContext = this[index]; - _dataBindedViewTable[this[index]] = view; - - view.MeasureInvalidated += OnItemMeasureInvalidated; - AddLogicalChild(view); - } - } - - public override void UnBinding(EvasObject native) - { - if (_nativeFormsTable.TryGetValue(native, out View view)) - { - view.MeasureInvalidated -= OnItemMeasureInvalidated; - ResetBindedView(view); - } - } - - public override ESize MeasureItem(int widthConstraint, int heightConstraint) - { - return MeasureItem(0, widthConstraint, heightConstraint); - } - - public override ESize MeasureItem(int index, int widthConstraint, int heightConstraint) - { - if (_dataBindedViewTable.TryGetValue(this[index], out View createdView) && createdView != null) - { - return createdView.Measure(Forms.ConvertToScaledDP(widthConstraint), Forms.ConvertToScaledDP(heightConstraint), MeasureFlags.IncludeMargins).Request.ToEFLPixel(); - } - - View view = null; - if (ItemTemplate is DataTemplateSelector selector) - { - view = selector.SelectTemplate(this[index], Element).CreateContent() as View; - } - else - { - view = ItemTemplate.CreateContent() as View; - } - using (var renderer = Platform.GetOrCreateRenderer(view)) - { - view.Parent = Element; - if (Count > index) - view.BindingContext = this[index]; - var request = view.Measure(Forms.ConvertToScaledDP(widthConstraint), Forms.ConvertToScaledDP(heightConstraint), MeasureFlags.IncludeMargins).Request; - return request.ToEFLPixel(); - } - } - - public override ESize MeasureHeader(int widthConstraint, int heightConstraint) - { - return _headerCache?.Measure(Forms.ConvertToScaledDP(widthConstraint), Forms.ConvertToScaledDP(heightConstraint)).Request.ToEFLPixel() ?? new ESize(0, 0); - } - - public override ESize MeasureFooter(int widthConstraint, int heightConstraint) - { - return _footerCache?.Measure(Forms.ConvertToScaledDP(widthConstraint), Forms.ConvertToScaledDP(heightConstraint)).Request.ToEFLPixel() ?? new ESize(0, 0); - } - - public override void UpdateViewState(EvasObject view, ViewHolderState state) - { - base.UpdateViewState(view, state); - if (_nativeFormsTable.TryGetValue(view, out View formsView)) - { - switch (state) - { - case ViewHolderState.Focused: - VisualStateManager.GoToState(formsView, VisualStateManager.CommonStates.Focused); - formsView.SetValue(VisualElement.IsFocusedPropertyKey, true); - break; - case ViewHolderState.Normal: - VisualStateManager.GoToState(formsView, VisualStateManager.CommonStates.Normal); - formsView.SetValue(VisualElement.IsFocusedPropertyKey, false); - break; - case ViewHolderState.Selected: - if (IsSelectable) - VisualStateManager.GoToState(formsView, VisualStateManager.CommonStates.Selected); - break; - } - } - } - - protected virtual View CreateHeaderView() - { - if (Element is StructuredItemsView structuredItemsView) - { - if (structuredItemsView.Header != null) - { - View header = null; - if (structuredItemsView.Header is View view) - { - header = view; - } - else if (structuredItemsView.HeaderTemplate != null) - { - header = structuredItemsView.HeaderTemplate.CreateContent() as View; - header.BindingContext = structuredItemsView.Header; - } - else if (structuredItemsView.Header is String str) - { - header = new XLabel { Text = str, }; - } - return header; - } - } - return null; - } - - protected virtual View CreateFooterView() - { - if (Element is StructuredItemsView structuredItemsView) - { - if (structuredItemsView.Footer != null) - { - View footer = null; - if (structuredItemsView.Footer is View view) - { - footer = view; - } - else if (structuredItemsView.FooterTemplate != null) - { - footer = structuredItemsView.FooterTemplate.CreateContent() as View; - footer.BindingContext = structuredItemsView.Footer; - } - else if (structuredItemsView.Footer is String str) - { - footer = new XLabel { Text = str, }; - } - return footer; - } - } - return null; - } - - void ResetBindedView(View view) - { - if (view.BindingContext != null && _dataBindedViewTable.ContainsKey(view.BindingContext)) - { - _dataBindedViewTable[view.BindingContext] = null; - RemoveLogicalChild(view); - view.BindingContext = null; - } - } - - void OnItemMeasureInvalidated(object sender, EventArgs e) - { - var data = (sender as View)?.BindingContext ?? null; - int index = GetItemIndex(data); - if (index != -1) - { - CollectionView?.ItemMeasureInvalidated(index); - } - } - - void AddLogicalChild(Element element) - { - if (Element is ItemsView iv) - { - iv.AddLogicalChild(element); - } - else - { - element.Parent = Element; - } - } - - void RemoveLogicalChild(Element element) - { - if (Element is ItemsView iv) - { - iv.RemoveLogicalChild(element); - } - else - { - element.Parent = null; - } - } - - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/CollectionView/LinearLayoutManager.cs b/src/Compatibility/Core/src/Tizen/Native/CollectionView/LinearLayoutManager.cs deleted file mode 100644 index d5e32d2b9bb4..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/CollectionView/LinearLayoutManager.cs +++ /dev/null @@ -1,610 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using ElmSharp; -using ERect = ElmSharp.Rect; -using ESize = ElmSharp.Size; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class LinearLayoutManager : ICollectionViewLayoutManager - { - ESize _allocatedSize; - bool _isLayouting; - ERect _last; - Dictionary _realizedItem = new Dictionary(); - List _itemSizes; - List _cached; - List _accumulatedItemSizes; - - bool _hasUnevenRows; - int _baseItemSize; - - ESize _headerSize; - EvasObject _header; - ESize _footerSize; - EvasObject _footer; - - public LinearLayoutManager(bool isHorizontal) : this(isHorizontal, ItemSizingStrategy.MeasureFirstItem) { } - - public LinearLayoutManager(bool isHorizontal, ItemSizingStrategy sizingStrategy) : this(isHorizontal, sizingStrategy, 0) { } - - public LinearLayoutManager(bool isHorizontal, ItemSizingStrategy sizingStrategy, int itemSpacing) - { - IsHorizontal = isHorizontal; - _hasUnevenRows = sizingStrategy == ItemSizingStrategy.MeasureAllItems; - ItemSpacing = itemSpacing; - } - - public bool IsHorizontal { get; } - - public int ItemSpacing { get; } - - public ICollectionViewController CollectionView { get; set; } - - public void SizeAllocated(ESize size) - { - _scrollCanvasSize = new ESize(0, 0); - _allocatedSize = size; - InitializeMeasureCache(); - } - - ESize _scrollCanvasSize; - - public ESize GetScrollCanvasSize() - { - if (CollectionView.Count == 0 || _allocatedSize.Width <= 0 || _allocatedSize.Height <= 0) - { - return _allocatedSize; - } - - if (_scrollCanvasSize.Width > 0 && _scrollCanvasSize.Height > 0) - return _scrollCanvasSize; - - int totalItemSize = 0; - - if (_hasUnevenRows) - { - totalItemSize = _accumulatedItemSizes[_accumulatedItemSizes.Count - 1] + FooterSizeWithSpacing; - } - else - { - totalItemSize = (BaseItemSize + ItemSpacing) * CollectionView.Count - ItemSpacing + ItemStartPoint + FooterSizeWithSpacing; - } - - if (IsHorizontal) - { - _scrollCanvasSize = new ESize(totalItemSize, _allocatedSize.Height); - } - else - { - _scrollCanvasSize = new ESize(_allocatedSize.Width, totalItemSize); - } - - return _scrollCanvasSize; - } - - int BaseItemSize - { - get - { - if (_baseItemSize == 0) - { - if (_allocatedSize.Width <= 0 || _allocatedSize.Height <= 0) - return 0; - - var itemBound = CollectionView.GetItemSize(ItemWidthConstraint, ItemHeightConstraint); - _baseItemSize = IsHorizontal ? itemBound.Width : itemBound.Height; - } - return _baseItemSize; - } - } - - // It is a rule, if you want to fit with a content natural size, constraint should be infinity - int ItemWidthConstraint => IsHorizontal ? int.MaxValue : _allocatedSize.Width; - int ItemHeightConstraint => IsHorizontal ? _allocatedSize.Height : int.MaxValue; - - int FooterSize => IsHorizontal ? _footerSize.Width : _footerSize.Height; - int HeaderSize => IsHorizontal ? _headerSize.Width : _headerSize.Height; - int ItemStartPoint - { - get - { - var startPoint = HeaderSize; - if (startPoint > 0) - { - startPoint += ItemSpacing; - } - return startPoint; - } - } - - int FooterSizeWithSpacing - { - get - { - var size = FooterSize; - if (size > 0) - { - size += ItemSpacing; - } - return size; - } - } - - bool ShouldRearrange(ERect viewport) - { - if (_isLayouting) - return false; - if (_last.Size != viewport.Size) - return true; - - var diff = IsHorizontal ? Math.Abs(_last.X - viewport.X) : Math.Abs(_last.Y - viewport.Y); - if (diff > BaseItemSize) - return true; - - return false; - } - - public void LayoutItems(ERect bound, bool force) - { - if (_allocatedSize.Width <= 0 || _allocatedSize.Height <= 0) - return; - - // TODO : need to optimization. it was frequently called with similar bound value. - if (!ShouldRearrange(bound) && !force) - { - return; - } - - _isLayouting = true; - _last = bound; - - int startIndex = Math.Max(GetStartIndex(bound) - 1, 0); - int endIndex = Math.Min(GetEndIndex(bound) + 1, CollectionView.Count - 1); - - foreach (var index in _realizedItem.Keys.ToList()) - { - if (index < startIndex || index > endIndex) - { - CollectionView.UnrealizeView(_realizedItem[index].View); - _realizedItem.Remove(index); - } - } - - var parent = CollectionView.ParentPosition; - for (int i = startIndex; i <= endIndex; i++) - { - EvasObject itemView = null; - if (!_realizedItem.ContainsKey(i)) - { - var view = CollectionView.RealizeView(i); - _realizedItem[i] = new RealizedItem - { - View = view, - Index = i, - }; - itemView = view; - } - else - { - itemView = _realizedItem[i].View; - } - var itemBound = GetItemBound(i); - itemBound.X += parent.X; - itemBound.Y += parent.Y; - itemView.Geometry = itemBound; - } - _isLayouting = false; - } - - public void ItemInserted(int inserted) - { - var items = _realizedItem.Keys.OrderByDescending(key => key); - foreach (var index in items) - { - if (index >= inserted) - { - _realizedItem[index + 1] = _realizedItem[index]; - } - } - if (_realizedItem.ContainsKey(inserted)) - { - _realizedItem.Remove(inserted); - } - else - { - var last = items.LastOrDefault(); - if (last >= inserted) - { - _realizedItem.Remove(last); - } - } - - UpdateInsertedSize(inserted); - - _scrollCanvasSize = new ESize(0, 0); - } - - public void ItemRemoved(int removed) - { - if (_realizedItem.ContainsKey(removed)) - { - CollectionView.UnrealizeView(_realizedItem[removed].View); - _realizedItem.Remove(removed); - } - - var items = _realizedItem.Keys.OrderBy(key => key); - foreach (var index in items) - { - if (index > removed) - { - _realizedItem[index - 1] = _realizedItem[index]; - } - } - - var last = items.LastOrDefault(); - if (last > removed) - { - _realizedItem.Remove(last); - } - - UpdateRemovedSize(removed); - - _scrollCanvasSize = new ESize(0, 0); - } - - public void ItemUpdated(int index) - { - if (_realizedItem.ContainsKey(index)) - { - var bound = _realizedItem[index].View.Geometry; - CollectionView.UnrealizeView(_realizedItem[index].View); - var view = CollectionView.RealizeView(index); - _realizedItem[index].View = view; - view.Geometry = bound; - } - } - - public ERect GetItemBound(int index) - { - int itemSize = 0; - int startPoint = 0; - - if (!_hasUnevenRows) - { - itemSize = BaseItemSize; - startPoint = ItemStartPoint + (itemSize + ItemSpacing) * index; - } - else if (index >= _itemSizes.Count) - { - return new ERect(0, 0, 0, 0); - } - else if (_cached[index]) - { - itemSize = _itemSizes[index]; - startPoint = _accumulatedItemSizes[index] - itemSize; - } - else - { - var measured = CollectionView.GetItemSize(index, ItemWidthConstraint, ItemHeightConstraint); - itemSize = IsHorizontal ? measured.Width : measured.Height; - - if (itemSize != _itemSizes[index]) - { - UpdateAccumulatedItemSize(index, itemSize - _itemSizes[index]); - _itemSizes[index] = itemSize; - - CollectionView.ContentSizeUpdated(); - } - startPoint = _accumulatedItemSizes[index] - itemSize; - _cached[index] = true; - } - - return IsHorizontal ? - new ERect(startPoint, 0, itemSize, _allocatedSize.Height) : - new ERect(0, startPoint, _allocatedSize.Width, itemSize); - } - - public void Reset() - { - foreach (var realizedItem in _realizedItem.Values.ToList()) - { - CollectionView.UnrealizeView(realizedItem.View); - } - _realizedItem.Clear(); - _scrollCanvasSize = new ESize(0, 0); - } - - public void ItemSourceUpdated() - { - InitializeMeasureCache(); - } - - public void ItemMeasureInvalidated(int index) - { - if (_hasUnevenRows) - { - if (_cached.Count > index) - _cached[index] = false; - - if (_realizedItem.ContainsKey(index)) - { - CollectionView.RequestLayoutItems(); - } - } - else if (index == 0) - { - // Reset item size to measure updated size - InitializeMeasureCache(); - CollectionView.RequestLayoutItems(); - } - } - - public int GetVisibleItemIndex(int x, int y) - { - int coordinate = IsHorizontal ? x : y; - int canvasSize = IsHorizontal ? _scrollCanvasSize.Width : _scrollCanvasSize.Height; - - if (coordinate < 0) - return 0; - if (canvasSize < coordinate) - return CollectionView.Count - 1; - - if (!_hasUnevenRows) - { - return Math.Min(Math.Max(0, (coordinate - ItemStartPoint) / (BaseItemSize + ItemSpacing)), CollectionView.Count - 1); - } - else - { - var index = _accumulatedItemSizes.FindIndex(current => coordinate <= current); - if (index == -1) - index = CollectionView.Count - 1; - return index; - } - } - - public int GetScrollBlockSize() - { - return BaseItemSize + ItemSpacing; - } - - public void SetHeader(EvasObject header, ESize size) - { - bool contentSizeChanged = false; - if (IsHorizontal) - { - if (_headerSize.Width != size.Width) - contentSizeChanged = true; - } - else - { - if (_headerSize.Height != size.Height) - contentSizeChanged = true; - } - - _header = header; - _headerSize = size; - - if (contentSizeChanged) - { - InitializeMeasureCache(); - CollectionView.ContentSizeUpdated(); - } - - var position = CollectionView.ParentPosition; - if (_header != null) - { - var bound = new ERect(position.X, position.Y, _headerSize.Width, _headerSize.Height); - if (IsHorizontal) - { - bound.Height = _allocatedSize.Height; - } - else - { - bound.Width = _allocatedSize.Width; - } - _header.Geometry = bound; - } - } - - public void SetFooter(EvasObject footer, ESize size) - { - bool contentSizeChanged = false; - if (IsHorizontal) - { - if (_footerSize.Width != size.Width) - contentSizeChanged = true; - } - else - { - if (_footerSize.Height != size.Height) - contentSizeChanged = true; - } - - _footer = footer; - _footerSize = size; - - if (contentSizeChanged) - { - InitializeMeasureCache(); - CollectionView.ContentSizeUpdated(); - } - - UpdateFooterPosition(); - } - - void UpdateFooterPosition() - { - if (_footer == null) - return; - - var position = CollectionView.ParentPosition; - if (IsHorizontal) - { - position.X += (GetScrollCanvasSize().Width - _footerSize.Width); - } - else - { - position.Y += (GetScrollCanvasSize().Height - _footerSize.Height); - } - - var bound = new ERect(position.X, position.Y, _footerSize.Width, _footerSize.Height); - if (IsHorizontal) - { - bound.Height = _allocatedSize.Height; - } - else - { - bound.Width = _allocatedSize.Width; - } - _footer.Geometry = bound; - } - - void InitializeMeasureCache() - { - _baseItemSize = 0; - _scrollCanvasSize = new ESize(0, 0); - - if (!_hasUnevenRows) - return; - - if (_allocatedSize.Width <= 0 || _allocatedSize.Height <= 0) - return; - - int n = CollectionView.Count; - _itemSizes = new List(); - _cached = new List(); - _accumulatedItemSizes = new List(); - - for (int i = 0; i < n; i++) - { - _cached.Add(false); - _itemSizes.Add(BaseItemSize); - _accumulatedItemSizes.Add((i > 0 ? (_accumulatedItemSizes[i - 1] + ItemSpacing) : ItemStartPoint) + _itemSizes[i]); - } - } - - int GetStartIndex(ERect bound, int itemSize) - { - return (ViewPortStartPoint(bound) - ItemStartPoint) / itemSize; - } - - int GetStartIndex(ERect bound) - { - if (!_hasUnevenRows) - { - return GetStartIndex(bound, BaseItemSize + ItemSpacing); - } - - return FindFirstGreaterOrEqualTo(_accumulatedItemSizes, ViewPortStartPoint(bound)); - } - - int GetEndIndex(ERect bound, int itemSize) - { - return (int)Math.Ceiling(ViewPortEndPoint(bound) / (double)itemSize) - 1; - } - - int GetEndIndex(ERect bound) - { - if (!_hasUnevenRows) - { - return GetEndIndex(bound, BaseItemSize + ItemSpacing); - } - - return FindFirstGreaterOrEqualTo(_accumulatedItemSizes, ViewPortEndPoint(bound)); - } - - int ViewPortStartPoint(ERect viewPort) - { - return IsHorizontal ? viewPort.X : viewPort.Y; - } - - int ViewPortEndPoint(ERect viewPort) - { - return ViewPortStartPoint(viewPort) + ViewPortSize(viewPort); - } - - int ViewPortSize(ERect viewPort) - { - return IsHorizontal ? viewPort.Width : viewPort.Height; - } - - void UpdateAccumulatedItemSize(int index, int diff) - { - for (int i = index; i < _accumulatedItemSizes.Count; i++) - { - _accumulatedItemSizes[i] += diff; - } - - if (_scrollCanvasSize.Width > 0 && _scrollCanvasSize.Height > 0) - { - - if (IsHorizontal) - { - _scrollCanvasSize.Width += diff; - } - else - { - _scrollCanvasSize.Height += diff; - } - } - UpdateFooterPosition(); - } - - void UpdateRemovedSize(int removed) - { - if (!_hasUnevenRows) - return; - var removedSize = _itemSizes[removed]; - _itemSizes.RemoveAt(removed); - UpdateAccumulatedItemSize(removed, -removedSize); - _accumulatedItemSizes.RemoveAt(removed); - _cached.RemoveAt(removed); - } - - void UpdateInsertedSize(int inserted) - { - if (!_hasUnevenRows) - return; - - _cached.Insert(inserted, false); - _itemSizes.Insert(inserted, BaseItemSize); - _accumulatedItemSizes.Insert(inserted, 0); - _accumulatedItemSizes[inserted] = inserted > 0 ? _accumulatedItemSizes[inserted - 1] : ItemStartPoint; - UpdateAccumulatedItemSize(inserted, BaseItemSize); - } - - static int FindFirstGreaterOrEqualTo(IList data, int value) - { - if (data.Count == 0) - return 0; - - int start = 0; - int end = data.Count - 1; - while (start < end) - { - int mid = (start + end) / 2; - if (data[mid] < value) - { - start = mid + 1; - } - else - { - end = mid - 1; - } - } - if (data[start] < value) - { - start++; - } - return start; - } - - class RealizedItem - { - public ViewHolder View { get; set; } - public int Index { get; set; } - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/CollectionView/RecyclerPool.cs b/src/Compatibility/Core/src/Tizen/Native/CollectionView/RecyclerPool.cs deleted file mode 100644 index 293170810e92..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/CollectionView/RecyclerPool.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - class RecyclerPool - { - LinkedList _pool = new LinkedList(); - - public void Clear(ItemAdaptor adaptor) - { - foreach (var item in _pool) - { - adaptor.RemoveNativeView(item); - } - _pool.Clear(); - } - - public void AddRecyclerView(ViewHolder view) - { - _pool.AddLast(view); - } - - public ViewHolder GetRecyclerView(object category) - { - var holder = _pool.Where(d => d.ViewCategory == category).FirstOrDefault(); - if (holder != null) - _pool.Remove(holder); - return holder; - } - - public ViewHolder GetRecyclerView() - { - if (_pool.First != null) - { - var fisrt = _pool.First; - _pool.RemoveFirst(); - return fisrt.Value; - } - return null; - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/CollectionView/ViewHolder.cs b/src/Compatibility/Core/src/Tizen/Native/CollectionView/ViewHolder.cs deleted file mode 100644 index b921bcb258ee..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/CollectionView/ViewHolder.cs +++ /dev/null @@ -1,175 +0,0 @@ -using System; -using ElmSharp; -using EColor = ElmSharp.Color; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - - public enum ViewHolderState - { - Normal, - Selected, - Focused, - } - - public class ViewHolder : Box - { - Button _focusArea; - EvasObject _content; - ViewHolderState _state; - bool _isSelected; - bool _isFocused; - bool _focusable; - - public ViewHolder(EvasObject parent) : base(parent) - { - Initialize(parent); - } - - public object ViewCategory { get; set; } - - [Obsolete("FocusedColor is obsolete. Use VisualStateManager")] - public EColor FocusedColor { get; set; } - - [Obsolete("SelectedColor is obsolete. Use VisualStateManager")] - public EColor SelectedColor { get; set; } - - public EvasObject Content - { - get - { - return _content; - } - set - { - if (_content != null) - { - UnPack(_content); - } - _content = value; - if (_content != null) - { - PackEnd(_content); - _content.StackBelow(_focusArea); - } - } - } - - public bool AllowItemFocus - { - get => _focusable; - set - { - _focusable = value; - if (!value && _focusArea.IsFocused) - { - _focusArea.SetFocus(false); - } - _focusArea.AllowFocus(_focusable); - } - } - - public ViewHolderState State - { - get { return _state; } - set - { - if (value == ViewHolderState.Normal) - _isSelected = false; - else if (value == ViewHolderState.Selected) - _isSelected = true; - - _state = _isFocused ? ViewHolderState.Focused : (_isSelected ? ViewHolderState.Selected : ViewHolderState.Normal); - - UpdateState(); - } - } - - public event EventHandler RequestSelected; - - public event EventHandler StateUpdated; - - public void ResetState() - { - State = ViewHolderState.Normal; - } - - protected void Initialize(EvasObject parent) - { - SetLayoutCallback(OnLayout); - - _focusArea = new Button(parent); - _focusArea.Color = EColor.Transparent; - _focusArea.BackgroundColor = EColor.Transparent; - _focusArea.SetEffectColor(EColor.Transparent); - _focusArea.Clicked += OnClicked; - _focusArea.Focused += OnFocused; - _focusArea.Unfocused += OnUnfocused; - _focusArea.KeyUp += OnKeyUp; - _focusArea.RepeatEvents = true; - _focusArea.Show(); - _focusArea.AllowFocus(_focusable); - - PackEnd(_focusArea); - Show(); - } - - protected virtual void OnFocused(object sender, EventArgs e) - { - UpdateFocusState(); - } - - protected virtual void OnUnfocused(object sender, EventArgs e) - { - UpdateFocusState(); - } - - protected virtual void OnClicked(object sender, EventArgs e) - { - RequestSelected?.Invoke(this, EventArgs.Empty); - } - - protected virtual void OnLayout() - { - _focusArea.Geometry = Geometry; - if (_content != null) - { - _content.Geometry = Geometry; - } - } - - protected virtual void UpdateState() - { - if (State == ViewHolderState.Selected) - _isSelected = true; - else if (State == ViewHolderState.Normal) - _isSelected = false; - else if (State == ViewHolderState.Focused) - RaiseTop(); - - StateUpdated?.Invoke(this, EventArgs.Empty); - } - - void UpdateFocusState() - { - if (_focusArea.IsFocused) - { - _isFocused = true; - State = ViewHolderState.Focused; - } - else - { - _isFocused = false; - State = _isSelected ? ViewHolderState.Selected : ViewHolderState.Normal; - } - } - - void OnKeyUp(object sender, EvasKeyEventArgs e) - { - if (e.KeyName == "Enter" && _focusArea.IsFocused) - { - RequestSelected?.Invoke(this, EventArgs.Empty); - } - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/DateChangedEventArgs.cs b/src/Compatibility/Core/src/Tizen/Native/DateChangedEventArgs.cs deleted file mode 100644 index 104a7fc16efa..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/DateChangedEventArgs.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// Event arguments for event. - /// - public class DateChangedEventArgs : EventArgs - { - /// - /// The date that the user entered. - /// - public DateTime NewDate { get; } - - /// - /// Creates a new object that represents a change to . - /// - /// Current date of . - public DateChangedEventArgs(DateTime newDate) - { - NewDate = newDate; - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/DateTimePicker.cs b/src/Compatibility/Core/src/Tizen/Native/DateTimePicker.cs deleted file mode 100644 index 96e003342dfd..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/DateTimePicker.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public enum DateTimePickerMode - { - Date, - Time - } - - public class DateTimePicker : DateTimeSelector - { - const string TimeFormat = "%d/%b/%Y %I:%M %p"; - const string TimeLayoutStyle = "time_layout"; - - const string DateFormat = "%d/%b/%Y"; - const string DateLayoutStyle = "date_layout"; - - DateTimePickerMode _mode = DateTimePickerMode.Date; - - public DateTimePicker(EvasObject parent) : base(parent) - { - UpdateMode(); - } - - protected DateTimePicker() : base() - { - } - - public DateTimePickerMode Mode - { - get { return _mode; } - set - { - if (_mode != value) - { - _mode = value; - UpdateMode(); - } - } - } - - protected virtual void UpdateMode() - { - if (Mode == DateTimePickerMode.Date) - { - Style = DateLayoutStyle; - Format = DateFormat; - } - else - { - Style = TimeLayoutStyle; - Format = TimeFormat; - } - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/DateTimePickerDialog.cs b/src/Compatibility/Core/src/Tizen/Native/DateTimePickerDialog.cs deleted file mode 100644 index 03234ecf48ae..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/DateTimePickerDialog.cs +++ /dev/null @@ -1,129 +0,0 @@ -using System; -using Microsoft.Maui.Devices; -using ElmSharp; -using EButton = ElmSharp.Button; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class DateTimePickerDialog : Dialog, IDateTimeDialog - { - EvasObject _parent; - DateTimePicker _picker; - - /// - /// Creates a dialog window. - /// - public DateTimePickerDialog(EvasObject parent) : base(parent) - { - _parent = parent; - Initialize(); - } - - /// - /// Gets or sets picker style - /// - public DateTimePickerMode Mode - { - get => _picker.Mode; - set => _picker.Mode = value; - } - - /// - /// Gets or sets the upper boundary of the DateTime field. - /// - public DateTime MaximumDateTime - { - get => _picker.MaximumDateTime; - set => _picker.MaximumDateTime = value; - } - - /// - /// Gets or sets the lower boundary of the DateTime field. - /// - public DateTime MinimumDateTime - { - get => _picker.MinimumDateTime; - set => _picker.MinimumDateTime = value; - } - - /// - /// Gets or sets the current value of the DateTime field. - /// - public DateTime DateTime - { - get => _picker.DateTime; - set => _picker.DateTime = value; - } - - /// - /// Occurs when the date of this dialog has changed. - /// - public event EventHandler DateTimeChanged; - - /// - /// Occurs when the picker dialog has opened. - /// - public event EventHandler PickerOpened; - - /// - /// Occurs when the picker dialog has closed. - /// - public event EventHandler PickerClosed; - - void Initialize() - { - _picker = new DateTimePicker(_parent); - _picker.Show(); - Content = _picker; - - //TODO need to add internationalization support - PositiveButton = new EButton(_parent) { Text = "Set" }; - PositiveButton.Clicked += (s, e) => - { - Confirm(); - }; - - //TODO need to add internationalization support - NegativeButton = new EButton(_parent) { Text = "Cancel" }; - NegativeButton.Clicked += (s, e) => - { - Hide(); - PickerClosed?.Invoke(this, EventArgs.Empty); - }; - BackButtonPressed += (object s, EventArgs e) => - { - Hide(); - PickerClosed?.Invoke(this, EventArgs.Empty); - }; - - ShowAnimationFinished += (object s, EventArgs e) => - { - PickerOpened?.Invoke(this, EventArgs.Empty); - }; - - // TODO This is Tizen TV Limitation. - // UX is defined and the focus move processing is complete, it should be removed(After Tizen 5.0) - if (DeviceInfo.Idiom == DeviceIdiom.TV) - { - KeyDown += (s, e) => - { - if (e.KeyName == "Return") - { - if (_picker != null && _picker.IsFocused) - { - Confirm(); - e.Flags |= EvasEventFlag.OnHold; - } - } - }; - } - } - - void Confirm() - { - DateTimeChanged?.Invoke(this, new DateChangedEventArgs(_picker.DateTime)); - Hide(); - PickerClosed?.Invoke(this, EventArgs.Empty); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/Dialog.cs b/src/Compatibility/Core/src/Tizen/Native/Dialog.cs deleted file mode 100644 index 10c4f292cf9c..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Dialog.cs +++ /dev/null @@ -1,311 +0,0 @@ -using System; -using Microsoft.Maui.Devices; -using ElmSharp; -using EButton = ElmSharp.Button; -using EColor = ElmSharp.Color; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - - /// - /// Enumerates the three valid positions of a dialog button. - /// - public enum ButtonPosition - { - Positive, - Neutral, - Negative - } - - /// - /// Base class for Dialogs. - /// A dialog is a small window that prompts the user to make a decision or enter additional information. - /// - public class Dialog : Popup - { - EButton _positiveButton; - EButton _neutralButton; - EButton _negativeButton; - EvasObject _content; - string _title; - string _message; - EColor _titleColor = EColor.Default; - - /// - /// Creates a dialog window. - /// - public static Dialog CreateDialog(EvasObject parent, bool hasAcceptButton = false) - { - if (DeviceInfo.Idiom == DeviceIdiom.Watch) - { - return new Watch.WatchDialog(Forms.NativeParent, hasAcceptButton); - } - else - { - return new Dialog(Forms.NativeParent); - } - } - - /// - /// Creates a dialog window that uses the default dialog theme. - /// - public Dialog(EvasObject parent) : base(parent) - { - Initialize(); - } - - /// - /// Occurs whenever the dialog is first displayed. - /// - public event EventHandler DialogShown; - - /// - /// Gets or sets the title of the dialog - /// - public string Title - { - get - { - return _title; - } - set - { - if (_title != value) - { - _title = value; - ApplyTitle(value); - } - } - } - - public EColor TitleColor - { - get - { - return _titleColor; - } - set - { - if (_titleColor != value) - { - _titleColor = value; - ApplyTitleColor(value); - } - } - } - - /// - /// Gets or sets the message to display in the dialog - /// - public string Message - { - get - { - return _message; - } - set - { - if (_message != value) - { - _message = value; - ApplyMessage(value); - } - } - } - - /// - /// Gets or sets the content to display in that dialog. - /// - public EvasObject Content - { - get - { - return _content; - } - set - { - if (_content != value) - { - _content = value; - ApplyContent(value); - } - } - } - - /// - /// Gets or sets the positive button used in the dialog - /// - public EButton PositiveButton - { - get - { - return _positiveButton; - } - set - { - if (_positiveButton != value) - { - _positiveButton = value; - ApplyButton(ButtonPosition.Positive, value); - } - } - } - - /// - /// Gets or sets the neutral button used in the dialog - /// - public EButton NeutralButton - { - get - { - return _neutralButton; - } - set - { - if (_neutralButton != value) - { - _neutralButton = value; - ApplyButton(ButtonPosition.Neutral, value); - } - } - } - - /// - /// Gets or sets the negative button used in the dialog - /// - public EButton NegativeButton - { - get - { - return _negativeButton; - } - set - { - if (_negativeButton != value) - { - _negativeButton = value; - ApplyButton(ButtonPosition.Negative, value); - } - } - } - - /// - /// Starts the dialog and displays it on screen. - /// - public new void Show() - { - base.Show(); - DialogShown?.Invoke(this, EventArgs.Empty); - } - - /// - /// Handles the disposing of a dialog widget. - /// - protected override void OnUnrealize() - { - _content?.Unrealize(); - _positiveButton?.Unrealize(); - _neutralButton?.Unrealize(); - _negativeButton?.Unrealize(); - ApplyButton(ButtonPosition.Positive, null); - ApplyButton(ButtonPosition.Neutral, null); - ApplyButton(ButtonPosition.Negative, null); - ApplyContent(null); - - base.OnUnrealize(); - } - - /// - /// Called when the dialog is shown. - /// - /// When shown, the dialog will register itself for the back key press event handling. - protected virtual void OnShown() - { - } - - /// - /// Called when the dialog is dismissed. - /// - /// When dismissed, the dialog will unregister itself from the back key press event handling. - protected virtual void OnDismissed() - { - } - - /// - /// Changes the dialog title. - /// - /// New dialog title. - protected virtual void ApplyTitle(string title) - { - this.SetTitleTextPart(title); - } - - protected virtual void ApplyTitleColor(EColor color) - { - this.SetTitleColor(color); - } - - /// - /// Puts the button in one of the three available slots. - /// - /// The slot to be occupied by the button expressed as a - /// The new button. - protected virtual void ApplyButton(ButtonPosition position, EButton button) - { - if (button != null) - { - button.SetPopupStyle(); - } - - switch (position) - { - case ButtonPosition.Positive: - this.SetButton3Part(button, true); - break; - - case ButtonPosition.Neutral: - this.SetButton2Part(button, true); - break; - - default: - this.SetButton1Part(button, true); - break; - } - } - - /// - /// Updates the content of the dialog. - /// - /// New dialog content. - protected virtual void ApplyContent(EvasObject content) - { - this.SetContentPart(content, true); - } - - protected virtual void ApplyMessage(string message) - { - base.Text = message; - } - - /// - /// Handles the initialization process. - /// - /// Creates handlers for vital events - void Initialize() - { - // Adds a handler for the Dismissed event. - // In effect, unregisters this instance from being affected by the hardware back key presses. - Dismissed += (s, e) => - { - OnDismissed(); - }; - - // Adds a handler for the Shown event. - // In effect, registers this instance to be affected by the hardware back key presses. - DialogShown += (s, e) => - { - OnShown(); - }; - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/EditfieldEntry.cs b/src/Compatibility/Core/src/Tizen/Native/EditfieldEntry.cs deleted file mode 100644 index b66ab8f5831c..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/EditfieldEntry.cs +++ /dev/null @@ -1,193 +0,0 @@ -using System; -using Microsoft.Maui.Devices; -using ElmSharp; -using EColor = ElmSharp.Color; -using ELayout = ElmSharp.Layout; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class EditfieldEntry : Native.Entry - { - Button _clearButton; - ELayout _editfieldLayout; - bool _enableClearButton; - int _heightPadding = 0; - - public EditfieldEntry(EvasObject parent) : base(parent) - { - } - - public EditfieldEntry(EvasObject parent, string style) : base(parent) - { - if (!string.IsNullOrEmpty(style) && _editfieldLayout is FormsLayout formsLayout) - formsLayout.SetTheme(formsLayout.ThemeClass, formsLayout.ThemeGroup, style); - } - - public bool IsTextBlockFocused { get; private set; } - - public override EColor BackgroundColor - { - get - { - return _editfieldLayout.BackgroundColor; - } - set - { - _editfieldLayout.BackgroundColor = value; - } - } - - public bool EnableClearButton - { - get => _enableClearButton; - set - { - _enableClearButton = value; - UpdateEnableClearButton(); - } - } - - public EColor ClearButtonColor - { - get => _clearButton.GetIconColor(); - set => _clearButton.SetIconColor(value); - } - - public void SetFocusOnTextBlock(bool isFocused) - { - SetFocus(isFocused); - IsTextBlockFocused = isFocused; - - if (isFocused) - OnTextBlockFocused(); - else - OnTextBlcokUnfocused(); - } - - public override ElmSharp.Size Measure(int availableWidth, int availableHeight) - { - var textBlockSize = base.Measure(availableWidth, availableHeight); - - // Calculate the minimum size by adding the width of a TextBlock and an Editfield. - textBlockSize.Width += _editfieldLayout.MinimumWidth; - - // If the height of a TextBlock is shorter than Editfield, use the minimun height of the Editfield. - // Or add the height of the EditField to the TextBlock - if (textBlockSize.Height < _editfieldLayout.MinimumHeight) - { - if (DeviceInfo.Idiom == DeviceIdiom.TV || DeviceInfo.Idiom == DeviceIdiom.Watch) - { - textBlockSize.Height = _editfieldLayout.MinimumHeight; - } - else - { - // Since the minimum height of EditFieldLayout too large, adjust it to an appropriate height. - var adjustedMinHeight = _editfieldLayout.MinimumHeight - (_editfieldLayout.MinimumHeight - _heightPadding) / 2; - textBlockSize.Height = textBlockSize.Height < adjustedMinHeight ? adjustedMinHeight : _editfieldLayout.MinimumHeight; - } - } - else - { - textBlockSize.Height += _heightPadding; - } - - return textBlockSize; - } - - protected override IntPtr CreateHandle(EvasObject parent) - { - var handle = base.CreateHandle(parent); - _editfieldLayout = CreateEditFieldLayout(parent); - - // If true, It means, there is no extra layout on the widget handle - // We need to set RealHandle, becuase we replace Handle to Layout - if (RealHandle == IntPtr.Zero) - { - RealHandle = handle; - } - Handle = handle; - - _editfieldLayout.SetContentPart(this); - _heightPadding = _editfieldLayout.GetContentPartEdjeObject().Geometry.Height; - return _editfieldLayout; - } - - protected override void OnTextChanged(string oldValue, string newValue) - { - base.OnTextChanged(oldValue, newValue); - if (EnableClearButton && _editfieldLayout is EditFieldEntryLayout layout) - { - layout.SendButtonActionSignal(!string.IsNullOrEmpty(newValue)); - } - } - - protected virtual ELayout CreateEditFieldLayout(EvasObject parent) - { - var layout = new EditFieldEntryLayout(parent, EditFieldEntryLayout.Styles.SingleLine); - layout.AllowFocus(true); - layout.Unfocused += (s, e) => - { - SetFocusOnTextBlock(false); - layout.SendFocusStateSignal(false); - OnEntryLayoutUnfocused(); - }; - layout.Focused += (s, e) => - { - layout.SendFocusStateSignal(true); - OnEntryLayoutFocused(); - }; - - layout.KeyDown += (s, e) => - { - if (e.KeyName == "Return") - { - if (!IsTextBlockFocused) - { - SetFocusOnTextBlock(true); - e.Flags |= EvasEventFlag.OnHold; - } - } - }; - Clicked += (s, e) => SetFocusOnTextBlock(true); - - Focused += (s, e) => - { - layout.RaiseTop(); - layout.SendFocusStateSignal(true); - }; - - Unfocused += (s, e) => - { - layout.SendFocusStateSignal(false); - }; - - return layout; - } - - protected virtual void UpdateEnableClearButton() - { - if (_editfieldLayout is EditFieldEntryLayout layout) - { - if (EnableClearButton) - { - _clearButton = (Button)new Button(_editfieldLayout).SetEditFieldClearStyle(); - _clearButton.AllowFocus(false); - _clearButton.Clicked += OnClearButtonClicked; - - layout.SetButtonPart(_clearButton); - layout.SendFocusStateSignal(true); - } - else - { - layout.SetButtonPart(null); - _clearButton = null; - } - } - } - - void OnClearButtonClicked(object sender, EventArgs e) - { - Text = string.Empty; - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Native/Entry.cs b/src/Compatibility/Core/src/Tizen/Native/Entry.cs deleted file mode 100644 index 20f336d71d88..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Entry.cs +++ /dev/null @@ -1,520 +0,0 @@ -using System; -using ElmSharp; -using EColor = ElmSharp.Color; -using EEntry = ElmSharp.Entry; -using ESize = ElmSharp.Size; - -#if __MATERIAL__ -using Tizen.NET.MaterialComponents; -#endif - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ -#if __MATERIAL__ - public class MaterialEntry : MTextField, IMeasurable, IBatchable, IEntry - { - const int TextFieldMinimumHeight = 115; - - public MaterialEntry(EvasObject parent) : base(parent) - { - Initialize(); - } - -#else - /// - /// Extends the Entry control, providing basic formatting features, - /// i.e. font color, size, placeholder. - /// - public class Entry : EEntry, IMeasurable, IBatchable, IEntry - { - /// - /// Initializes a new instance of the class. - /// - /// Parent evas object. - public Entry(EvasObject parent) : base(parent) - { - Initialize(); - } -#endif - - const int VariationNormal = 0; - const int VariationSignedAndDecimal = 3; - - /// - /// Holds the formatted text of the entry. - /// - readonly Span _span = new Span(); - - /// - /// Holds the formatted text of the placeholder. - /// - readonly Span _placeholderSpan = new Span(); - - /// - /// Helps to detect whether the text change was initiated by the user - /// or via the Text property. - /// - int _changedByUserCallbackDepth; - - /// - /// The type of the keyboard used by the entry. - /// - Keyboard _keyboard; - - /// - /// Occurs when the text has changed. - /// - public event EventHandler TextChanged; - - /// - /// Occurs when the text block get focused. - /// - public event EventHandler TextBlockFocused; - - /// - /// Occurs when the text block loses focus - /// - public event EventHandler TextBlockUnfocused; - - /// - /// Occurs when the layout of entry get focused. - /// - public event EventHandler EntryLayoutFocused; - - /// - /// Occurs when the layout of entry loses focus - /// - public event EventHandler EntryLayoutUnfocused; - - /// - /// Gets or sets the text. - /// - /// The text. - public override string Text - { - get - { - return _span.Text; - } - - set - { - - if (value != _span.Text) - { - var old = _span.Text; - _span.Text = value; - ApplyTextAndStyle(); - Application.Current.Dispatcher.DispatchDelayed(TimeSpan.FromTicks(1), () => OnTextChanged(old, value)); - } - } - } - - /// - /// Gets or sets the color of the text. - /// - /// The color of the text. -#if __MATERIAL__ - public new EColor TextColor -#else - public EColor TextColor -#endif - { - get - { - return _span.ForegroundColor; - } - - set - { - if (!_span.ForegroundColor.Equals(value)) - { - _span.ForegroundColor = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the font family of the text and the placeholder. - /// - /// The font family of the text and the placeholder. - public string FontFamily - { - get - { - return _span.FontFamily; - } - - set - { - if (value != _span.FontFamily) - { - _span.FontFamily = value; - ApplyTextAndStyle(); - - _placeholderSpan.FontFamily = value; - ApplyPlaceholderAndStyle(); - } - } - } - - /// - /// Gets or sets the font attributes of the text and the placeholder. - /// - /// The font attributes of the text and the placeholder. - public FontAttributes FontAttributes - { - get - { - return _span.FontAttributes; - } - - set - { - if (value != _span.FontAttributes) - { - _span.FontAttributes = value; - ApplyTextAndStyle(); - - _placeholderSpan.FontAttributes = value; - ApplyPlaceholderAndStyle(); - } - } - } - - - /// - /// Gets or sets the size of the font of both text and placeholder. - /// - /// The size of the font of both text and placeholder. - public double FontSize - { - get - { - return _span.FontSize; - } - - set - { - if (value != _span.FontSize) - { - _span.FontSize = value; - ApplyTextAndStyle(); - - _placeholderSpan.FontSize = value; - ApplyPlaceholderAndStyle(); - } - } - } - - /// - /// Gets or sets the font weight for the text. - /// - /// The weight of the font. - public string FontWeight - { - get - { - return _span.FontWeight; - } - - set - { - if (value != _span.FontWeight) - { - _span.FontWeight = value; - ApplyTextAndStyle(); - - _placeholderSpan.FontWeight = value; - ApplyPlaceholderAndStyle(); - } - } - } - - /// - /// Gets or sets the horizontal text alignment of both text and placeholder. - /// - /// The horizontal text alignment of both text and placeholder. - public TextAlignment HorizontalTextAlignment - { - get - { - return _span.HorizontalTextAlignment; - } - - set - { - if (value != _span.HorizontalTextAlignment) - { - _span.HorizontalTextAlignment = value; - ApplyTextAndStyle(); - - _placeholderSpan.HorizontalTextAlignment = value; - ApplyPlaceholderAndStyle(); - } - } - } - - /// - /// Gets or sets the keyboard type used by the entry. - /// - /// The keyboard type. - public Keyboard Keyboard - { - get - { - return _keyboard; - } - - set - { - if (value != _keyboard) - { - ApplyKeyboard(value); - } - } - } - - /// - /// Gets or sets the placeholder's text. - /// - /// The placeholder's text. - public string Placeholder - { - get - { - return _placeholderSpan.Text; - } - - set - { - if (value != _placeholderSpan.Text) - { - _placeholderSpan.Text = value; - ApplyPlaceholderAndStyle(); - } - } - } - - /// - /// Gets or sets the color of the placeholder's text. - /// - /// The color of the placeholder's text. - public EColor PlaceholderColor - { - get - { - return _placeholderSpan.ForegroundColor; - } - - set - { - if (!_placeholderSpan.ForegroundColor.Equals(value)) - { - _placeholderSpan.ForegroundColor = value; - ApplyPlaceholderAndStyle(); - } - } - } - - /// - /// Implementation of the IMeasurable.Measure() method. - /// - public virtual ESize Measure(int availableWidth, int availableHeight) - { - var originalSize = Geometry; - // resize the control using the whole available width - Resize(availableWidth, originalSize.Height); - - ESize rawSize; - ESize formattedSize; - - // if there's no text, but there's a placeholder, use it for measurements - if (string.IsNullOrEmpty(Text) && !string.IsNullOrEmpty(Placeholder)) - { - rawSize = this.GetPlaceHolderTextBlockNativeSize(); - formattedSize = this.GetPlaceHolderTextBlockFormattedSize(); - } - else - { - // there's text in the entry, use it instead - rawSize = this.GetTextBlockNativeSize(); - formattedSize = this.GetTextBlockFormattedSize(); - } - - // restore the original size - Resize(originalSize.Width, originalSize.Height); - - // Set bottom padding for lower case letters that have segments below the bottom line of text (g, j, p, q, y). - var verticalPadding = (int)Math.Ceiling(0.05 * FontSize); - var horizontalPadding = (int)Math.Ceiling(0.2 * FontSize); - rawSize.Height += verticalPadding; - formattedSize.Height += verticalPadding; - formattedSize.Width += horizontalPadding; - - ESize size; - - // if the raw text width is larger than available width, we use the available width, - // while height is set to the smallest height value - if (rawSize.Width > availableWidth) - { - size.Width = availableWidth; - size.Height = Math.Min(formattedSize.Height, Math.Max(rawSize.Height, availableHeight)); - } - else - { - // width is fine, return the formatted text size - size = formattedSize; - } - -#if __MATERIAL__ - // for adapting material style, - // the height of the entry should be bigger than minimun size defined by Tizen.NET.Material.Components - if (size.Height < TextFieldMinimumHeight) - { - size.Height = TextFieldMinimumHeight; - } -#endif - return size; - - } - - protected virtual void OnTextBlockFocused() - { - TextBlockFocused?.Invoke(this, EventArgs.Empty); - } - - protected virtual void OnTextBlcokUnfocused() - { - TextBlockUnfocused?.Invoke(this, EventArgs.Empty); - } - - protected virtual void OnEntryLayoutFocused() - { - EntryLayoutFocused?.Invoke(this, EventArgs.Empty); - } - - protected virtual void OnEntryLayoutUnfocused() - { - EntryLayoutUnfocused?.Invoke(this, EventArgs.Empty); - } - - protected virtual void OnTextChanged(string oldValue, string newValue) - { - TextChanged?.Invoke(this, new TextChangedEventArgs(oldValue, newValue)); - } - - void Initialize() - { - Scrollable = true; - - ChangedByUser += (s, e) => - { - _changedByUserCallbackDepth++; - - Text = GetInternalText(); - - _changedByUserCallbackDepth--; - }; - - ApplyKeyboard(Keyboard.Normal); - } - - void IBatchable.OnBatchCommitted() - { - ApplyTextAndStyle(); - } - - /// - /// Applies entry's text and its style. - /// - void ApplyTextAndStyle() - { - if (!this.IsBatched()) - { - SetInternalTextAndStyle(_span.GetDecoratedText(), _span.GetStyle()); - } - } - - /// - /// Sets entry's internal text and its style. - /// - /// Formatted text, supports HTML tags. - /// Style applied to the formattedText. - void SetInternalTextAndStyle(string formattedText, string textStyle) - { - if (_changedByUserCallbackDepth == 0) - { - base.Text = formattedText; - base.TextStyle = textStyle; - } - } - - /// - /// Gets the internal text representation of the entry. - /// - /// The internal text representation. - string GetInternalText() - { - return EEntry.ConvertMarkupToUtf8(base.Text); - } - - /// - /// Applies the keyboard type to be used by the entry. - /// - /// Keyboard type to be used. - void ApplyKeyboard(Keyboard keyboard) - { - _keyboard = keyboard; - SetInternalKeyboard(keyboard); - } - - /// - /// Configures the ElmSharp.Entry with specified keyboard type and displays - /// the keyboard automatically unless the provided type is Keyboard.None. - /// - /// Keyboard type to be used. - void SetInternalKeyboard(Keyboard keyboard) - { - if (keyboard == Keyboard.None) - { - SetInputPanelEnabled(false); - } - else if (Keyboard == Keyboard.Numeric) - { - SetInputPanelEnabled(true); - SetInputPanelLayout(InputPanelLayout.NumberOnly); - // InputPanelVariation is used to allow using deciaml point. - InputPanelVariation = VariationSignedAndDecimal; - } - else - { - SetInputPanelEnabled(true); - SetInputPanelLayout((InputPanelLayout)keyboard); - InputPanelVariation = VariationNormal; - } - } - - /// - /// Applies placeholders's text and its style. - /// - void ApplyPlaceholderAndStyle() - { - SetInternalPlaceholderAndStyle(_placeholderSpan.GetMarkupText()); - } - - /// - /// Sets placeholder's internal text and style. - /// - /// Markup text to be used as a placeholder. - protected virtual void SetInternalPlaceholderAndStyle(string markupText) - { -#if __MATERIAL__ - base.Label = markupText; -#else - this.SetPlaceHolderTextPart(markupText ?? ""); -#endif - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/EvasBox.cs b/src/Compatibility/Core/src/Tizen/Native/EvasBox.cs deleted file mode 100644 index a183c669d29b..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/EvasBox.cs +++ /dev/null @@ -1,131 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using ElmSharp; -using EColor = ElmSharp.Color; -using ERectangle = ElmSharp.Rectangle; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class EvasBox : Container - { - Interop.CanvasBoxLayoutCallback _layoutCallback; - Lazy _rectangle; - - public event EventHandler LayoutUpdated; - - public EvasBox(EvasObject parent) : base(parent) - { - _rectangle = new Lazy(() => - { - var rectangle = new ERectangle(this) { AlignmentX = -1, AlignmentY = -1, WeightX = 1, WeightY = 1 }; - Interop.evas_object_box_insert_at(Handle, rectangle, 0); - rectangle.Lower(); - rectangle.Show(); - return rectangle; - }); - - SetLayoutCallback(() => { NotifyOnLayout(); }); - } - - public override EColor BackgroundColor - { - get - { - return _rectangle.Value.Color; - } - set - { - _rectangle.Value.Color = value.IsDefault ? EColor.Transparent : value; - } - } - - public void PackEnd(EvasObject content) - { - Interop.evas_object_box_append(Handle, content); - AddChild(content); - } - - public bool UnPack(EvasObject content) - { - var ret = Interop.evas_object_box_remove(Handle, content); - if (ret) - RemoveChild(content); - return ret; - } - - public bool UnPackAll() - { - var ret = Interop.evas_object_box_remove_all(Handle, true); - if (ret) - { - ClearChildren(); - if (_rectangle.IsValueCreated) - { - Interop.evas_object_box_append(Handle, _rectangle.Value); - } - } - return ret; - } - - public void SetLayoutCallback(Action action) - { - _layoutCallback = (obj, priv, data) => - { - if (_rectangle.IsValueCreated) - { - _rectangle.Value.Geometry = Geometry; - } - action(); - }; - Interop.evas_object_box_layout_set(Handle, _layoutCallback, IntPtr.Zero, null); - } - - protected override IntPtr CreateHandle(EvasObject parent) - { - return Interop.evas_object_box_add(Interop.evas_object_evas_get(parent.Handle)); - } - - void NotifyOnLayout() - { - if (null != LayoutUpdated) - { - LayoutUpdated(this, new LayoutEventArgs() { Geometry = Geometry }); - } - } - - class Interop - { - public const string LibEvas = "libevas.so.1"; - - public delegate void CanvasBoxLayoutCallback(IntPtr obj, IntPtr priv, IntPtr userData); - - public delegate void CanvasBoxDataFreeCallback(IntPtr data); - - [DllImport(LibEvas)] - internal static extern IntPtr evas_object_box_add(IntPtr evas); - - [DllImport(LibEvas)] - internal static extern IntPtr evas_object_evas_get(IntPtr obj); - - [DllImport(LibEvas)] - internal static extern void evas_object_box_append(IntPtr obj, IntPtr child); - - [DllImport(LibEvas)] - internal static extern void evas_object_box_insert_at(IntPtr obj, IntPtr child, int pos); - - [DllImport(LibEvas)] - [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool evas_object_box_remove(IntPtr obj, IntPtr child); - - [DllImport(LibEvas)] - [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool evas_object_box_remove_all(IntPtr obj, bool clear); - - [DllImport(LibEvas)] - internal static extern void evas_object_box_layout_set(IntPtr obj, CanvasBoxLayoutCallback cb, IntPtr data, CanvasBoxDataFreeCallback dataFreeCb); - - [DllImport(LibEvas)] - internal static extern void evas_object_box_layout_set(IntPtr obj, CanvasBoxLayoutCallback cb, IntPtr data, IntPtr dataFreeCb); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/EvasFormsCanvas.cs b/src/Compatibility/Core/src/Tizen/Native/EvasFormsCanvas.cs deleted file mode 100644 index aaafc6347e16..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/EvasFormsCanvas.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System.Collections.Generic; -using System.Collections.Specialized; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class EvasFormsCanvas : EvasBox, IContainable - { - public EvasFormsCanvas(EvasObject parent) : base(parent) - { - Initilize(); - } - - readonly ObservableCollection _children = new ObservableCollection(); - - public new IList Children - { - get - { - return _children; - } - } - - protected override void OnUnrealize() - { - foreach (var child in _children) - { - child.Unrealize(); - } - - base.OnUnrealize(); - } - - void Initilize() - { - _children.CollectionChanged += (o, e) => - { - if (e.Action == NotifyCollectionChangedAction.Add) - { - foreach (var v in e.NewItems) - { - var view = v as EvasObject; - if (null != view) - { - OnAdd(view); - } - } - } - else if (e.Action == NotifyCollectionChangedAction.Remove) - { - foreach (var v in e.OldItems) - { - var view = v as EvasObject; - if (null != view) - { - OnRemove(view); - } - } - } - else if (e.Action == NotifyCollectionChangedAction.Reset) - { - OnRemoveAll(); - } - }; - } - - void OnAdd(EvasObject view) - { - PackEnd(view); - } - - void OnRemove(EvasObject view) - { - UnPack(view); - } - - void OnRemoveAll() - { - UnPackAll(); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/FlyoutPage.cs b/src/Compatibility/Core/src/Tizen/Native/FlyoutPage.cs deleted file mode 100644 index 7f8a732d76a1..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/FlyoutPage.cs +++ /dev/null @@ -1,505 +0,0 @@ -using System; -using ElmSharp; -using Microsoft.Maui.Devices; -using Microsoft.Maui.Controls.Internals; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// The native widget which provides Xamarin.FlyoutPage features. - /// - public class FlyoutPage : Box - { - /// - /// The default flyout layout behavior (a.k.a mode). - /// - static readonly FlyoutLayoutBehavior s_defaultFlyoutLayoutBehavior = (DeviceInfo.Idiom == DeviceIdiom.Phone || DeviceInfo.Idiom == DeviceIdiom.Watch) ? FlyoutLayoutBehavior.Popover : FlyoutLayoutBehavior.SplitOnLandscape; - - /// - /// The Flyout native container. - /// - readonly Canvas _flyoutCanvas; - - /// - /// The Detail native container. - /// - readonly Canvas _detailCanvas; - - /// - /// The container for _flyoutCanvas and _detailCanvas used in split mode. - /// - readonly Panes _splitPane; - - /// - /// The container for _flyoutCanvas used in popover mode. - /// - readonly Panel _drawer; - - /// - /// The property value. - /// - FlyoutLayoutBehavior _flyoutLayoutBehavior = s_defaultFlyoutLayoutBehavior; - - /// - /// The actual FlyoutPage mode - either split or popover. It depends on _flyoutLayoutBehavior and screen orientation. - /// - FlyoutLayoutBehavior _internalFlyoutLayoutBehavior = FlyoutLayoutBehavior.Popover; - - /// - /// The property value. - /// - EvasObject _flyout; - - /// - /// The property value. - /// - EvasObject _detail; - - /// - /// The main widget - either or , depending on the mode. - /// - EvasObject _mainWidget; - - /// - /// The property value. - /// - bool _isGestureEnabled = true; - - /// - /// The portion of the screen that the Flyout takes in Split mode. - /// - double _splitRatio = 0.35; - - /// - /// The portion of the screen that the Flyout takes in Popover mode. - /// - double _popoverRatio = 0.8; - - /// - /// Initializes a new instance of the class. - /// - /// Parent evas object. - public FlyoutPage(EvasObject parent) : base(parent) - { - LayoutUpdated += (s, e) => - { - UpdateChildCanvasGeometry(); - }; - - // create the controls which will hold the flyout and detail pages - _flyoutCanvas = new Canvas(this); - _flyoutCanvas.SetAlignment(-1.0, -1.0); // fill - _flyoutCanvas.SetWeight(1.0, 1.0); // expand - _flyoutCanvas.LayoutUpdated += (sender, e) => - { - UpdatePageGeometry(_flyout); - }; - - _detailCanvas = new Canvas(this); - _detailCanvas.SetAlignment(-1.0, -1.0); // fill - _detailCanvas.SetWeight(1.0, 1.0); // expand - _detailCanvas.LayoutUpdated += (sender, e) => - { - UpdatePageGeometry(_detail); - }; - - _splitPane = new Panes(this) - { - AlignmentX = -1, - AlignmentY = -1, - WeightX = 1, - WeightY = 1, - IsFixed = true, - IsHorizontal = false, - Proportion = _splitRatio, - }; - - _drawer = new Panel(Forms.NativeParent); - _drawer.SetScrollable(_isGestureEnabled); - _drawer.SetScrollableArea(1.0); - _drawer.Direction = PanelDirection.Left; - _drawer.Toggled += (object sender, EventArgs e) => - { - UpdateFocusPolicy(); - IsPresentedChanged?.Invoke(this, new IsPresentedChangedEventArgs(_drawer.IsOpen)); - }; - - ConfigureLayout(); - - // in case of the screen rotation we may need to update the choice between split - // and popover behaviors and reconfigure the layout - DeviceDisplay.MainDisplayInfoChanged += (s, e) => - { - UpdateFlyoutLayoutBehavior(); - }; - } - - /// - /// Occurs when the Flyout is shown or hidden. - /// - public event EventHandler IsPresentedChanged; - - /// - /// Occurs when the IsPresentChangeable was changed. - /// - public event EventHandler UpdateIsPresentChangeable; - - /// - /// Gets or sets the FlyoutPage behavior. - /// - /// The behavior of the FlyoutPage requested by the user. - public FlyoutLayoutBehavior FlyoutLayoutBehavior - { - get - { - return _flyoutLayoutBehavior; - } - - set - { - _flyoutLayoutBehavior = value; - UpdateFlyoutLayoutBehavior(); - } - } - - /// - /// Gets the FlyoutPage was splited - /// - public bool IsSplit => _internalFlyoutLayoutBehavior == FlyoutLayoutBehavior.Split; - - /// - /// Gets or sets the content of the Flyout. - /// - /// The Flyout. - public EvasObject Flyout - { - get - { - return _flyout; - } - - set - { - if (_flyout != value) - { - _flyout = value; - UpdatePageGeometry(_flyout); - _flyoutCanvas.Children.Clear(); - _flyoutCanvas.Children.Add(_flyout); - if (!IsSplit) - UpdateFocusPolicy(); - } - } - } - - /// - /// Gets or sets the content of the DetailPage. - /// - /// The DetailPage. - public EvasObject Detail - { - get - { - return _detail; - } - - set - { - if (_detail != value) - { - _detail = value; - UpdatePageGeometry(_detail); - _detailCanvas.Children.Clear(); - _detailCanvas.Children.Add(_detail); - if (!IsSplit) - UpdateFocusPolicy(); - } - } - } - - /// - /// Gets or sets a value indicating whether the Flyout is shown. - /// - /// true if the Flyout is presented. - public bool IsPresented - { - get - { - return _drawer.IsOpen; - } - - set - { - if (_drawer.IsOpen != value) - { - _drawer.IsOpen = value; - } - } - } - - /// - /// Gets or sets a value indicating whether a FlyoutPage allows showing FlyoutPage with swipe gesture. - /// - /// true if the FlyoutPage can be revealed with a gesture. - public bool IsGestureEnabled - { - get - { - return _isGestureEnabled; - } - - set - { - if (_isGestureEnabled != value) - { - _isGestureEnabled = value; - // Fixme - // Elementary panel was not support to change scrollable property on runtime - // Please uncomment when EFL was updated - //_drawer.SetScrollable(_isGestureEnabled); - } - } - } - - /// - /// Gets or Sets the portion of the screen that the FlyoutPage takes in split mode. - /// - /// The portion. - public double SplitRatio - { - get - { - return _splitRatio; - } - set - { - if (_splitRatio != value) - { - _splitRatio = value; - _splitPane.Proportion = _splitRatio; - } - } - - } - - /// - /// Gets or sets the portion of the screen that the FlyoutPage takes in Popover mode. - /// - /// The portion. - public double PopoverRatio - { - get - { - return _popoverRatio; - } - set - { - if (_popoverRatio != value) - { - _popoverRatio = value; - UpdateChildCanvasGeometry(); - } - } - } - - /// - /// Provides destruction for native element and contained elements. - /// - protected override void OnUnrealize() - { - // Views that are not belong to view tree should be unrealized. - if (IsSplit) - { - _drawer.Unrealize(); - } - else - { - _splitPane.Unrealize(); - } - base.OnUnrealize(); - } - - /// - /// Updates the geometry of the selected page. - /// - /// Flyout or Detail page to be updated. - void UpdatePageGeometry(EvasObject page) - { - if (page != null) - { - if (_flyout == page) - { - // update the geometry of the flyout page - page.Geometry = _flyoutCanvas.Geometry; - } - else if (_detail == page) - { - // update the geometry of the detail page - page.Geometry = _detailCanvas.Geometry; - } - } - } - - /// - /// Updates according to set by the user and current screen orientation. - /// - void UpdateFlyoutLayoutBehavior() - { - var behavior = (_flyoutLayoutBehavior == FlyoutLayoutBehavior.Default) ? s_defaultFlyoutLayoutBehavior : _flyoutLayoutBehavior; - - // Screen orientation affects those 2 behaviors - if (behavior == FlyoutLayoutBehavior.SplitOnLandscape || behavior == FlyoutLayoutBehavior.SplitOnPortrait) - { - var orientation = DeviceDisplay.MainDisplayInfo.Orientation; - - if ((orientation.IsLandscape() && behavior == FlyoutLayoutBehavior.SplitOnLandscape) || (orientation.IsPortrait() && behavior == FlyoutLayoutBehavior.SplitOnPortrait)) - { - behavior = FlyoutLayoutBehavior.Split; - } - else - { - behavior = FlyoutLayoutBehavior.Popover; - } - } - - if (behavior != _internalFlyoutLayoutBehavior) - { - _internalFlyoutLayoutBehavior = behavior; - ConfigureLayout(); - } - } - - /// - /// Composes the structure of all the necessary widgets. - /// - void ConfigureLayout() - { - _drawer.SetContent(null, true); - _drawer.Hide(); - - _splitPane.SetLeftPart(null, true); - _splitPane.SetRightPart(null, true); - _splitPane.Hide(); - - UnPackAll(); - - // the structure for split mode and for popover mode looks differently - if (IsSplit) - { - _splitPane.SetLeftPart(_flyoutCanvas, true); - _splitPane.SetRightPart(_detailCanvas, true); - _splitPane.Show(); - _mainWidget = _splitPane; - PackEnd(_splitPane); - - IsPresented = true; - UpdateIsPresentChangeable?.Invoke(this, new UpdateIsPresentChangeableEventArgs(false)); - UpdateFocusPolicy(true); - } - else - { - _drawer.SetContent(_flyoutCanvas, true); - _drawer.Show(); - _mainWidget = _detailCanvas; - PackEnd(_detailCanvas); - PackEnd(_drawer); - - _drawer.IsOpen = IsPresented; - UpdateIsPresentChangeable?.Invoke(this, new UpdateIsPresentChangeableEventArgs(true)); - UpdateFocusPolicy(); - } - - _flyoutCanvas.Show(); - _detailCanvas.Show(); - - // even though child was changed, Layout callback was not called, so i manually call layout function. - // Layout callback was filter out when geometry was not changed in Native.Box - UpdateChildCanvasGeometry(); - } - - void UpdateChildCanvasGeometry() - { - var bound = Geometry; - // main widget should fill the area of the FlyoutPage - if (_mainWidget != null) - { - _mainWidget.Geometry = bound; - } - - bound.Width = (int)((_popoverRatio * bound.Width)); - _drawer.Geometry = bound; - // When a _drawer.IsOpen was false, Content of _drawer area is not allocated. So, need to manaully set the content area - if (!IsSplit) - _flyoutCanvas.Geometry = bound; - } - - /// - /// Force update the focus management - /// - void UpdateFocusPolicy(bool forceAllowFocusAll = false) - { - var flyout = _flyout as Widget; - var detail = _detail as Widget; - - if (forceAllowFocusAll) - { - if (flyout != null) - flyout.AllowTreeFocus = true; - if (detail != null) - detail.AllowTreeFocus = true; - return; - } - - if (_drawer.IsOpen) - { - if (detail != null) - { - detail.AllowTreeFocus = false; - } - if (flyout != null) - { - flyout.AllowTreeFocus = true; - flyout.SetFocus(true); - } - } - else - { - if (flyout != null) - { - flyout.AllowTreeFocus = false; - } - if (detail != null) - { - detail.AllowTreeFocus = true; - detail.SetFocus(true); - } - } - } - } - - public class IsPresentedChangedEventArgs : EventArgs - { - public IsPresentedChangedEventArgs(bool isPresent) - { - IsPresent = isPresent; - } - - /// - /// Value of IsPresent - /// - public bool IsPresent { get; private set; } - } - - public class UpdateIsPresentChangeableEventArgs : EventArgs - { - public UpdateIsPresentChangeableEventArgs(bool canChange) - { - CanChange = canChange; - } - - /// - /// Value of changeable - /// - public bool CanChange { get; private set; } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/FormattedString.cs b/src/Compatibility/Core/src/Tizen/Native/FormattedString.cs deleted file mode 100644 index 23177d7d1186..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/FormattedString.cs +++ /dev/null @@ -1,129 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// Represents a text with attributes applied to some parts. - /// - /// - /// Formatted string consists of spans that represent text segments with various attributes applied. - /// - public class FormattedString - { - /// - /// A flag indicating whether the instance contains just a plain string without any formatting. - /// - /// - /// true if the instance contains an unformatted string. - /// - readonly bool _just_string; - - /// - /// Holds the unformatted string. - /// - /// - /// The contents of this field are accurate if and only if the _just_string flag is set. - /// - readonly string _string; - - /// - /// Holds the collection of span elements. - /// - /// - /// Span elements are basically chunks of text with uniform formatting. - /// - readonly ObservableCollection _spans; - - /// - /// Returns the collection of span elements. - /// - public IList Spans { get { return _spans; } } - - /// - /// Creates a new FormattedString instance with an empty string. - /// - public FormattedString() - { - _just_string = false; - _spans = new ObservableCollection(); - } - - /// - /// Creates a new FormattedString instance based on given str. - /// - /// - /// A string used to make a new FormattedString instance. - /// - public FormattedString(string str) - { - _just_string = true; - _string = str; - } - - /// - /// Returns the plain text of the FormattedString as an unformatted string. - /// - /// - /// The text content of the FormattedString without any format applied. - /// - public override string ToString() - { - if (_just_string) - { - return _string; - } - else - { - return string.Concat(from span in this.Spans select span.Text); - } - } - - /// - /// Returns the markup text representation of the FormattedString instance. - /// - /// The string containing a markup text. - internal string ToMarkupString() - { - if (_just_string) - { - return _string; - } - else - { - return string.Concat(from span in Spans select span.GetMarkupText()); - } - } - - /// - /// Casts the FormattedString to a string. - /// - /// The FormattedString instance which will be used for the conversion. - public static explicit operator string(FormattedString formatted) - { - return formatted.ToString(); - } - - /// - /// Casts the string to a FormattedString. - /// - /// The text which will be put in a new FormattedString instance. - public static implicit operator FormattedString(string text) - { - return new FormattedString(text); - } - - /// - /// Casts the Span to a FormattedString. - /// - /// The span which will be used for the conversion. - public static implicit operator FormattedString(Span span) - { - return new FormattedString() - { - Spans = { span } - }; - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/FormsLayout.cs b/src/Compatibility/Core/src/Tizen/Native/FormsLayout.cs deleted file mode 100644 index 423e48c1ff03..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/FormsLayout.cs +++ /dev/null @@ -1,128 +0,0 @@ -using ElmSharp; - -using ELayout = ElmSharp.Layout; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class FormsLayout : ELayout - { - public string ThemeClass { get; private set; } - public string ThemeGroup { get; private set; } - public string ThemeStyle { get; private set; } - - public FormsLayout(EvasObject parent) : base(parent) - { - } - - public new void SetTheme(string klass, string group, string style) - { - base.SetTheme(klass, group, style); - ThemeClass = klass; - ThemeGroup = group; - ThemeStyle = style; - } - } - - public class ApplicationLayout : FormsLayout - { - public class Styles - { - public const string Default = "default"; - } - - public class Parts - { - public const string Content = "elm.swallow.content"; - public const string Background = "elm.swallow.bg"; - } - - public ApplicationLayout(EvasObject parent, string style = Styles.Default) : base(parent) - { - SetTheme("layout", "application", style); - } - - public bool SetContentPart(EvasObject content, bool preserveOldContent = false) - { - return SetPartContent(Parts.Content, content, preserveOldContent); - } - - public bool SetBackgroundPart(EvasObject content, bool preserveOldContent = false) - { - return SetPartContent(Parts.Background, content, preserveOldContent); - } - } - - public class WidgetLayout : FormsLayout - { - public class Styles - { - public const string Default = "default"; - } - - public WidgetLayout(EvasObject parent, string style = Styles.Default) : base(parent) - { - SetTheme("layout", "elm_widget", style); - } - } - - public class EntryLayout : FormsLayout - { - public class Styles - { - public const string Default = "default"; - } - - public class Parts - { - public const string Content = "elm.swallow.content"; - } - - public EntryLayout(EvasObject parent, string style = Styles.Default) : base(parent) - { - SetTheme("layout", "entry", style); - } - } - - public class EditFieldEntryLayout : FormsLayout - { - public class Styles - { - public const string SingleLine = "singleline"; - public const string MulitLine = "multiline"; - } - - public class Parts - { - public const string Button = "elm.swallow.button"; - } - - public class Signals - { - public const string FocusedState = "elm,state,focused"; - public const string UnFocusedState = "elm,state,unfocused"; - public const string ShowButtonAction = "elm,action,show,button"; - public const string HideButtonAction = "elm,action,hide,button"; - } - - public EditFieldEntryLayout(EvasObject parent, string style) : base(parent) - { - SetTheme("layout", "editfield", style); - } - - public bool SetButtonPart(EvasObject content, bool preserveOldContent = false) - { - return SetPartContent(Parts.Button, content, preserveOldContent); - } - - public void SendButtonActionSignal(bool isVisible) - { - SignalEmit(isVisible ? Signals.ShowButtonAction : Signals.HideButtonAction, ""); - } - - public void SendFocusStateSignal(bool isFocus) - { - SignalEmit(isFocus ? Signals.FocusedState : Signals.UnFocusedState, ""); - } - - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/IBatchable.cs b/src/Compatibility/Core/src/Tizen/Native/IBatchable.cs deleted file mode 100644 index a79df34062ff..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/IBatchable.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - internal interface IBatchable - { - void OnBatchCommitted(); - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/IButton.cs b/src/Compatibility/Core/src/Tizen/Native/IButton.cs deleted file mode 100644 index c8a0208b6309..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/IButton.cs +++ /dev/null @@ -1,24 +0,0 @@ -using EColor = ElmSharp.Color; -using ESize = ElmSharp.Size; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public interface IButton - { - string Text { get; set; } - - double FontSize { get; set; } - - FontAttributes FontAttributes { get; set; } - - string FontFamily { get; set; } - - EColor TextColor { get; set; } - - Image Image { get; set; } - - ESize Measure(int availableWidth, int availableHeight); - - void UpdateStyle(string style); - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Native/IContainable.cs b/src/Compatibility/Core/src/Tizen/Native/IContainable.cs deleted file mode 100644 index a157546a092f..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/IContainable.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Collections.Generic; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// Interface defining methods for managing elements of the container. - /// - /// The type of element that can be added to the container. - public interface IContainable - { - /// - /// The children collection of an element. - /// - IList Children { get; } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/IDateTimeDialog.cs b/src/Compatibility/Core/src/Tizen/Native/IDateTimeDialog.cs deleted file mode 100644 index 0a3f35682ca7..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/IDateTimeDialog.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public interface IDateTimeDialog - { - string Title { get; set; } - DateTimePickerMode Mode { get; set; } - DateTime MaximumDateTime { get; set; } - DateTime MinimumDateTime { get; set; } - DateTime DateTime { get; set; } - - event EventHandler DateTimeChanged; - event EventHandler PickerOpened; - event EventHandler PickerClosed; - - void Show(); - void Hide(); - void Unrealize(); - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/IEntry.cs b/src/Compatibility/Core/src/Tizen/Native/IEntry.cs deleted file mode 100644 index ecb3ee22fbc7..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/IEntry.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using EColor = ElmSharp.Color; - - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public interface IEntry - { - double FontSize { get; set; } - - FontAttributes FontAttributes { get; set; } - - string FontFamily { get; set; } - - EColor TextColor { get; set; } - - TextAlignment HorizontalTextAlignment { get; set; } - - string Placeholder { get; set; } - - EColor PlaceholderColor { get; set; } - - string FontWeight { get; set; } - - Keyboard Keyboard { get; set; } - - event EventHandler TextChanged; - - event EventHandler TextBlockFocused; - - event EventHandler TextBlockUnfocused; - - event EventHandler EntryLayoutFocused; - - event EventHandler EntryLayoutUnfocused; - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Native/IMeasurable.cs b/src/Compatibility/Core/src/Tizen/Native/IMeasurable.cs deleted file mode 100644 index 8d4f922e40e5..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/IMeasurable.cs +++ /dev/null @@ -1,20 +0,0 @@ -using ESize = ElmSharp.Size; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// Interface of the controls which can measure their size taking into - /// account the available area. - /// - public interface IMeasurable - { - /// - /// Measures the size of the control in order to fit it into the - /// available area. - /// - /// Available width. - /// Available height. - /// Size of the control that fits the available area. - ESize Measure(int availableWidth, int availableHeight); - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/ITableView.cs b/src/Compatibility/Core/src/Tizen/Native/ITableView.cs deleted file mode 100644 index b67ae0479e43..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/ITableView.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - interface ITableView - { - void ApplyTableRoot(TableRoot root); - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/ITextable.cs b/src/Compatibility/Core/src/Tizen/Native/ITextable.cs deleted file mode 100644 index 2a82c3ed1c11..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/ITextable.cs +++ /dev/null @@ -1,68 +0,0 @@ -using EColor = ElmSharp.Color; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// Interface defining properties of formattable text. - /// - public interface ITextable - { - /// - /// Get or sets the formatted text. - /// - FormattedString FormattedText { get; set; } - - /// - /// Gets or sets the text. - /// - string Text { get; set; } - - /// - /// Gets or sets the color for the text. - /// - EColor TextColor { get; set; } - - /// - /// Gets or sets the background color for the text. - /// - EColor TextBackgroundColor { get; set; } - - /// - /// Gets or sets the font family for the text. - /// - string FontFamily { get; set; } - - /// - /// Gets or sets the font attributes for the text. - /// See for information about FontAttributes. - /// - FontAttributes FontAttributes { get; set; } - - /// - /// Gets or sets the font size for the text. - /// - double FontSize { get; set; } - - /// - /// Gets or sets the horizontal alignment mode for the text. - /// See for information about TextAlignment. - /// - TextAlignment HorizontalTextAlignment { get; set; } - - /// - /// Gets or sets the vertical alignment mode for the text. - /// See for information about TextAlignment. - /// - TextAlignment VerticalTextAlignment { get; set; } - - /// - /// Gets or sets the value that indicates whether the text has underline. - /// - bool Underline { get; set; } - - /// - /// Gets or sets the value that indicates whether the text has strike line though it. - /// - bool Strikethrough { get; set; } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/Image.cs b/src/Compatibility/Core/src/Tizen/Native/Image.cs deleted file mode 100644 index 66385d3d7a06..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Image.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Threading.Tasks; -using ElmSharp; -using EImage = ElmSharp.Image; -using ESize = ElmSharp.Size; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// Extends the ElmSharp.Image class with functionality useful to renderer. - /// - public class Image : EImage, IMeasurable - { - /// - /// Initializes a new instance of the class. - /// - /// The parent EvasObject. - public Image(EvasObject parent) : base(parent) - { - } - - /// - /// Implements the interface. - /// - /// Available width. - /// Available height. - public ESize Measure(int availableWidth, int availableHeight) - { - var imageSize = ObjectSize; - var size = new ESize() - { - Width = imageSize.Width, - Height = imageSize.Height, - }; - - if (0 != availableWidth && 0 != availableHeight - && (imageSize.Width > availableWidth || imageSize.Height > availableHeight)) - { - // when available size is limited and insufficient for the image ... - double imageRatio = (double)imageSize.Width / (double)imageSize.Height; - double availableRatio = (double)availableWidth / (double)availableHeight; - // depending on the relation between availableRatio and imageRatio, copy the availableWidth or availableHeight - // and calculate the size which preserves the image ratio, but does not exceed the available size - size.Width = availableRatio > imageRatio ? imageSize.Width * availableHeight / imageSize.Height : availableWidth; - size.Height = availableRatio > imageRatio ? availableHeight : imageSize.Height * availableWidth / imageSize.Width; - } - - return size; - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Native/Keyboard.cs b/src/Compatibility/Core/src/Tizen/Native/Keyboard.cs deleted file mode 100644 index 4c502c943f57..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Keyboard.cs +++ /dev/null @@ -1,89 +0,0 @@ -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// Keyboard layout type on entry control. - /// - public enum Keyboard - { - /// - /// Disable Keyboard - /// - None = -1, - - /// - /// Keyboard layout type default. - /// - Normal, - - /// - /// Keyboard layout type number. - /// - Number, - - /// - /// Keyboard layout type email. - /// - Email, - - /// - /// Keyboard layout type url. - /// - Url, - - /// - /// Keyboard layout type phone. - /// - PhoneNumber, - - /// - /// Keyboard layout type ip. - /// - Ip, - - /// - /// Keyboard layout type month. - /// - Month, - - /// - /// Keyboard layout type number. - /// - NumberOnly, - - /// - /// Keyboard layout type error type. Do not use it directly! - /// - Invalid, - - /// - /// Keyboard layout type hexadecimal. - /// - Hex, - - /// - /// Keyboard layout type terminal type, esc, alt, ctrl, etc. - /// - Terminal, - - /// - /// Keyboard layout type password. - /// - Password, - - /// - /// Keyboard layout type date and time. - /// - DateTime, - - /// - /// Keyboard layout type emoticons. - /// - Emoticon, - - /// - /// Keyboard layout type numeric. - /// - Numeric = Emoticon + 2017, - } -} - diff --git a/src/Compatibility/Core/src/Tizen/Native/Label.cs b/src/Compatibility/Core/src/Tizen/Native/Label.cs deleted file mode 100644 index b18c7b8d2c4a..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Label.cs +++ /dev/null @@ -1,419 +0,0 @@ -using System; -using ElmSharp; -using EColor = ElmSharp.Color; -using ELabel = ElmSharp.Label; -using ESize = ElmSharp.Size; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// The Label class extends ElmSharp.Label to be better suited for Xamarin renderers. - /// Mainly the formatted text support. - /// - public class Label : ELabel, ITextable, IMeasurable, IBatchable - { - /// - /// The _span holds the content of the label. - /// - readonly Span _span = new Span(); - - /// - /// Initializes a new instance of the class. - /// - /// Parent evas object. - public Label(EvasObject parent) : base(parent) - { - } - - /// - /// Get or sets the formatted text. - /// - /// Setting FormattedText changes the value of the Text property. - /// The formatted text. - public FormattedString FormattedText - { - get - { - return _span.FormattedText; - } - - set - { - if (value != _span.FormattedText) - { - _span.FormattedText = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the text. - /// - /// Setting Text overwrites the value of the FormattedText property too. - /// The content of the label. - public override string Text - { - get - { - return _span.Text; - } - - set - { - if (value != _span.Text) - { - _span.Text = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the color of the formatted text. - /// - /// The color of the text. - public EColor TextColor - { - get - { - return _span.ForegroundColor; - } - - set - { - if (!_span.ForegroundColor.Equals(value)) - { - _span.ForegroundColor = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the background color for the text. - /// - /// The color of the label's background. - public EColor TextBackgroundColor - { - get - { - return _span.BackgroundColor; - } - - set - { - if (!_span.BackgroundColor.Equals(value)) - { - _span.BackgroundColor = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the font family for the text. - /// - /// The font family. - public string FontFamily - { - get - { - return _span.FontFamily; - } - - set - { - if (value != _span.FontFamily) - { - _span.FontFamily = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the font attributes. - /// - /// The font attributes. - public FontAttributes FontAttributes - { - get - { - return _span.FontAttributes; - } - - set - { - if (value != _span.FontAttributes) - { - _span.FontAttributes = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the font size for the text. - /// - /// The size of the font. - public double FontSize - { - get - { - return _span.FontSize; - } - - set - { - if (value != _span.FontSize) - { - _span.FontSize = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the line height. - /// - public double LineHeight - { - get - { - return _span.LineHeight; - } - set - { - if (value != _span.LineHeight) - { - _span.LineHeight = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the font weight for the text. - /// - /// The weight of the font. - public string FontWeight - { - get - { - return _span.FontWeight; - } - - set - { - if (value != _span.FontWeight) - { - _span.FontWeight = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the line wrap option. - /// - /// The line break mode. - public LineBreakMode LineBreakMode - { - get - { - return _span.LineBreakMode; - } - - set - { - if (value != _span.LineBreakMode) - { - _span.LineBreakMode = value; - switch (value) - { - case LineBreakMode.NoWrap: - LineWrapType = WrapType.None; - IsEllipsis = false; - break; - case LineBreakMode.CharacterWrap: - LineWrapType = WrapType.Char; - IsEllipsis = false; - break; - case LineBreakMode.WordWrap: - LineWrapType = WrapType.Word; - IsEllipsis = false; - break; - case LineBreakMode.MixedWrap: - LineWrapType = WrapType.Mixed; - IsEllipsis = false; - break; - default: - LineWrapType = WrapType.None; - IsEllipsis = true; - break; - } - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the horizontal text alignment. - /// - /// The horizontal text alignment. - public TextAlignment HorizontalTextAlignment - { - get - { - return _span.HorizontalTextAlignment; - } - - set - { - if (value != _span.HorizontalTextAlignment) - { - _span.HorizontalTextAlignment = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the vertical text alignment. - /// - /// The vertical text alignment. - public TextAlignment VerticalTextAlignment - { - // README: It only work on Tizen 4.0 - get - { - double valign = this.GetVerticalTextAlignment(); - if (valign == 0.0) - { - return TextAlignment.Start; - } - else if (valign == 0.5) - { - return TextAlignment.Center; - } - else if (valign == 1.0) - { - return TextAlignment.End; - } - else - { - return TextAlignment.Auto; - } - } - set - { - double valign = 0; - switch (value) - { - case TextAlignment.Auto: - valign = -1; - break; - case TextAlignment.None: - case TextAlignment.Start: - valign = 0; - break; - case TextAlignment.Center: - valign = 0.5; - break; - case TextAlignment.End: - valign = 1.0; - break; - } - this.SetVerticalTextAlignment(valign); - } - } - - /// - /// Gets or sets the value that indicates whether the text is underlined. - /// - /// true if the text is underlined. - public bool Underline - { - get - { - return _span.Underline; - } - - set - { - if (value != _span.Underline) - { - _span.Underline = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Gets or sets the value that indicates whether the text is striked out. - /// - /// true if the text is striked out. - public bool Strikethrough - { - get - { - return _span.Strikethrough; - } - - set - { - if (value != _span.Strikethrough) - { - _span.Strikethrough = value; - ApplyTextAndStyle(); - } - } - } - - /// - /// Implements to provide a desired size of the label. - /// - /// Available width. - /// Available height. - /// Size of the control that fits the available area. - public ESize Measure(int availableWidth, int availableHeight) - { - var size = Geometry; - - Resize(availableWidth, size.Height); - - var formattedSize = this.GetTextBlockFormattedSize(); - Resize(size.Width, size.Height); - - // Set bottom padding for lower case letters that have segments below the bottom line of text (g, j, p, q, y). - var verticalPadding = (int)Math.Ceiling(0.05 * FontSize); - formattedSize.Height += verticalPadding; - - // This is the EFL team's guide. - // For wrap to work properly, the label must be 1 pixel larger than the size of the formatted text. - formattedSize.Width += 1; - - return formattedSize; - } - - void IBatchable.OnBatchCommitted() - { - ApplyTextAndStyle(); - } - - void ApplyTextAndStyle() - { - if (!this.IsBatched()) - { - SetInternalTextAndStyle(_span.GetDecoratedText(), _span.GetStyle()); - } - } - - void SetInternalTextAndStyle(string formattedText, string textStyle) - { - base.Text = formattedText; - TextStyle = textStyle; - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/LayoutEventArgs.cs b/src/Compatibility/Core/src/Tizen/Native/LayoutEventArgs.cs deleted file mode 100644 index a88655190918..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/LayoutEventArgs.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using ERect = ElmSharp.Rect; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// Holds information about size of the area which can be used for layout. - /// - public class LayoutEventArgs : EventArgs - { - /// - /// Geometry of the layout area, absolute coordinate - /// - public ERect Geometry - { - get; - internal set; - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/LineBreakMode.cs b/src/Compatibility/Core/src/Tizen/Native/LineBreakMode.cs deleted file mode 100644 index 064344863d0d..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/LineBreakMode.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// Enumerates values that describe options for line braking. - /// - public enum LineBreakMode - { - /// - /// Follow base LineBreakMode. - /// - None, - - /// - /// Do not wrap text. - /// - NoWrap, - - /// - /// Wrap at character boundaries. - /// - CharacterWrap, - - /// - /// Wrap at word boundaries. - /// - WordWrap, - - /// - /// Tries to wrap at word boundaries, and then wrap at a character boundary if the word is too long. - /// - MixedWrap, - - /// - /// Truncate the head of text. - /// - HeadTruncation, - - /// - /// Truncate the middle of text. This may be done, for example, by replacing it with an ellipsis. - /// - MiddleTruncation, - - /// - /// Truncate the tail of text. - /// - TailTruncation, - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/ListView.cs b/src/Compatibility/Core/src/Tizen/Native/ListView.cs deleted file mode 100644 index 2f373f5bc1f7..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/ListView.cs +++ /dev/null @@ -1,700 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using ElmSharp; -using Microsoft.Maui.Controls.Internals; -using EColor = ElmSharp.Color; -using ERect = ElmSharp.Rect; -using EScroller = ElmSharp.Scroller; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - // Type alias which identifies list of cells whose data model was transformed by Xamarin. - using GroupList = TemplatedItemsList, Cell>; - - /// - /// Native ListView implementation for Xamarin renderer - /// - /// - /// This internally uses GenList class. - /// One should note that it is optimized for displaying many elements which may be - /// unavailable at first. This means that only currently visible elements will be constructed. - /// Whenever element disappears from visible space its content is destroyed for time being. - /// This is carried out by so called Cell Handlers. - /// - [Obsolete] - public class ListView : GenList - { - /// - /// ItemContext helper class. This represents the association between Microsoft.Maui.Controls.Compatibility.Cell and - /// native elements. It also stores useful context for them. - /// - public class ItemContext - { - public ItemContext() - { - Item = null; - Cell = null; - Renderer = null; - ListOfSubItems = null; - } - - public GenItem Item; - public Cell Cell; - public bool IsGroupItem; - public CellRenderer Renderer; - internal TemplatedItemsList, Cell> ListOfSubItems; - } - - public class HeaderFooterItemContext : ItemContext - { - public VisualElement Element; - } - - class ScrollerExtension : EScroller - { - public ScrollerExtension(GenList scrollableLayout) : base(scrollableLayout) - { - } - - protected override IntPtr CreateHandle(EvasObject parent) - { - return parent.RealHandle; - } - } - - /// - /// The item context list for each added element. - /// - readonly List _itemContextList = new List(); - - /// - /// Registered cell handlers. - /// - protected readonly IDictionary _cellRendererCache = new Dictionary(); - - /// - /// Registered group handlers. - /// - protected readonly IDictionary _groupCellRendererCache = new Dictionary(); - - /// - /// The header element. - /// - VisualElement _headerElement; - - - /// - /// The footer element. - /// - VisualElement _footerElement; - - /// - /// The item class for header and footer. - /// - GenItemClass _headerFooterItemClass = null; - - /// - /// The object to handle scroller properties. - /// - protected virtual EScroller Scroller { get; set; } - - protected HeaderFooterItemContext HeaderItemContext { get; set; } - - protected HeaderFooterItemContext FooterItemContext { get; set; } - - /// - /// Gets or sets a value indicating whether this instance has grouping enabled. - /// - /// true if this instance has grouping enabled. - public bool IsGroupingEnabled { get; set; } - - /// - /// Gets the current region in the content object that is visible through the Scroller. - /// - public virtual ERect CurrentRegion => Scroller?.CurrentRegion ?? new ERect(); - - /// - /// Sets or gets the value of VerticalScrollBarVisibility - /// - public virtual ScrollBarVisiblePolicy VerticalScrollBarVisibility - { - get - { - return Scroller?.VerticalScrollBarVisiblePolicy ?? ScrollBarVisiblePolicy.Auto; - } - set - { - if (Scroller != null) - Scroller.VerticalScrollBarVisiblePolicy = value; - } - } - - /// - /// Sets or gets the value of HorizontalScrollBarVisibility - /// - public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisibility - { - get - { - return Scroller?.HorizontalScrollBarVisiblePolicy ?? ScrollBarVisiblePolicy.Auto; - } - set - { - if (Scroller != null) - Scroller.HorizontalScrollBarVisiblePolicy = value; - } - } - - public EColor BottomLineColor { get; set; } - - /// - /// Occurs when the ListView has scrolled. - /// - public event EventHandler Scrolled; - - /// - /// Constructor of ListView native control. - /// - /// ElmSharp object which is parent of particular list view - public ListView(EvasObject parent) - : base(parent) - { - Scroller = new ScrollerExtension(this); - Scroller.Scrolled += OnScrolled; - } - - protected ListView() - { - } - - /// - /// Gets the item context based on Cell item. - /// - /// The item context. - /// Cell for which context should be found. - internal ItemContext GetItemContext(Cell cell) - { - if (cell == null) - { - return null; - } - else - { - return _itemContextList.Find(X => X.Cell == cell); - } - } - - /// - /// Sets the HasUnevenRows property. - /// - /// If true, the list will allow uneven sizes for its rows. - public void SetHasUnevenRows(bool hasUnevenRows) - { - Homogeneous = !hasUnevenRows; - UpdateRealizedItems(); - } - - /// - /// Adds elements to the list and defines its presentation based on Cell type. - /// - /// IEnumerable on Cell collection. - /// Cell before which new items will be placed. - /// Null value may also be passed as this parameter, which results in appending new items to the end. - /// - public virtual void AddSource(IEnumerable source, Cell beforeCell = null) - { - foreach (var data in source) - { - GroupList groupList = data as GroupList; - if (groupList != null) - { - AddGroupItem(groupList, beforeCell); - foreach (var item in groupList) - { - AddItem(item, groupList.HeaderContent); - } - } - else - { - AddItem(data as Cell, null, beforeCell); - } - } - } - - /// - /// Deletes all items from a given group. - /// - /// Group of items to be deleted. - internal void ResetGroup(GroupList group) - { - var items = _itemContextList.FindAll(x => x.ListOfSubItems == group && x.Cell != group.HeaderContent); - foreach (var item in items) - { - item.Item?.Delete(); - } - } - - /// - /// Adds items to the group. - /// - /// Group to which elements will be added. - /// New list items to be added. - /// A reference to the Cell already existing in a ListView. - /// Newly added cells will be put just before this cell. - public void AddItemsToGroup(IEnumerable itemGroup, IEnumerable newItems, Cell cellBefore = null) - { - ItemContext groupCtx = GetItemContext((itemGroup as GroupList)?.HeaderContent); - if (groupCtx != null) - { - foreach (var item in newItems) - { - AddItem(item as Cell, groupCtx.Cell, cellBefore); - } - } - } - - /// - /// Removes the specified cells. - /// - /// Cells to be removed. - public void Remove(IEnumerable cells) - { - foreach (var data in cells) - { - var group = data as GroupList; - if (group != null) - { - ItemContext groupCtx = GetItemContext(group.HeaderContent); - Remove(groupCtx.ListOfSubItems); - groupCtx.Item.Delete(); - } - else - { - ItemContext itemCtx = GetItemContext(data as Cell); - itemCtx?.Item?.Delete(); - } - } - } - - /// - /// Scrolls the list to a specified cell. - /// - /// - /// Different scrolling behaviors are also possible. The element may be positioned in the center, - /// top or bottom of the visible part of the list depending on the value of the position parameter. - /// - /// Cell which will be displayed after scrolling . - /// This will defines scroll to behavior based on ScrollToPosition values. - /// If true, scrolling will be animated. Otherwise the cell will be moved instantaneously. - public void ApplyScrollTo(Cell cell, ScrollToPosition position, bool animated) - { - GenListItem item = GetItemContext(cell)?.Item as GenListItem; - if (item != null) - this.ScrollTo(item, position.ToNative(), animated); - } - - /// - /// Selects the specified cell. - /// - /// Cell to be selected. - public void ApplySelectedItem(Cell cell) - { - GenListItem item = GetItemContext(cell)?.Item as GenListItem; - if (item != null) - item.IsSelected = true; - } - - /// - /// Sets the header. - /// - /// Header of the list. - public virtual void SetHeader(VisualElement header) - { - _headerElement = header; - UpdateHeader(); - } - - protected virtual void UpdateHeader() - { - if (GetHeader() == null) - { - if (HasHeaderContext()) - { - RemoveHeaderItemContext(); - } - return; - } - - var headerTemplate = GetHeaderFooterItemClass(); - if (!HasHeaderContext()) - { - InitializeHeaderItemContext(headerTemplate); - } - else - { - HeaderItemContext.Element = GetHeader(); - (HeaderItemContext.Item as GenListItem).UpdateItemClass(headerTemplate, HeaderItemContext); - } - } - - protected void InitializeHeaderItemContext(GenItemClass headerTemplate) - { - var context = new HeaderFooterItemContext(); - context.Element = GetHeader(); - if (FirstItem != null) - { - context.Item = InsertBefore(headerTemplate, context, FirstItem); - } - else - { - context.Item = Append(headerTemplate, context); - } - context.Item.SelectionMode = GenItemSelectionMode.None; - context.Item.Deleted += OnHeaderItemDeleted; - HeaderItemContext = context; - } - - void OnHeaderItemDeleted(object sender, EventArgs e) - { - HeaderItemContext = null; - } - - /// - /// Sets the footer. - /// - /// Footer of the list. - public virtual void SetFooter(VisualElement footer) - { - _footerElement = footer; - UpdateFooter(); - } - - protected virtual void UpdateFooter() - { - if (GetFooter() == null) - { - if (HasFooterContext()) - { - RemoveFooterItemContext(); - } - return; - } - - var footerTemplate = GetHeaderFooterItemClass(); - if (!HasFooterContext()) - { - InitializeFooterItemContext(footerTemplate); - } - else - { - FooterItemContext.Element = GetFooter(); - (HeaderItemContext.Item as GenListItem).UpdateItemClass(footerTemplate, HeaderItemContext); - } - } - - protected void InitializeFooterItemContext(GenItemClass footerTemplate) - { - var context = new HeaderFooterItemContext(); - context.Element = GetFooter(); - context.Item = Append(footerTemplate, context); - context.Item.SelectionMode = GenItemSelectionMode.None; - context.Item.Deleted += OnFooterItemDeleted; - FooterItemContext = context; - } - - void OnFooterItemDeleted(object sender, EventArgs e) - { - FooterItemContext = null; - } - - protected void RemoveHeaderItemContext() - { - HeaderItemContext?.Item?.Delete(); - HeaderItemContext = null; - } - - protected void RemoveFooterItemContext() - { - FooterItemContext?.Item?.Delete(); - FooterItemContext = null; - } - - public bool HasHeaderContext() - { - return HeaderItemContext != null; - } - - public bool HasFooterContext() - { - return FooterItemContext != null; - } - - /// - /// Gets the header. - /// - /// The header. - public VisualElement GetHeader() - { - return _headerElement; - } - - /// - /// Gets the footer. - /// - /// The footer. - public VisualElement GetFooter() - { - return _footerElement; - } - - protected virtual void OnScrolled(object sender, EventArgs e) - { - Scrolled?.Invoke(this, EventArgs.Empty); - } - - /// - /// Called every time an object gets realized. - /// - /// Sender of the event. - /// GenListItemEventArgs. - void OnItemAppear(object sender, GenListItemEventArgs evt) - { - ItemContext itemContext = (evt.Item.Data as ItemContext); - - if (itemContext != null && itemContext.Cell != null) - { - itemContext.Cell.SendSignalToItem(evt.Item); - if (BottomLineColor.IsDefault) - { - evt.Item.DeleteBottomlineColor(); - } - else - { - evt.Item.SetBottomlineColor(BottomLineColor); - } - (itemContext.Cell as ICellController).SendAppearing(); - } - } - - /// - /// Called every time an object gets unrealized. - /// - /// Sender of the event. - /// GenListItemEventArgs. - void OnItemDisappear(object sender, GenListItemEventArgs evt) - { - ItemContext itemContext = (evt.Item.Data as ItemContext); - if (itemContext != null && itemContext.Cell != null) - { - (itemContext.Cell as ICellController).SendDisappearing(); - itemContext.Renderer?.SendUnrealizedCell(itemContext.Cell); - } - } - - protected override void OnRealized() - { - base.OnRealized(); - ItemRealized += OnItemAppear; - ItemUnrealized += OnItemDisappear; - } - - /// - /// A convenience shorthand method for derivate classes. - /// - /// Cell to be added. - protected void AddCell(Cell cell) - { - AddItem(cell); - } - - /// - /// Gets the cell renderer for given cell type. - /// - /// The cell handler. - /// Cell to be added. - /// If true, then group handlers will be included in the lookup as well. - protected virtual CellRenderer GetCellRenderer(Cell cell, bool isGroup = false) - { - Type type = cell.GetType(); - var cache = isGroup ? _groupCellRendererCache : _cellRendererCache; - if (cache.ContainsKey(type)) - { - var cacheCellRenderer = cache[type]; - cacheCellRenderer.SendCreatedCell(cell, isGroup); - return cacheCellRenderer; - } - - CellRenderer renderer = null; - renderer = Forms.GetHandler(type); - - if (renderer == null) - { - Log.Error("Cell type is not handled: {0}", cell.GetType()); - throw new ArgumentException("Unsupported cell type"); - } - - renderer.SetGroupMode(isGroup); - renderer.SendCreatedCell(cell, isGroup); - return cache[type] = renderer; - } - - /// - /// Adds the group item. Group item is actually of class GroupList because - /// group item has sub items (can be zero) which needs to be added. - /// If beforeCell is not null, new group will be added just before it. - /// - /// Group to be added. - /// Before cell. - void AddGroupItem(GroupList groupList, Cell beforeCell = null) - { - Cell groupCell = groupList.HeaderContent; - CellRenderer groupRenderer = GetCellRenderer(groupCell, true); - - ItemContext groupItemContext = new ItemContext(); - groupItemContext.Cell = groupCell; - groupItemContext.Renderer = groupRenderer; - groupItemContext.IsGroupItem = true; - groupItemContext.ListOfSubItems = groupList; - _itemContextList.Add(groupItemContext); - - if (beforeCell != null) - { - GenListItem beforeItem = GetItemContext(beforeCell)?.Item as GenListItem; - groupItemContext.Item = InsertBefore(groupRenderer.Class, groupItemContext, beforeItem, GenListItemType.Group); - } - else - { - groupItemContext.Item = Append(groupRenderer.Class, groupItemContext, GenListItemType.Group); - } - - groupItemContext.Item.SelectionMode = GenItemSelectionMode.None; - groupItemContext.Item.IsEnabled = groupCell.IsEnabled; - groupItemContext.Item.Deleted += ItemDeletedHandler; - - } - - /// - /// Adds the item. - /// - /// Cell to be added. - /// Group to which the new item should belong. - /// If the value of groupCell is not null, the new item will be put into the requested group. - /// The cell before which the new item should be placed. - /// If the value of beforeCell is not null, the new item will be placed just before the requested cell. - void AddItem(Cell cell, Cell groupCell = null, Cell beforeCell = null) - { - CellRenderer renderer = GetCellRenderer(cell); - GenListItem parentItem = null; - - ItemContext itemContext = new ItemContext(); - itemContext.Cell = cell; - itemContext.Renderer = renderer; - _itemContextList.Add(itemContext); - - if (IsGroupingEnabled && groupCell != null) - { - var groupContext = GetItemContext(groupCell); - itemContext.ListOfSubItems = groupContext.ListOfSubItems; - parentItem = groupContext.Item as GenListItem; - } - - if (beforeCell != null) - { - GenListItem beforeItem = GetItemContext(beforeCell)?.Item as GenListItem; - itemContext.Item = InsertBefore(renderer.Class, itemContext, beforeItem, GenListItemType.Normal, parentItem); - } - else if (HasFooterContext()) - { - itemContext.Item = InsertBefore(renderer.Class, itemContext, FooterItemContext.Item as GenListItem, GenListItemType.Normal, parentItem); - } - else - { - itemContext.Item = Append(renderer.Class, itemContext, GenListItemType.Normal, parentItem); - } - - itemContext.Item.SelectionMode = GenItemSelectionMode.Always; - itemContext.Item.IsEnabled = cell.IsEnabled; - itemContext.Item.Deleted += ItemDeletedHandler; - - cell.PropertyChanged += OnCellPropertyChanged; - (cell as ICellController).ForceUpdateSizeRequested += OnForceUpdateSizeRequested; - } - - /// - /// Handles item deleted event. - /// - /// Sender of the event. - /// Empty argument. - void ItemDeletedHandler(object sender, EventArgs e) - { - ItemContext itemContext = (sender as GenListItem).Data as ItemContext; - if (itemContext.Cell != null) - { - itemContext.Cell.PropertyChanged -= OnCellPropertyChanged; - (itemContext.Cell as ICellController).ForceUpdateSizeRequested -= OnForceUpdateSizeRequested; - } - _itemContextList.Remove(itemContext); - } - - /// - /// Invoked whenever the properties of data model change. - /// - /// Sender of the event. - /// PropertyChangedEventArgs. - /// - /// The purpose of this method is to propagate these changes to the presentation layer. - /// - void OnCellPropertyChanged(object sender, PropertyChangedEventArgs e) - { - var cell = sender as Cell; - var context = GetItemContext(cell); - context.Renderer.SendCellPropertyChanged(cell, context.Item, e.PropertyName); - } - - void OnForceUpdateSizeRequested(object sender, EventArgs e) - { - var cell = sender as Cell; - var itemContext = GetItemContext(cell); - if (itemContext.Item != null) - itemContext.Item.Update(); - } - - /// - /// Gets the item class used for header and footer cells. - /// - /// The header and footer item class. - protected GenItemClass GetHeaderFooterItemClass() - { - if (_headerFooterItemClass == null) - { - _headerFooterItemClass = new GenItemClass(ThemeConstants.GenItemClass.Styles.Full) - { - GetContentHandler = (data, part) => - { - var context = data as HeaderFooterItemContext; - if (context == null || context.Element == null) - return null; - - var renderer = Platform.GetOrCreateRenderer(context.Element); - if (context.Element.MinimumHeightRequest == -1) - { - SizeRequest request = context.Element.Measure(double.PositiveInfinity, double.PositiveInfinity); - renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(request.Request.Height); - } - else - { - renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(context.Element.MinimumHeightRequest); - } - - (renderer as ILayoutRenderer)?.RegisterOnLayoutUpdated(); - - return renderer.NativeView; - } - }; - } - return _headerFooterItemClass; - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/ObservableCollection.cs b/src/Compatibility/Core/src/Tizen/Native/ObservableCollection.cs deleted file mode 100644 index 958e898f4e9b..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/ObservableCollection.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Collections.Specialized; -using System.Linq; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// Represents a dynamic data collection that provides notifications when items get added, removed, or when the whole list is refreshed. - /// - /// The type of elements in the collection. - internal class ObservableCollection : System.Collections.ObjectModel.ObservableCollection - { - /// - /// Removes all items from the collection. - /// - /// - /// Fisrt remove all items, send CollectionChanged event with Remove Action - /// Second call ClearItems of base - /// - protected override void ClearItems() - { - var oldItems = Items.ToList(); - Items.Clear(); - using (BlockReentrancy()) - { - OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, oldItems)); - } - base.ClearItems(); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/Page.cs b/src/Compatibility/Core/src/Tizen/Native/Page.cs deleted file mode 100644 index b5dbed747eda..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Page.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// A basic page which can hold a single view. - /// - public class Page : Background, IContainable - { - /// - /// The name of the part to be used when setting content. - /// - [Obsolete("ContentPartName is obsolete. Please use the ThemeConstants.Background.Parts.Overlay instead.")] - public const string ContentPartName = ThemeConstants.Background.Parts.Overlay; - - /// - /// Exposes the Children property, mapping it to the _canvas' Children property. - /// - public new IList Children => Forms.UseFastLayout ? EvasFormsCanvas?.Children : Canvas?.Children; - - /// - /// The canvas, used as a container for other objects. - /// - /// - /// The canvas holds all the Views that the ContentPage is composed of. - /// - internal Container _canvas; - - EvasFormsCanvas EvasFormsCanvas => _canvas as EvasFormsCanvas; - - Canvas Canvas => _canvas as Canvas; - - /// - /// Initializes a new instance of the ContentPage class. - /// - public Page(EvasObject parent) : base(parent) - { - if (Forms.UseFastLayout) - _canvas = new EvasFormsCanvas(this); - else - _canvas = new Canvas(this); - this.SetOverlayPart(_canvas); - } - - /// - /// Allows custom handling of events emitted when the layout has been updated. - /// - public event EventHandler LayoutUpdated - { - add - { - if (Forms.UseFastLayout) - EvasFormsCanvas.LayoutUpdated += value; - else - Canvas.LayoutUpdated += value; - - } - remove - { - if (Forms.UseFastLayout) - EvasFormsCanvas.LayoutUpdated -= value; - else - Canvas.LayoutUpdated -= value; - } - } - - /// - /// Handles the disposing of a ContentPage - /// - /// - /// Takes the proper care of discarding the canvas, then calls the base method. - /// - protected override void OnUnrealize() - { - _canvas.Unrealize(); - base.OnUnrealize(); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/RoundRectangle.cs b/src/Compatibility/Core/src/Tizen/Native/RoundRectangle.cs deleted file mode 100644 index ee8a65389b86..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/RoundRectangle.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System; -using System.Collections.Generic; -using ElmSharp; -using EPolygon = ElmSharp.Polygon; -using ERect = ElmSharp.Rect; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class RoundRectangle : EPolygon - { - readonly int[] _radius = new int[4]; - public RoundRectangle(EvasObject parent) : base(parent) - { - } - - public int X { get; set; } - public int Y { get; set; } - - public int Width { get; set; } - public int Height { get; set; } - - public void SetRadius(int r) - { - SetRadius(r, r, r, r); - } - - public void SetRadius(int topLeft, int topRight, int bottomLeft, int bottomRight) - { - _radius[0] = topLeft; - _radius[1] = topRight; - _radius[2] = bottomLeft; - _radius[3] = bottomRight; - } - - public IReadOnlyList GetRadius() - { - return _radius; - } - - public void Draw() - { - DrawPoints(); - } - - public void Draw(ERect bound) - { - X = bound.X; - Y = bound.Y; - Width = bound.Width; - Height = bound.Height; - Draw(); - // It is workaround for fix geometry issue - // A polygon make a margin of 1 pixel at the outermost point - Geometry = bound; - } - - - protected virtual void DrawPoints() - { - int[] radius = new int[4]; - int maxR = Math.Min(Width / 2, Height / 2); - radius[0] = Math.Min(_radius[0], maxR); - radius[1] = Math.Min(_radius[1], maxR); - radius[2] = Math.Min(_radius[2], maxR); - radius[3] = Math.Min(_radius[3], maxR); - - ClearPoints(); - for (int i = 0; i <= radius[0]; i++) - { - int x = i; - int dx = radius[0] - x; - int y = radius[0] - (int)Math.Sqrt((radius[0] * radius[0]) - (dx * dx)); - AddRelativePoint(x, y); - } - - AddRelativePoint(Width - radius[1], 0); - - for (int i = Width - radius[1]; i <= Width; i++) - { - int x = i; - int dx = radius[1] - (Width - x); - int y = radius[1] - (int)Math.Sqrt((radius[1] * radius[1]) - (dx * dx)); - AddRelativePoint(x, y); - } - - AddRelativePoint(Width, Height - radius[3]); - - for (int i = Width; i >= Width - radius[3]; i--) - { - int x = i; - int dx = radius[3] - (Width - x); - int y = Height - radius[3] + (int)Math.Sqrt((radius[3] * radius[3]) - (dx * dx)); - AddRelativePoint(x, y); - } - - AddRelativePoint(radius[2], Height); - - for (int i = radius[2]; i >= 0; i--) - { - int x = i; - int dx = radius[2] - x; - int y = Height - radius[2] + (int)Math.Sqrt((radius[2] * radius[2]) - (dx * dx)); - AddRelativePoint(x, y); - } - } - - protected void AddRelativePoint(int x, int y) - { - AddPoint(X + x, Y + y); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/Scroller.cs b/src/Compatibility/Core/src/Tizen/Native/Scroller.cs deleted file mode 100644 index 4bf9079b9eeb..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Scroller.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System.Threading.Tasks; -using ElmSharp; -using ERect = ElmSharp.Rect; -using EScroller = ElmSharp.Scroller; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class Scroller : EScroller - { - TaskCompletionSource _animationTaskComplateSource; - bool _isAnimation = false; - - public Scroller(EvasObject parent) : base(parent) - { - } - - protected Scroller() - { - } - - protected override void OnRealized() - { - base.OnRealized(); - new SmartEvent(this, RealHandle, ThemeConstants.Scroller.Signals.StartScrollAnimation).On += (s, e) => _isAnimation = true; - new SmartEvent(this, RealHandle, ThemeConstants.Scroller.Signals.StopScrollAnimation).On += (s, e) => - { - if (_animationTaskComplateSource != null) - { - _animationTaskComplateSource.TrySetResult(true); - } - _isAnimation = false; - }; - } - - void CheckTaskCompletionSource() - { - if (_animationTaskComplateSource != null) - { - if (_animationTaskComplateSource.Task.Status == TaskStatus.Running) - { - _animationTaskComplateSource.TrySetCanceled(); - } - } - _animationTaskComplateSource = new TaskCompletionSource(); - } - - public Task ScrollToAsync(int horizontalPageIndex, int verticalPageIndex, bool animated) - { - CheckTaskCompletionSource(); - ScrollTo(horizontalPageIndex, verticalPageIndex, animated); - return animated && _isAnimation ? _animationTaskComplateSource.Task : Task.CompletedTask; - } - - public Task ScrollToAsync(ERect rect, bool animated) - { - CheckTaskCompletionSource(); - ScrollTo(rect, animated); - return animated && _isAnimation ? _animationTaskComplateSource.Task : Task.CompletedTask; - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Native/SearchBar.cs b/src/Compatibility/Core/src/Tizen/Native/SearchBar.cs deleted file mode 100644 index c0259c563d5f..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/SearchBar.cs +++ /dev/null @@ -1,18 +0,0 @@ -using ElmSharp; -using EColor = ElmSharp.Color; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class SearchBar : Native.EditfieldEntry - { - public SearchBar(EvasObject parent) : base(parent) - { - EnableClearButton = true; - } - - public void SetClearButtonColor(EColor color) - { - ClearButtonColor = color; - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Native/Span.cs b/src/Compatibility/Core/src/Tizen/Native/Span.cs deleted file mode 100644 index 2b663171c96b..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Span.cs +++ /dev/null @@ -1,288 +0,0 @@ -using System; -using System.Text; -using EColor = ElmSharp.Color; -using Specific = Microsoft.Maui.Controls.PlatformConfiguration.TizenSpecific; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// Represent a text with attributes applied. - /// - public class Span - { - string _text; - - /// - /// Gets or sets the formatted text. - /// - public FormattedString FormattedText { get; set; } - - /// - /// Gets or sets the text. - /// - /// - /// Setting Text to a non-null value will set the FormattedText property to null. - /// - public string Text - { - get - { - if (FormattedText != null) - { - return FormattedText.ToString(); - } - else - { - return _text; - } - } - set - { - if (value == null) - { - value = ""; - } - else - { - FormattedText = null; - } - _text = value; - } - } - - /// - /// Gets or sets the color for the text. - /// - public EColor ForegroundColor { get; set; } - - /// - /// Gets or sets the background color for the text. - /// - public EColor BackgroundColor { get; set; } - - /// - /// Gets or sets the font family for the text. - /// - public string FontFamily { get; set; } - - /// - /// Gets or sets the font attributes for the text. - /// See for information about FontAttributes. - /// - public FontAttributes FontAttributes { get; set; } - - /// - /// Gets or sets the font size for the text. - /// - public double FontSize { get; set; } - - /// - /// Gets or sets the font weight for the text. - /// - public string FontWeight { get; set; } - - /// - /// Gets or sets the line height. - /// - public double LineHeight { get; set; } - - /// - /// Gets or sets the line break mode for the text. - /// See for information about LineBreakMode. - /// - public LineBreakMode LineBreakMode { get; set; } - - /// - /// Gets or sets the horizontal alignment mode for the text. - /// See for information about TextAlignment. - /// - public TextAlignment HorizontalTextAlignment { get; set; } - - /// - /// Gets or sets the value that indicates whether the text has underline. - /// - public bool Underline { get; set; } - - /// - /// Gets or sets the value that indicates whether the text has strike line though it. - /// - public bool Strikethrough { get; set; } - - /// - /// Create a new Span instance with default attributes. - /// - public Span() - { - Text = ""; - FontFamily = ""; - FontSize = -1; - FontWeight = Specific.FontWeight.None; - FontAttributes = FontAttributes.None; - ForegroundColor = EColor.Default; - BackgroundColor = EColor.Default; - HorizontalTextAlignment = TextAlignment.None; - LineBreakMode = LineBreakMode.None; - Underline = false; - Strikethrough = false; - LineHeight = -1.0d; - } - - /// - /// This method return marked up text - /// - internal string GetMarkupText() - { - StringBuilder sb = new StringBuilder(); - sb.Append(""); - sb.Append(GetDecoratedText()); - sb.Append(""); - return sb.ToString(); - } - - /// - /// This method return text decorated with markup if FormattedText is set or plain text otherwise. - /// - public string GetDecoratedText() - { - if (FormattedText != null) - { - return FormattedText.ToMarkupString(); - } - else - { - return ConvertTags(Text); - } - } - - StringBuilder PrepareFormattingString(StringBuilder _formattingString) - { - if (!ForegroundColor.IsDefault) - { - _formattingString.AppendFormat("color={0} ", ForegroundColor.ToHex()); - } - - if (!BackgroundColor.IsDefault) - { - _formattingString.AppendFormat("backing_color={0} backing=on ", BackgroundColor.ToHex()); - } - - if (!string.IsNullOrEmpty(FontFamily)) - { - _formattingString.AppendFormat("font={0} ", FontFamily); - } - - if (FontSize != -1) - { - _formattingString.AppendFormat("font_size={0} ", Forms.ConvertToEflFontPoint(FontSize)); - } - - if ((FontAttributes & FontAttributes.Bold) != 0) - { - _formattingString.Append("font_weight=Bold "); - } - else - { - // FontWeight is only available in case of FontAttributes.Bold is not used. - if (FontWeight != Specific.FontWeight.None) - { - _formattingString.AppendFormat("font_weight={0} ", FontWeight); - } - } - - if ((FontAttributes & FontAttributes.Italic) != 0) - { - _formattingString.Append("font_style=italic "); - } - - if (Underline) - { - _formattingString.AppendFormat("underline=on underline_color={0} ", - ForegroundColor.IsDefault ? ThemeConstants.Span.ColorClass.DefaultUnderLineColor.ToHex() : ForegroundColor.ToHex()); - } - - if (Strikethrough) - { - _formattingString.AppendFormat("strikethrough=on strikethrough_color={0} ", - ForegroundColor.IsDefault ? ThemeConstants.Span.ColorClass.DefaultUnderLineColor.ToHex() : ForegroundColor.ToHex()); - } - - switch (HorizontalTextAlignment) - { - case TextAlignment.Auto: - _formattingString.Append("align=auto "); - break; - - case TextAlignment.Start: - _formattingString.Append("align=left "); - break; - - case TextAlignment.End: - _formattingString.Append("align=right "); - break; - - case TextAlignment.Center: - _formattingString.Append("align=center "); - break; - - case TextAlignment.None: - break; - } - - if (LineHeight != -1.0d) - { - _formattingString.Append($"linerelsize={(int)(LineHeight * 100)}%"); - } - - switch (LineBreakMode) - { - case LineBreakMode.HeadTruncation: - _formattingString.Append("ellipsis=0.0"); - break; - - case LineBreakMode.MiddleTruncation: - _formattingString.Append("ellipsis=0.5"); - break; - - case LineBreakMode.TailTruncation: - _formattingString.Append("ellipsis=1.0"); - break; - case LineBreakMode.None: - break; - } - - return _formattingString; - } - - string ConvertTags(string text) - { - return text.Replace("&", "&", StringComparison.Ordinal) - .Replace("<", "<", StringComparison.Ordinal) - .Replace(">", ">", StringComparison.Ordinal) - .Replace(Environment.NewLine, "
", StringComparison.Ordinal); - } - - public string GetStyle() - { - StringBuilder sb = new StringBuilder(); - - sb.Append("DEFAULT='"); - - PrepareFormattingString(sb); - - sb.Append("'"); - - return sb.ToString(); - } - - /// - /// Converts string value to Span. - /// - /// The string text - public static implicit operator Span(string text) - { - return new Span { Text = text }; - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Native/TableView.cs b/src/Compatibility/Core/src/Tizen/Native/TableView.cs deleted file mode 100644 index 3b9621bf0bbb..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/TableView.cs +++ /dev/null @@ -1,71 +0,0 @@ -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// Extends the ListView class to provide TableView class implementation. - /// - [System.Obsolete] - public class TableView : ListView, ITableView - { - - static readonly SectionCellRenderer _sectionCellRenderer = new SectionCellRenderer(); - /// - /// Initializes a new instance of the TableView class. - /// - public TableView(EvasObject parent) - : base(parent) - { - } - - /// - /// Sets the root of the table. - /// - /// TableRoot, which is parent to one or more TableSections. - public void ApplyTableRoot(TableRoot root) - { - Clear(); - foreach (TableSection ts in root) - { - if (!string.IsNullOrEmpty(ts.Title)) - AddSectionTitle(ts.Title, ts.TextColor); - AddSource(ts); - } - } - - protected override CellRenderer GetCellRenderer(Cell cell, bool isGroup = false) - { - if (cell.GetType() == typeof(SectionCell)) - { - return _sectionCellRenderer; - } - return base.GetCellRenderer(cell, isGroup); - } - - /// - /// Sets the section title. - /// - void AddSectionTitle(string title, Graphics.Color textColor) - { - Cell cell = new SectionCell() - { - Text = title, - TextColor = textColor - }; - AddCell(cell); - } - - internal class SectionCellRenderer : TextCellRenderer - { - public SectionCellRenderer() : this(ThemeConstants.GenItemClass.Styles.GroupIndex) - { - } - - protected SectionCellRenderer(string style) : base(style) { } - } - class SectionCell : TextCell - { - } - } -} - diff --git a/src/Compatibility/Core/src/Tizen/Native/TextAlignment.cs b/src/Compatibility/Core/src/Tizen/Native/TextAlignment.cs deleted file mode 100644 index 8aec01734169..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/TextAlignment.cs +++ /dev/null @@ -1,30 +0,0 @@ -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// Enumerates values that describe alignemnt of text. - /// - public enum TextAlignment - { - /// - /// Follow base TextAlignment - /// - None, - - /// - /// Aligns horizontal text according to language. Top aligned for vertical text. - /// - Auto, - /// - /// Left and top aligned for horizontal and vertical text, respectively. - /// - Start, - /// - /// Right and bottom aligned for horizontal and vertical text, respectively. - /// - End, - /// - /// Center-aligned text. - /// - Center, - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/TextHelper.cs b/src/Compatibility/Core/src/Tizen/Native/TextHelper.cs deleted file mode 100644 index 6093d8ea87d8..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/TextHelper.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using ElmSharp; -using ELayout = ElmSharp.Layout; -using ESize = ElmSharp.Size; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - /// - /// The Text Helper contains functions that assist in working with text-able objects. - /// - public static class TextHelper - { - /// - /// Gets the size of raw text block. - /// - /// The with text part. - /// Returns the size of raw text block. - public static ESize GetRawTextBlockSize(EvasObject textable) - { - return GetElmTextPart(textable)?.TextBlockNativeSize ?? new ESize(0, 0); - } - - /// - /// Gets the size of formatted text block. - /// - /// The with text part. - /// Returns the size of formatted text block. - public static ESize GetFormattedTextBlockSize(EvasObject textable) - { - return GetElmTextPart(textable)?.TextBlockFormattedSize ?? new ESize(0, 0); - } - - /// - /// Gets the ELM text part of evas object. - /// - /// The with text part. - /// Requested instance. - /// Throws exception when parameter isn't text-able object or doesn't have ELM text part. - static EdjeTextPartObject GetElmTextPart(EvasObject textable) - { - ELayout widget = textable as ELayout; - if (widget == null) - { - Log.Error("textable should be ElmSharp.Layout"); - } - EdjeTextPartObject textPart = widget?.EdjeObject[ThemeConstants.Common.Parts.Text]; - if (textPart == null) - { - Log.Error("There is no elm.text part"); - } - return textPart; - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/TitleViewPage.cs b/src/Compatibility/Core/src/Tizen/Native/TitleViewPage.cs deleted file mode 100644 index 3697632d90e7..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/TitleViewPage.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - [Obsolete] - public class TitleViewPage : Native.Box - { - Native.Page _page = null; - View _titleView = null; - bool _hasNavigationBar = true; - - public TitleViewPage(EvasObject parent, Microsoft.Maui.Controls.Page page, View titleView) : base(parent) - { - _page = Platform.GetOrCreateRenderer(page).NativeView as Native.Page; - _titleView = titleView; - if (_titleView != null) - { - var renderer = Platform.GetOrCreateRenderer(_titleView); - (renderer as ILayoutRenderer)?.RegisterOnLayoutUpdated(); - - this.PackEnd(renderer.NativeView); - } - this.PackEnd(_page); - this.LayoutUpdated += OnLayoutUpdated; - } - - public bool HasNavigationBar - { - get - { - return _hasNavigationBar; - } - set - { - if (_hasNavigationBar != value) - { - _hasNavigationBar = value; - UpdatPageLayout(this, new LayoutEventArgs() { Geometry = this.Geometry }); - } - - } - } - - void OnLayoutUpdated(object sender, LayoutEventArgs e) - { - UpdatPageLayout(sender, e); - } - - void UpdatPageLayout(object sender, LayoutEventArgs e) - { - double dHeight = _titleView.Measure(Forms.ConvertToScaledDP(e.Geometry.Width), Forms.ConvertToScaledDP(e.Geometry.Height)).Request.Height; - int height = 0; - if (_hasNavigationBar) - { - height = Forms.ConvertToScaledPixel(dHeight); - } - - var renderer = Platform.GetOrCreateRenderer(_titleView); - renderer.NativeView.Move(e.Geometry.X, e.Geometry.Y); - renderer.NativeView.Resize(e.Geometry.Width, height); - - _page.Move(e.Geometry.X, e.Geometry.Y + height); - _page.Resize(e.Geometry.Width, e.Geometry.Height - height); - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Native/ToolbarItemButton.cs b/src/Compatibility/Core/src/Tizen/Native/ToolbarItemButton.cs deleted file mode 100644 index fd82e45019f2..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/ToolbarItemButton.cs +++ /dev/null @@ -1,177 +0,0 @@ -using System; -using System.ComponentModel; -using ElmSharp.Accessible; -using EColor = ElmSharp.Color; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class ToolbarItemButton : Button - { - ToolbarItem _item; - string _defaultAccessibilityName; - string _defaultAccessibilityDescription; - bool? _defaultIsAccessibilityElement; - - public ToolbarItemButton(ToolbarItem item) : base(Forms.NativeParent) - { - _item = item; - BackgroundColor = EColor.Transparent; - - Clicked += OnClicked; - Deleted += OnDeleted; - _item.PropertyChanged += OnToolbarItemPropertyChanged; - - UpdateText(); - UpdateIsEnabled(); - UpdateIcon(); - SetAccessibilityName(true); - SetAccessibilityDescription(true); - SetIsAccessibilityElement(true); - SetLabeledBy(true); - } - - void OnDeleted(object sender, EventArgs e) - { - Clicked -= OnClicked; - Deleted -= OnDeleted; - _item.PropertyChanged -= OnToolbarItemPropertyChanged; - } - - void OnClicked(object sender, EventArgs e) - { - ((IMenuItemController)_item).Activate(); - } - - void OnToolbarItemPropertyChanged(object sender, PropertyChangedEventArgs e) - { - if (e.PropertyName == ToolbarItem.TextProperty.PropertyName) - { - UpdateText(); - } - else if (e.PropertyName == ToolbarItem.IsEnabledProperty.PropertyName) - { - UpdateIsEnabled(); - } - else if (e.PropertyName == ToolbarItem.IconImageSourceProperty.PropertyName) - { - UpdateIcon(); - } - else if (e.PropertyName == AutomationProperties.NameProperty.PropertyName) - { - SetAccessibilityName(false); - } - else if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName) - { - SetAccessibilityDescription(false); - } - else if (e.PropertyName == AutomationProperties.IsInAccessibleTreeProperty.PropertyName) - { - SetIsAccessibilityElement(false); - } - else if (e.PropertyName == AutomationProperties.LabeledByProperty.PropertyName) - { - SetLabeledBy(false); - } - } - - void UpdateText() - { - UpdateStyle(); - Text = _item.Text; - } - - void UpdateIsEnabled() - { - IsEnabled = _item.IsEnabled; - } - - void UpdateIcon() - { - if (_item.IconImageSource.IsNullOrEmpty()) - { - //On 5.0, the part content should be removed before the style is changed, otherwise, EFL does not remove the part content. - Image = null; - UpdateStyle(); - } - else - { - // In reverse, the style should be set before setting the part content. - UpdateStyle(); - Native.Image iconImage = new Native.Image(Forms.NativeParent); - _ = iconImage.LoadFromImageSourceAsync(_item.IconImageSource); - Image = iconImage; - } - } - - void UpdateStyle() - { - if (_item.IconImageSource.IsNullOrEmpty()) - { - if (string.IsNullOrEmpty(_item.Text)) - { - // We assumed the default toolbar icon is "naviframe/drawer" if there are no icon and text. - this.SetNavigationDrawerStyle(); - } - else - { - if (_item.Order == ToolbarItemOrder.Primary) - this.SetNavigationTitleRightStyle(); - else - this.SetNavigationTitleLeftStyle(); - } - } - else - { - this.SetDefaultStyle(); - } - } - - void SetAccessibilityName(bool initialize) - { - if (initialize && (string)_item.GetValue(AutomationProperties.NameProperty) == (default(string))) - return; - - var accessibleObject = this as IAccessibleObject; - if (accessibleObject != null) - { - _defaultAccessibilityName = accessibleObject.SetAccessibilityName(_item, _defaultAccessibilityName); - } - } - - void SetAccessibilityDescription(bool initialize) - { - if (initialize && (string)_item.GetValue(AutomationProperties.HelpTextProperty) == (default(string))) - return; - - var accessibleObject = this as IAccessibleObject; - if (accessibleObject != null) - { - _defaultAccessibilityDescription = accessibleObject.SetAccessibilityDescription(_item, _defaultAccessibilityDescription); - } - } - - void SetIsAccessibilityElement(bool initialize) - { - if (initialize && (bool?)_item.GetValue(AutomationProperties.IsInAccessibleTreeProperty) == default(bool?)) - return; - - var accessibleObject = this as IAccessibleObject; - if (accessibleObject != null) - { - _defaultIsAccessibilityElement = accessibleObject.SetIsAccessibilityElement(_item, _defaultIsAccessibilityElement); - } - } - - void SetLabeledBy(bool initialize) - { - if (initialize && (VisualElement)_item.GetValue(AutomationProperties.LabeledByProperty) == default(VisualElement)) - return; - - var accessibleObject = this as IAccessibleObject; - if (accessibleObject != null) - { - accessibleObject.SetLabeledBy(_item); - } - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/Watch/FormsMoreOptionItem.cs b/src/Compatibility/Core/src/Tizen/Native/Watch/FormsMoreOptionItem.cs deleted file mode 100644 index 84a69fb5a665..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Watch/FormsMoreOptionItem.cs +++ /dev/null @@ -1,9 +0,0 @@ -using ElmSharp.Wearable; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native.Watch -{ - public class FormsMoreOptionItem : MoreOptionItem - { - public ToolbarItem ToolbarItem { get; set; } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/Watch/FormsWatchLayout.cs b/src/Compatibility/Core/src/Tizen/Native/Watch/FormsWatchLayout.cs deleted file mode 100644 index 9d2e9972cccc..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Watch/FormsWatchLayout.cs +++ /dev/null @@ -1,113 +0,0 @@ -using Microsoft.Maui.Devices; -using ElmSharp; -using EColor = ElmSharp.Color; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native.Watch -{ - public class FormsWatchLayout : FormsLayout - { - public FormsWatchLayout(EvasObject parent) : base(parent) - { - if (DeviceInfo.Idiom != DeviceIdiom.Watch) - Log.Error($"{0} is only supported on TargetIdiom.Watch : {1}", this, DeviceInfo.Idiom); - } - } - - public class DateTimeLayout : FormsWatchLayout - { - public class Styles - { - public const string Default = "datetime"; - } - - public class Parts - { - public const string ButtomButton = "elm.swallow.btn"; - } - - public DateTimeLayout(EvasObject parent, string style = Styles.Default) : base(parent) - { - SetTheme("layout", "circle", style); - } - - public bool SetBottomButtonPart(EvasObject content, bool preserveOldContent = false) - { - return SetPartContent(Parts.ButtomButton, content, preserveOldContent); - } - } - - public class PopupLayout : FormsWatchLayout - { - public class Parts - { - public const string Button1 = "button1"; - public const string Button2 = "button2"; - public const string Title = "elm.text.title"; - public const string Content = "elm.swallow.content"; - - public class Colors - { - public const string Title = "text_title"; - } - } - - public class Styles - { - public const string Circle = "content/circle"; - public const string Buttons2 = "content/circle/buttons2"; - } - - - public PopupLayout(EvasObject parent, string style) : base(parent) - { - SetTheme("layout", "popup", style); - } - - public bool SetTitleText(string title) - { - return SetPartText(Parts.Title, title); - } - - public void SetTitleColor(EColor color) - { - SetPartColor(Parts.Colors.Title, color); - } - } - - public class PopupClassBaseGroupLayout : FormsWatchLayout - { - public class Styles - { - public const string Circle = "circle"; - } - - public class Parts - { - public const string ActionArea = "elm.swallow.action_area"; - } - - public PopupClassBaseGroupLayout(EvasObject parent) : base(parent) - { - SetTheme("popup", "base", Styles.Circle); - } - } - - public class PopupClass2ButtonGroupLayout : FormsWatchLayout - { - public class Styles - { - public const string Circle = "popup/circle"; - } - - public class Parts - { - public const string Content = "elm.swallow.content"; - } - - public PopupClass2ButtonGroupLayout(EvasObject parent) : base(parent) - { - SetTheme("popup", "buttons2", Styles.Circle); - } - } - -} diff --git a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchButton.cs b/src/Compatibility/Core/src/Tizen/Native/Watch/WatchButton.cs deleted file mode 100644 index 6bde527a75fa..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchButton.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using ElmSharp; -using Microsoft.Maui.Controls.PlatformConfiguration.TizenSpecific; -using ESize = ElmSharp.Size; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native.Watch -{ - public class WatchButton : Button, IMeasurable - { - public WatchButton(EvasObject parent) : base(parent) - { - } - - public override ESize Measure(int availableWidth, int availableHeight) - { - if (Style == ButtonStyle.Default) - { - //Should gurantee the finger size (40) - MinimumWidth = MinimumWidth < 40 ? 40 : MinimumWidth; - if (Image != null) - MinimumWidth += Image.Geometry.Width; - var rawSize = this.GetTextBlockNativeSize(); - return new ESize(rawSize.Width + MinimumWidth, Math.Max(MinimumHeight, rawSize.Height)); - } - else - { - return new ESize(MinimumWidth, MinimumHeight); - } - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchDateTimePicker.cs b/src/Compatibility/Core/src/Tizen/Native/Watch/WatchDateTimePicker.cs deleted file mode 100644 index 40d5c2396dc7..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchDateTimePicker.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using ElmSharp; -using ElmSharp.Wearable; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native.Watch -{ - public class WatchDateTimePicker : CircleDateTimeSelector, IRotaryInteraction - { - DateTimePickerMode _mode; - - public IRotaryActionWidget RotaryWidget => this; - - public WatchDateTimePicker(EvasObject parent, CircleSurface surface) : base(parent, surface) - { - UpdateMode(); - } - - public DateTimePickerMode Mode - { - get - { - return _mode; - } - set - { - if (_mode != value) - { - _mode = value; - UpdateMode(); - } - } - } - - protected virtual void UpdateMode() - { - if (_mode == DateTimePickerMode.Date) - { - Style = ThemeConstants.CircleDateTimeSelector.Styles.CircleDatePicker; - Format = "%d/%b/%Y"; - } - else - { - Style = ThemeConstants.CircleDateTimeSelector.Styles.CircleTimePicker; - Format = "%d/%b/%Y %I:%M %p"; - } - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchDateTimePickerDialog.cs b/src/Compatibility/Core/src/Tizen/Native/Watch/WatchDateTimePickerDialog.cs deleted file mode 100644 index 891b0a6129a4..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchDateTimePickerDialog.cs +++ /dev/null @@ -1,136 +0,0 @@ -using System; -using ElmSharp; -using ElmSharp.Wearable; -using EButton = ElmSharp.Button; -using ELayout = ElmSharp.Layout; -using Specific = Microsoft.Maui.Controls.PlatformConfiguration.TizenSpecific.Application; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native.Watch -{ - public class WatchDateTimePickerDialog : Popup, IDateTimeDialog - { - ELayout _surfaceLayout; - DateTimeLayout _datetimeLayout; - CircleSurface _surface; - EButton _doneButton; - Box _container; - string _title; - WatchDateTimePicker _picker; - - public WatchDateTimePickerDialog(EvasObject parent) : base(parent) - { - this.SetWatchCircleStyle(); - AlignmentX = -1; - AlignmentY = -1; - WeightX = 1.0; - WeightY = 1.0; - - _container = new Box(parent) { AlignmentX = -1, AlignmentY = -1, WeightX = 1, WeightY = 1 }; - _container.BackgroundColor = ElmSharp.Color.Blue; - _container.SetLayoutCallback(OnContainerLayout); - - _datetimeLayout = new DateTimeLayout(parent); - _surfaceLayout = new ELayout(parent); - - _container.PackEnd(_datetimeLayout); - _container.PackEnd(_surfaceLayout); - - _surface = new CircleSurface(_surfaceLayout); - - _picker = new WatchDateTimePicker(parent, _surface); - _picker.Show(); - _datetimeLayout.SetContent(_picker); - - _doneButton = new Button(parent) - { - Text = "Set", - }; - _doneButton.SetBottomStyle(); - _datetimeLayout.SetBottomButtonPart(_doneButton); - _doneButton.Clicked += OnDoneClicked; - - ActivateRotaryInteraction(); - - _datetimeLayout.Show(); - _surfaceLayout.Show(); - _container.Show(); - - SetContent(_container); - ShowAnimationFinished += OnShowAnimationFinished; - BackButtonPressed += OnBackButtonPressed; - } - - public string Title - { - get => _title; - set - { - _title = value; - _datetimeLayout.SetTextPart(_title); - } - } - - public DateTimePickerMode Mode - { - get => _picker.Mode; - set => _picker.Mode = value; - } - - public DateTime MaximumDateTime - { - get => _picker.MaximumDateTime; - set => _picker.MaximumDateTime = value; - } - - public DateTime MinimumDateTime - { - get => _picker.MinimumDateTime; - set => _picker.MinimumDateTime = value; - } - - public DateTime DateTime - { - get => _picker.DateTime; - set => _picker.DateTime = value; - } - - public event EventHandler DateTimeChanged; - public event EventHandler PickerOpened; - public event EventHandler PickerClosed; - - protected virtual void ActivateRotaryInteraction() - { - if (_picker is IRotaryInteraction ri) - { - if (Specific.GetUseBezelInteraction(Application.Current)) - { - ri.RotaryWidget.Activate(); - } - } - } - - void OnContainerLayout() - { - _surfaceLayout.Geometry = _container.Geometry; - _datetimeLayout.Geometry = _container.Geometry; - } - - void OnDoneClicked(object sender, EventArgs e) - { - DateTimeChanged?.Invoke(this, new DateChangedEventArgs(_picker.DateTime)); - Hide(); - PickerClosed?.Invoke(this, EventArgs.Empty); - } - - void OnBackButtonPressed(object sender, EventArgs e) - { - Hide(); - PickerClosed?.Invoke(this, EventArgs.Empty); - } - - void OnShowAnimationFinished(object sender, EventArgs e) - { - PickerOpened?.Invoke(this, EventArgs.Empty); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchDialog.cs b/src/Compatibility/Core/src/Tizen/Native/Watch/WatchDialog.cs deleted file mode 100644 index d839aa023ee8..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchDialog.cs +++ /dev/null @@ -1,86 +0,0 @@ -using ElmSharp; -using EButton = ElmSharp.Button; -using EColor = ElmSharp.Color; -using ELayout = ElmSharp.Layout; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native.Watch -{ - public class WatchDialog : Dialog - { - ELayout _popupLayout; - bool _hasAcceptButton = false; - - /// - /// Creates a dialog window for watch - /// - public WatchDialog(EvasObject parent, bool hasAcceptButton) : base(parent) - { - this.SetWatchCircleStyle(); - _hasAcceptButton = hasAcceptButton; - _popupLayout = new PopupLayout(this, hasAcceptButton ? PopupLayout.Styles.Buttons2 : PopupLayout.Styles.Circle) - { - AlignmentX = -1, - AlignmentY = -1, - WeightX = 1, - WeightY = 1 - }; - _popupLayout.Show(); - SetContent(_popupLayout); - } - - protected override void ApplyButton(ButtonPosition position, EButton button) - { - - switch (position) - { - case ButtonPosition.Neutral: - this.SetButton2Part(button.SetWatchPopupRightStyle()); - break; - - case ButtonPosition.Negative: - if (_hasAcceptButton) - { - button.BackgroundColor = EColor.Default; - this.SetButton1Part(button.SetWatchPopupLeftStyle()); - } - else - { - button.BackgroundColor = new EColor(0, 47, 66, 255); - this.SetButton1Part(button.SetBottomStyle()); - } - break; - - case ButtonPosition.Positive: - default: - // Due to ux limiation, nothing to do - break; - } - } - - protected override void ApplyContent(EvasObject content) - { - _popupLayout.SetContent(content); - } - - protected override void ApplyTitle(string title) - { - if (_popupLayout is PopupLayout layout) - { - layout.SetTitleText(title); - } - } - - protected override void ApplyTitleColor(EColor color) - { - if (_popupLayout is PopupLayout layout) - { - layout.SetTitleColor(color); - } - } - - protected override void ApplyMessage(string message) - { - _popupLayout.SetTextPart(message); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchListView.cs b/src/Compatibility/Core/src/Tizen/Native/Watch/WatchListView.cs deleted file mode 100644 index c0a365e0a77f..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchListView.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using System.Collections; -using ElmSharp; -using ElmSharp.Wearable; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native.Watch -{ - [Obsolete] - public class WatchListView : Native.ListView, IRotaryActionWidget, IRotaryInteraction - { - CircleGenList _circleGenList; - CircleSurface _surface; - - public IntPtr CircleHandle => _circleGenList.CircleHandle; - - public CircleGenList CircleGenList => _circleGenList; - - public CircleSurface CircleSurface => _surface; - - public IRotaryActionWidget RotaryWidget { get => this; } - - GenItemClass _paddingItemClass; - protected GenItemClass PaddingItemTemplate => _paddingItemClass ?? (_paddingItemClass = new PaddingItemClass()); - - public override ScrollBarVisiblePolicy VerticalScrollBarVisibility - { - get => _circleGenList.VerticalScrollBarVisiblePolicy; - set => _circleGenList.VerticalScrollBarVisiblePolicy = value; - } - - public WatchListView(EvasObject parent, CircleSurface surface) - { - _surface = surface; - Realize(parent); - - Scroller = new CircleScrollerExtension(this); - Scroller.Scrolled += OnScrolled; - } - - protected override void UpdateHeader() - { - if (GetHeader() != null) - { - base.UpdateHeader(); - } - else - { - var paddingTemplate = PaddingItemTemplate; - if (!HasHeaderContext()) - { - InitializeHeaderItemContext(PaddingItemTemplate); - } - else - { - (HeaderItemContext.Item as GenListItem).UpdateItemClass(paddingTemplate, HeaderItemContext); - } - HeaderItemContext.Element = null; - } - } - - protected override void UpdateFooter() - { - if (GetFooter() != null) - { - base.UpdateFooter(); - } - else - { - var paddingTemplate = PaddingItemTemplate; - if (!HasFooterContext()) - { - InitializeFooterItemContext(PaddingItemTemplate); - } - else - { - (FooterItemContext.Item as GenListItem).UpdateItemClass(paddingTemplate, FooterItemContext); - } - FooterItemContext.Element = null; - } - } - - - protected override IntPtr CreateHandle(EvasObject parent) - { - _circleGenList = new CircleGenList(parent, _surface); - RealHandle = _circleGenList.RealHandle; - return _circleGenList.Handle; - } - - class PaddingItemClass : GenItemClass - { - public PaddingItemClass() : base(ThemeConstants.GenItemClass.Styles.Watch.Padding) - { - } - } - - class CircleScrollerExtension : CircleScroller - { - WatchListView _list; - - public override IntPtr CircleHandle => _list.CircleHandle; - - public CircleScrollerExtension(WatchListView parent) : base(parent, parent.CircleSurface) - { - _list = parent; - } - - protected override IntPtr CreateHandle(EvasObject parent) - { - return parent.RealHandle; - } - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchScroller.cs b/src/Compatibility/Core/src/Tizen/Native/Watch/WatchScroller.cs deleted file mode 100644 index b832a900f2e4..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchScroller.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using ElmSharp; -using ElmSharp.Wearable; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native.Watch -{ - public class WatchScroller : Native.Scroller, IRotaryActionWidget, IRotaryInteraction - { - CircleScroller _circleScroller; - CircleSurface _surface; - - public IntPtr CircleHandle => _circleScroller.CircleHandle; - - public CircleSurface CircleSurface => _surface; - - public CircleScroller CircleScroller => _circleScroller; - - public IRotaryActionWidget RotaryWidget { get => this; } - - public WatchScroller(EvasObject parent, CircleSurface surface) - { - _surface = surface; - Realize(parent); - - VerticalScrollBarVisiblePolicy = ScrollBarVisiblePolicy.Invisible; - HorizontalScrollBarVisiblePolicy = ScrollBarVisiblePolicy.Invisible; - } - - public override ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy - { - get => _circleScroller.VerticalScrollBarVisiblePolicy; - set => _circleScroller.VerticalScrollBarVisiblePolicy = value; - } - - public override ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy - { - get => _circleScroller.HorizontalScrollBarVisiblePolicy; - set => _circleScroller.HorizontalScrollBarVisiblePolicy = value; - } - - protected override IntPtr CreateHandle(EvasObject parent) - { - _circleScroller = new CircleScroller(parent, _surface); - RealHandle = _circleScroller.RealHandle; - return _circleScroller.Handle; - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchSpinner.cs b/src/Compatibility/Core/src/Tizen/Native/Watch/WatchSpinner.cs deleted file mode 100644 index 9cd011812a1c..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchSpinner.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using ElmSharp; -using ElmSharp.Wearable; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native.Watch -{ - public class WatchSpinner : CircleSpinner, IRotaryInteraction - { - SmartEvent _wheelAppeared, _wheelDisappeared; - - public event EventHandler WheelAppeared; - - public event EventHandler WheelDisappeared; - - public IRotaryActionWidget RotaryWidget { get => this; } - - public WatchSpinner(EvasObject parent, CircleSurface surface) : base(parent, surface) - { - Style = ThemeConstants.CircleSpinner.Styles.Circle; - _wheelAppeared = new SmartEvent(this, ThemeConstants.CircleSpinner.Signals.ShowList); - _wheelDisappeared = new SmartEvent(this, ThemeConstants.CircleSpinner.Signals.HideList); - - _wheelAppeared.On += (s, e) => WheelAppeared?.Invoke(this, EventArgs.Empty); - _wheelDisappeared.On += (s, e) => WheelDisappeared?.Invoke(this, EventArgs.Empty); - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchTableView.cs b/src/Compatibility/Core/src/Tizen/Native/Watch/WatchTableView.cs deleted file mode 100644 index 65ff1e120f6b..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/Watch/WatchTableView.cs +++ /dev/null @@ -1,66 +0,0 @@ -using ElmSharp; -using ElmSharp.Wearable; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native.Watch -{ - [System.Obsolete] - public class WatchTableView : WatchListView, ITableView - { - static readonly SectionCellRenderer _sectionCellRenderer = new SectionCellRenderer(); - - public WatchTableView(EvasObject parent, CircleSurface surface) : base(parent, surface) - { - } - - public void ApplyTableRoot(TableRoot root) - { - Clear(); - var cls = new PaddingItemClass(); - Append(cls, null); - foreach (TableSection ts in root) - { - if (!string.IsNullOrEmpty(ts.Title)) - AddSectionTitle(ts.Title, ts.TextColor); - AddSource(ts); - } - Append(cls, null); - } - - protected override CellRenderer GetCellRenderer(Cell cell, bool isGroup = false) - { - if (cell.GetType() == typeof(SectionCell)) - { - return _sectionCellRenderer; - } - return base.GetCellRenderer(cell, isGroup); - } - - void AddSectionTitle(string title, Graphics.Color textColor) - { - Cell cell = new SectionCell() - { - Text = title, - TextColor = textColor - }; - AddCell(cell); - } - - internal class SectionCellRenderer : TextCellRenderer - { - public SectionCellRenderer() : this(ThemeConstants.GenItemClass.Styles.GroupIndex) - { - } - protected SectionCellRenderer(string style) : base(style) { } - } - class SectionCell : TextCell - { - } - - class PaddingItemClass : GenItemClass - { - public PaddingItemClass() : base(ThemeConstants.GenItemClass.Styles.Watch.Padding) - { - } - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Native/WebViewContainer.cs b/src/Compatibility/Core/src/Tizen/Native/WebViewContainer.cs deleted file mode 100644 index 5ac6f676fd79..000000000000 --- a/src/Compatibility/Core/src/Tizen/Native/WebViewContainer.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using ElmSharp; -using TWebView = Tizen.WebView.WebView; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native -{ - public class WebViewContainer : WidgetLayout - { - public TWebView WebView { get; } - - public WebViewContainer(EvasObject parent) : base(parent) - { - WebView = new TWebView(parent); - SetContent(WebView); - AllowFocus(true); - Focused += OnFocused; - Unfocused += OnUnfocused; - } - - void OnFocused(object sender, EventArgs e) - { - WebView.SetFocus(true); - } - - void OnUnfocused(object sender, EventArgs e) - { - WebView.SetFocus(false); - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/NativeBindingService.cs b/src/Compatibility/Core/src/Tizen/NativeBindingService.cs index c5f4b2cb5fbf..d575dbf30615 100644 --- a/src/Compatibility/Core/src/Tizen/NativeBindingService.cs +++ b/src/Compatibility/Core/src/Tizen/NativeBindingService.cs @@ -1,7 +1,7 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.Maui.Controls.Xaml.Internals; -using EObject = ElmSharp.EvasObject; +using NView = Tizen.NUI.BaseComponents.View; namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen { @@ -11,7 +11,7 @@ class NativeBindingService : INativeBindingService public bool TrySetBinding(object target, string propertyName, BindingBase binding) { Hosting.MauiAppBuilderExtensions.CheckForCompatibility(); - var view = target as EObject; + var view = target as NView; if (view == null) return false; if (target.GetType().GetProperty(propertyName)?.GetMethod == null) @@ -23,7 +23,7 @@ public bool TrySetBinding(object target, string propertyName, BindingBase bindin public bool TrySetBinding(object target, BindableProperty property, BindingBase binding) { Hosting.MauiAppBuilderExtensions.CheckForCompatibility(); - var view = target as EObject; + var view = target as NView; if (view == null) return false; view.SetBinding(property, binding); @@ -33,7 +33,7 @@ public bool TrySetBinding(object target, BindableProperty property, BindingBase public bool TrySetValue(object target, BindableProperty property, object value) { Hosting.MauiAppBuilderExtensions.CheckForCompatibility(); - var view = target as EObject; + var view = target as NView; if (view == null) return false; view.SetValue(property, value); diff --git a/src/Compatibility/Core/src/Tizen/NativeValueConverterService.cs b/src/Compatibility/Core/src/Tizen/NativeValueConverterService.cs index 274b9cf5a5f7..392604340fc8 100644 --- a/src/Compatibility/Core/src/Tizen/NativeValueConverterService.cs +++ b/src/Compatibility/Core/src/Tizen/NativeValueConverterService.cs @@ -1,7 +1,7 @@ using System; using Microsoft.Maui.Controls.Xaml.Internals; -using EObject = ElmSharp.EvasObject; +using NUI = Tizen.NUI.BaseComponents.View; namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen { @@ -11,9 +11,9 @@ public bool ConvertTo(object value, Type toType, out object nativeValue) { Hosting.MauiAppBuilderExtensions.CheckForCompatibility(); nativeValue = null; - if ((value is EObject) && toType.IsAssignableFrom(typeof(View))) + if ((value is NUI) && toType.IsAssignableFrom(typeof(View))) { - nativeValue = ((EObject)value).ToView(); + nativeValue = ((NUI)value).ToView(); return true; } return false; diff --git a/src/Compatibility/Core/src/Tizen/NativeViewWrapper.cs b/src/Compatibility/Core/src/Tizen/NativeViewWrapper.cs index 3aee74595085..ed7d94018001 100644 --- a/src/Compatibility/Core/src/Tizen/NativeViewWrapper.cs +++ b/src/Compatibility/Core/src/Tizen/NativeViewWrapper.cs @@ -1,23 +1,23 @@ -using ElmSharp; -using ESize = ElmSharp.Size; +using Microsoft.Maui.Graphics; +using NView = Tizen.NUI.BaseComponents.View; namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen { - public delegate ESize? MeasureDelegate(NativeViewWrapperRenderer renderer, int availableWidth, int availableHeight); - #pragma warning disable CS0618 // Type or member is obsolete + public delegate Size? MeasureDelegate(NativeViewWrapperRenderer renderer, int availableWidth, int availableHeight); + public class NativeViewWrapper : View #pragma warning disable CS0618 // Type or member is obsolete { - public NativeViewWrapper(EvasObject obj, MeasureDelegate measureDelegate = null) + public NativeViewWrapper(NView obj, MeasureDelegate measureDelegate = null) { - EvasObject = obj; + NativeView = obj; MeasureDelegate = measureDelegate; obj.TransferBindablePropertiesToWrapper(this); } - public EvasObject EvasObject + public NView NativeView { get; private set; @@ -29,7 +29,7 @@ protected override void OnBindingContextChanged() { // TODO: we should provide a delegate to obtain children of a Container object, // however currently there is no way to get the list of children - EvasObject.SetBindingContext(BindingContext); + NativeView.SetBindingContext(BindingContext); base.OnBindingContextChanged(); } } diff --git a/src/Compatibility/Core/src/Tizen/PanGestureHandler.cs b/src/Compatibility/Core/src/Tizen/PanGestureHandler.cs deleted file mode 100644 index 8a3213fa1fc9..000000000000 --- a/src/Compatibility/Core/src/Tizen/PanGestureHandler.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.ComponentModel; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [Obsolete] - public class PanGestureHandler : GestureHandler - { - int _currentPanGestureId; - - public PanGestureHandler(IGestureRecognizer recognizer) : base(recognizer) - { - } - - public override GestureLayer.GestureType Type - { - get - { - return GestureLayer.GestureType.Momentum; - } - } - - protected override void OnStarted(View sender, object data) - { - _currentPanGestureId++; - (Recognizer as IPanGestureController)?.SendPanStarted(sender, _currentPanGestureId); - } - - protected override void OnMoved(View sender, object data) - { - var lineData = (GestureLayer.MomentumData)data; - (Recognizer as IPanGestureController)?.SendPan(sender, Forms.ConvertToScaledDP(lineData.X2 - lineData.X1), Forms.ConvertToScaledDP(lineData.Y2 - lineData.Y1), _currentPanGestureId); - } - - protected override void OnCompleted(View sender, object data) - { - (Recognizer as IPanGestureController)?.SendPanCompleted(sender, _currentPanGestureId); - } - - protected override void OnCanceled(View sender, object data) - { - (Recognizer as IPanGestureController)?.SendPanCanceled(sender, _currentPanGestureId); - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/PinchGestureHandler.cs b/src/Compatibility/Core/src/Tizen/PinchGestureHandler.cs deleted file mode 100644 index a5888f2935c0..000000000000 --- a/src/Compatibility/Core/src/Tizen/PinchGestureHandler.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.ComponentModel; -using ElmSharp; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [Obsolete] - public class PinchGestureHandler : GestureHandler - { - Graphics.Point _currentScalePoint; - int _previousPinchRadius; - double _originalPinchScale; - - public PinchGestureHandler(IGestureRecognizer recognizer) : base(recognizer) - { - } - - public override GestureLayer.GestureType Type - { - get - { - return GestureLayer.GestureType.Zoom; - } - } - - protected override void OnStarted(View sender, object data) - { - var geometry = Platform.GetRenderer(sender).NativeView.Geometry; - var zoomData = (GestureLayer.ZoomData)data; - _currentScalePoint = new Graphics.Point((zoomData.X - geometry.X) / (double)geometry.Width, (zoomData.Y - geometry.Y) / (double)geometry.Height); - _originalPinchScale = sender.Scale; - _previousPinchRadius = zoomData.Radius; - (Recognizer as IPinchGestureController)?.SendPinchStarted(sender, _currentScalePoint); - } - - protected override void OnMoved(View sender, object data) - { - var zoomData = (GestureLayer.ZoomData)data; - if (_previousPinchRadius <= 0) - _previousPinchRadius = 1; - // functionality limitation: _currentScalePoint is not updated - (Recognizer as IPinchGestureController)?.SendPinch(sender, - 1 + _originalPinchScale * (zoomData.Radius - _previousPinchRadius) / _previousPinchRadius, - _currentScalePoint - ); - _previousPinchRadius = zoomData.Radius; - } - - protected override void OnCompleted(View sender, object data) - { - (Recognizer as IPinchGestureController)?.SendPinchEnded(sender); - } - - protected override void OnCanceled(View sender, object data) - { - (Recognizer as IPinchGestureController)?.SendPinchCanceled(sender); - } - } -} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Platform.cs b/src/Compatibility/Core/src/Tizen/Platform.cs index 0ef8670bf924..423268c7d3e8 100644 --- a/src/Compatibility/Core/src/Tizen/Platform.cs +++ b/src/Compatibility/Core/src/Tizen/Platform.cs @@ -4,9 +4,9 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Threading.Tasks; -using ElmSharp; using Microsoft.Maui.Controls.Internals; -using Microsoft.Maui.Handlers; +using Tizen.UIExtensions.NUI; +using NView = Tizen.NUI.BaseComponents.View; [assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Material")] @@ -88,10 +88,6 @@ internal static IVisualElementRenderer CreateRenderer(VisualElement element) renderer = ver; else if (handler is IPlatformViewHandler vh) { - if (element.Parent is IView view && view.Handler is IPlatformViewHandler nvh) - { - vh.SetParent(nvh); - } renderer = new HandlerToRendererShim(vh); element.Handler = handler; } @@ -100,14 +96,9 @@ internal static IVisualElementRenderer CreateRenderer(VisualElement element) return renderer; } - internal static ITizenPlatform CreatePlatform(EvasObject parent) + internal static ITizenPlatform CreatePlatform() { - if (Forms.PlatformType == PlatformType.Lightweight) - { - return new LightweightPlatform(parent); - } - - return new DefaultPlatform(parent); + return new DefaultPlatform(); } public static SizeRequest GetNativeSize(VisualElement view, double widthConstraint, double heightConstraint) @@ -130,16 +121,9 @@ public interface ITizenPlatform : IDisposable { void SetPage(Page page); bool SendBackButtonPressed(); - EvasObject GetRootNativeView(); - bool HasAlpha { get; set; } - event EventHandler RootNativeViewChanged; - bool PageIsChildOfPlatform(Page page); - } + NView GetRootNativeView(); - public class RootNativeViewChangedEventArgs : EventArgs - { - public RootNativeViewChangedEventArgs(EvasObject view) => RootNativeView = view; - public EvasObject RootNativeView { get; private set; } + bool PageIsChildOfPlatform(Page page); } [Obsolete] @@ -147,28 +131,20 @@ public class DefaultPlatform : BindableObject, ITizenPlatform, INavigation { NavigationModel _navModel = new NavigationModel(); bool _disposed; - readonly Naviframe _internalNaviframe; + readonly NavigationStack _viewStack; readonly PopupManager _popupManager; - readonly HashSet _alerts = new HashSet(); + readonly Dictionary _pageMap = new Dictionary(); -#pragma warning disable 0067 - public event EventHandler RootNativeViewChanged; -#pragma warning restore 0067 - internal DefaultPlatform(EvasObject parent) + internal DefaultPlatform() { - Forms.NativeParent = parent; - - _internalNaviframe = new Naviframe(Forms.NativeParent) + _viewStack = new NavigationStack { - PreserveContentOnPop = true, - DefaultBackButtonEnabled = false, + BackgroundColor = global::Tizen.NUI.Color.White, + WidthResizePolicy = global::Tizen.NUI.ResizePolicyType.FillToParent, + HeightResizePolicy = global::Tizen.NUI.ResizePolicyType.FillToParent, }; - _internalNaviframe.SetAlignment(-1, -1); - _internalNaviframe.SetWeight(1.0, 1.0); - _internalNaviframe.Show(); - _internalNaviframe.AnimationFinished += NaviAnimationFinished; if (Forms.UseMessagingCenter) { @@ -183,11 +159,19 @@ internal DefaultPlatform(EvasObject parent) public Page Page { get; private set; } - public bool HasAlpha { get; set; } + Page CurrentPage + { + get + { + if (_viewStack.Top != null && _pageMap.ContainsKey(_viewStack.Top)) + { + return _pageMap[_viewStack.Top]; + } + return null; + } + } - Task CurrentModalNavigationTask { get; set; } - TaskCompletionSource CurrentTaskCompletionSource { get; set; } - IPageController CurrentPageController => _navModel.CurrentPage as IPageController; + IPageController CurrentPageController => CurrentPage; IReadOnlyList INavigation.ModalStack => _navModel.Modals.ToList(); IReadOnlyList INavigation.NavigationStack => new List(); @@ -201,69 +185,44 @@ public void SetPage(Page newRoot) { if (Page != null) { - var copyOfStack = new List(_internalNaviframe.NavigationStack); - for (var i = 0; i < copyOfStack.Count; i++) - { - copyOfStack[i].Delete(); - } - foreach (Page page in _navModel.Roots) + foreach (var child in _viewStack.Children.ToList()) { - var renderer = Platform.GetRenderer(page); - renderer?.Dispose(); + child.Dispose(); } - _navModel = new NavigationModel(); + _viewStack.Clear(); + _pageMap.Clear(); } + _navModel = new NavigationModel(); if (newRoot == null) return; + Page = newRoot; _navModel.Push(newRoot, null); - Page = newRoot; + ((Application)Page.RealParent).NavigationProxy.Inner = this; IVisualElementRenderer pageRenderer = Platform.CreateRenderer(Page); - var naviItem = _internalNaviframe.Push(pageRenderer.NativeView); - naviItem.TitleBarVisible = false; + _pageMap[pageRenderer.NativeView] = newRoot; + _viewStack.Push(pageRenderer.NativeView, false); - // Make naviitem transparent if parent window is transparent. - // Make sure that this is only for _navModel._naviTree. (not for _navModel._modalStack) - // In addtion, the style of naviItem is only decided before the naviItem pushed into Naviframe. (not on-demand). - if (HasAlpha) - { - naviItem.Style = "default/transparent"; - } - - ((Application)Page.RealParent).NavigationProxy.Inner = this; - - Application.Current.Dispatcher.DispatchDelayed(TimeSpan.Zero, () => CurrentPageController?.SendAppearing()); + Application.Current.Dispatcher.Dispatch(() => CurrentPageController?.SendAppearing()); } public bool SendBackButtonPressed() { - bool handled = false; - if (_navModel.CurrentPage != null) - { - if (CurrentModalNavigationTask != null && !CurrentModalNavigationTask.IsCompleted) - { - handled = true; - } - else - { - handled = _navModel.CurrentPage.SendBackButtonPressed(); - } - } - return handled; + return _navModel.CurrentPage?.SendBackButtonPressed() ?? false; } - public EvasObject GetRootNativeView() + public NView GetRootNativeView() { - return _internalNaviframe as EvasObject; + return _viewStack; } public bool PageIsChildOfPlatform(Page page) { var parent = page.AncestorToRoot(); - return Page == parent || _navModel.Roots.Contains(parent); + return _navModel.Modals.FirstOrDefault() == page || _navModel.Roots.Contains(parent); } protected virtual void Dispose(bool disposing) @@ -274,7 +233,8 @@ protected virtual void Dispose(bool disposing) { _popupManager?.Dispose(); SetPage(null); - _internalNaviframe.Unrealize(); + _viewStack.Unparent(); + _viewStack.Dispose(); } _disposed = true; } @@ -333,15 +293,14 @@ Task INavigation.PushModalAsync(Page modal) async Task INavigation.PushModalAsync(Page modal, bool animated) { var previousPage = CurrentPageController; - Application.Current.Dispatcher.Dispatch(() => previousPage?.SendDisappearing()); + previousPage?.SendDisappearing(); _navModel.PushModal(modal); - await PushModalInternal(modal, animated); - - // Verify that the modal is still on the stack - if (_navModel.CurrentPage == modal) - CurrentPageController.SendAppearing(); + var renderer = Platform.GetOrCreateRenderer(modal); + _pageMap[renderer.NativeView] = modal; + await _viewStack.Push(renderer.NativeView, animated); + CurrentPageController.SendAppearing(); } Task INavigation.PopModalAsync() @@ -351,95 +310,19 @@ Task INavigation.PopModalAsync() async Task INavigation.PopModalAsync(bool animated) { - Page modal = _navModel.PopModal(); + Page page = _navModel.PopModal(); + (page as IPageController)?.SendDisappearing(); - IVisualElementRenderer modalRenderer = Platform.GetRenderer(modal); - if (modalRenderer != null) - { - await PopModalInternal(animated); - modalRenderer.Dispose(); - } + IVisualElementRenderer modalRenderer = Platform.GetRenderer(page); - CurrentPageController?.SendAppearing(); - return modal; - } - - async Task PushModalInternal(Page modal, bool animated) - { - TaskCompletionSource tcs = null; - if (CurrentModalNavigationTask != null && !CurrentModalNavigationTask.IsCompleted) - { - var previousTask = CurrentModalNavigationTask; - tcs = new TaskCompletionSource(); - CurrentModalNavigationTask = tcs.Task; - await previousTask; - } - - var after = _internalNaviframe.NavigationStack.LastOrDefault(); - NaviItem pushed = null; - if (animated || after == null) - { - pushed = _internalNaviframe.Push(Platform.GetOrCreateRenderer(modal).NativeView, modal.Title); - } - else - { - pushed = _internalNaviframe.InsertAfter(after, Platform.GetOrCreateRenderer(modal).NativeView, modal.Title); - } - pushed.TitleBarVisible = false; - - bool shouldWait = animated && after != null; - await WaitForCompletion(shouldWait, tcs); - } - - async Task PopModalInternal(bool animated) - { - TaskCompletionSource tcs = null; - if (CurrentModalNavigationTask != null && !CurrentModalNavigationTask.IsCompleted) - { - var previousTask = CurrentModalNavigationTask; - tcs = new TaskCompletionSource(); - CurrentModalNavigationTask = tcs.Task; - await previousTask; - } + await _viewStack.Pop(animated); + _pageMap.Remove(modalRenderer.NativeView); - if (animated) - { - _internalNaviframe.Pop(); - } - else - { - _internalNaviframe.NavigationStack.LastOrDefault()?.Delete(); - } + modalRenderer?.Dispose(); - bool shouldWait = animated && (_internalNaviframe.NavigationStack.Count != 0); - await WaitForCompletion(shouldWait, tcs); - } - - async Task WaitForCompletion(bool shouldWait, TaskCompletionSource tcs) - { - if (shouldWait) - { - tcs = tcs ?? new TaskCompletionSource(); - CurrentTaskCompletionSource = tcs; - if (CurrentModalNavigationTask == null || CurrentModalNavigationTask.IsCompleted) - { - CurrentModalNavigationTask = CurrentTaskCompletionSource.Task; - } - } - else - { - tcs?.SetResult(true); - } - - if (tcs != null) - await tcs.Task; - } + CurrentPageController?.SendAppearing(); - void NaviAnimationFinished(object sender, EventArgs e) - { - var tcs = CurrentTaskCompletionSource; - CurrentTaskCompletionSource = null; - tcs?.SetResult(true); + return page; } } } diff --git a/src/Compatibility/Core/src/Tizen/PopupManager.cs b/src/Compatibility/Core/src/Tizen/PopupManager.cs index e726c5f39294..1a0d5a2ae5a6 100644 --- a/src/Compatibility/Core/src/Tizen/PopupManager.cs +++ b/src/Compatibility/Core/src/Tizen/PopupManager.cs @@ -1,14 +1,5 @@ using System; -using System.Collections.Generic; -using ElmSharp; using Microsoft.Maui.Controls.Internals; -using Microsoft.Maui.Controls.PlatformConfiguration.TizenSpecific; -using Microsoft.Maui.Devices; -using EButton = ElmSharp.Button; -using EColor = ElmSharp.Color; -using EProgressBar = ElmSharp.ProgressBar; -using Color = Microsoft.Maui.Graphics.Color; -using XStackLayout = Microsoft.Maui.Controls.StackLayout; namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen { @@ -16,9 +7,6 @@ namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen public class PopupManager : IDisposable { ITizenPlatform _platform; - Native.Dialog _pageBusyDialog; - int _pageBusyCount; - readonly HashSet _alerts = new HashSet(); public PopupManager(ITizenPlatform platform) { @@ -50,42 +38,7 @@ void OnBusySetRequest(Page sender, bool enabled) // Verify that the page making the request is child of this platform if (!_platform.PageIsChildOfPlatform(sender)) return; - - if (null == _pageBusyDialog) - { - _pageBusyDialog = new Native.Dialog(Forms.NativeParent) - { - Orientation = PopupOrientation.Center, - BackgroundColor = EColor.Transparent - }; - - if (DeviceInfo.Idiom == DeviceIdiom.Phone) - { - _pageBusyDialog.SetTitleBackgroundColor(EColor.Transparent); - _pageBusyDialog.SetContentBackgroundColor(EColor.Transparent); - } - else if (DeviceInfo.Idiom == DeviceIdiom.Watch) - { - _pageBusyDialog.SetWatchCircleStyle(); - } - - var activity = new EProgressBar(_pageBusyDialog) { IsPulseMode = true }.SetLargeStyle(); - activity.PlayPulse(); - activity.Show(); - - _pageBusyDialog.Content = activity; - - } - _pageBusyCount = Math.Max(0, enabled ? _pageBusyCount + 1 : _pageBusyCount - 1); - if (_pageBusyCount > 0) - { - _pageBusyDialog.Show(); - } - else - { - _pageBusyDialog.Dismiss(); - _pageBusyDialog = null; - } + // TODO. show busy popup } void OnAlertRequest(Page sender, AlertArguments arguments) @@ -93,41 +46,7 @@ void OnAlertRequest(Page sender, AlertArguments arguments) // Verify that the page making the request is child of this platform if (!_platform.PageIsChildOfPlatform(sender)) return; - - var alert = Native.Dialog.CreateDialog(Forms.NativeParent, (arguments.Accept != null)); - - alert.Title = arguments.Title; - var message = arguments.Message?.Replace("&", "&", StringComparison.Ordinal).Replace("<", "<", StringComparison.Ordinal).Replace(">", ">", StringComparison.Ordinal).Replace(Environment.NewLine, "
", StringComparison.Ordinal); - alert.Message = message; - - var cancel = new EButton(alert) { Text = arguments.Cancel }; - alert.NegativeButton = cancel; - cancel.Clicked += (s, evt) => - { - arguments.SetResult(false); - alert.Dismiss(); - }; - - if (arguments.Accept != null) - { - var ok = new EButton(alert) { Text = arguments.Accept }; - alert.NeutralButton = ok; - ok.Clicked += (s, evt) => - { - arguments.SetResult(true); - alert.Dismiss(); - }; - } - - alert.BackButtonPressed += (s, evt) => - { - arguments.SetResult(false); - alert.Dismiss(); - }; - - alert.Show(); - _alerts.Add(alert); - alert.Dismissed += (s, e) => _alerts.Remove(alert); + // TODO. Show alert popup } void OnActionSheetRequest(Page sender, ActionSheetArguments arguments) @@ -135,72 +54,7 @@ void OnActionSheetRequest(Page sender, ActionSheetArguments arguments) // Verify that the page making the request is child of this platform if (!_platform.PageIsChildOfPlatform(sender)) return; - - var alert = Native.Dialog.CreateDialog(Forms.NativeParent); - - alert.Title = arguments.Title; - var box = new Box(alert); - - if (null != arguments.Destruction) - { - var destruction = new Native.Button(alert) - { - Text = arguments.Destruction, - AlignmentX = -1 - }; - destruction.SetWatchTextStyle(); - //TextColor should be set after applying style - destruction.TextColor = EColor.Red; - - destruction.Clicked += (s, evt) => - { - arguments.SetResult(arguments.Destruction); - alert.Dismiss(); - }; - destruction.Show(); - box.PackEnd(destruction); - } - - foreach (string buttonName in arguments.Buttons) - { - var button = new Native.Button(alert) - { - Text = buttonName, - AlignmentX = -1 - }; - button.SetWatchTextStyle(); - - button.Clicked += (s, evt) => - { - arguments.SetResult(buttonName); - alert.Dismiss(); - }; - button.Show(); - box.PackEnd(button); - } - - box.Show(); - alert.Content = box; - - if (null != arguments.Cancel) - { - var cancel = new EButton(Forms.NativeParent) { Text = arguments.Cancel }; - alert.NegativeButton = cancel; - cancel.Clicked += (s, evt) => - { - alert.Dismiss(); - }; - } - - alert.BackButtonPressed += (s, evt) => - { - alert.Dismiss(); - }; - - alert.Show(); - - _alerts.Add(alert); - alert.Dismissed += (s, e) => _alerts.Remove(alert); + // TODO. Show action sheet popup } void OnPromptRequested(Page sender, PromptArguments args) @@ -209,91 +63,7 @@ void OnPromptRequested(Page sender, PromptArguments args) if (!_platform.PageIsChildOfPlatform(sender)) return; - var prompt = Native.Dialog.CreateDialog(Forms.NativeParent, (args.Accept != null)); - prompt.Title = args.Title; - - var entry = new Entry - { - MinimumWidthRequest = 200, - HorizontalOptions = LayoutOptions.Fill, - BackgroundColor = Color.FromRgb(250, 250, 250), - TextColor = Color.FromRgb(0, 0, 0), - Keyboard = args.Keyboard, - }; - - if (!string.IsNullOrEmpty(args.Placeholder)) - { - entry.Placeholder = args.Placeholder; - } - if (args.MaxLength > 0) - { - entry.MaxLength = args.MaxLength; - } - - var layout = new XStackLayout - { - Spacing = 10, - Children = - { - new Label - { - LineBreakMode = LineBreakMode.CharacterWrap, - TextColor = DeviceInfo.Idiom == DeviceIdiom.Watch ? Color.FromRgb(255,255,255) : Application.AccentColor, - Text = args.Message, - HorizontalOptions = LayoutOptions.Fill, - HorizontalTextAlignment = TextAlignment.Center, -#pragma warning disable CS0612 // Type or member is obsolete - FontSize = Device.GetNamedSize(NamedSize.Subtitle, typeof(Label)), -#pragma warning disable CS0612 // Type or member is obsolete - }, - entry, - } - }; - - layout.Parent = sender; - var layoutrenderer = Platform.GetOrCreateRenderer(layout); - - var request = layout.Measure(DeviceInfo.Idiom == DeviceIdiom.Watch ? sender.Width * 0.7 : sender.Width, sender.Height); - (layoutrenderer as ILayoutRenderer).RegisterOnLayoutUpdated(); - layoutrenderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(request.Request.Height); - layoutrenderer.NativeView.MinimumWidth = Forms.ConvertToScaledPixel(request.Request.Width); - - prompt.Content = layoutrenderer.NativeView; - - var cancel = new EButton(prompt) { Text = args.Cancel }; - prompt.NegativeButton = cancel; - cancel.Clicked += (s, evt) => - { - args.SetResult(null); - prompt.Dismiss(); - }; - - if (args.Accept != null) - { - var ok = new EButton(prompt) { Text = args.Accept }; - prompt.NeutralButton = ok; - ok.Clicked += (s, evt) => - { - args.SetResult(entry.Text); - prompt.Dismiss(); - }; - } - - entry.Completed += (s, e) => - { - args.SetResult(entry.Text); - prompt.Dismiss(); - }; - - prompt.BackButtonPressed += (s, evt) => - { - prompt.Dismiss(); - }; - - prompt.Show(); - - _alerts.Add(prompt); - prompt.Dismissed += (s, e) => _alerts.Remove(prompt); + // TODO prompt popup } } diff --git a/src/Compatibility/Core/src/Tizen/PreloadedWindow.cs b/src/Compatibility/Core/src/Tizen/PreloadedWindow.cs deleted file mode 100644 index baa8aadf2f2e..000000000000 --- a/src/Compatibility/Core/src/Tizen/PreloadedWindow.cs +++ /dev/null @@ -1,43 +0,0 @@ -using ElmSharp; -using Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native; -using ELayout = ElmSharp.Layout; -using EWindow = ElmSharp.Window; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - public class PreloadedWindow : EWindow - { - static PreloadedWindow s_precreated; - - public PreloadedWindow() : base("FormsWindow-pre") - { - s_precreated = this; - Initialize(); - } - - public ELayout BaseLayout - { - get; - protected set; - } - - protected void Initialize() - { - var conformant = new Conformant(this); - conformant.Show(); - - var layout = new ApplicationLayout(conformant); - layout.Show(); - - BaseLayout = layout; - conformant.SetContent(BaseLayout); - } - - public static PreloadedWindow GetInstance() - { - var instance = s_precreated; - s_precreated = null; - return instance; - } - } -} diff --git a/src/Compatibility/Core/src/Tizen/Properties/AssemblyInfo.cs b/src/Compatibility/Core/src/Tizen/Properties/AssemblyInfo.cs index 54f1710e1f6e..08f186324624 100644 --- a/src/Compatibility/Core/src/Tizen/Properties/AssemblyInfo.cs +++ b/src/Compatibility/Core/src/Tizen/Properties/AssemblyInfo.cs @@ -3,4 +3,4 @@ [assembly: Preserve] [assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Compatibility.Platform")] -[assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Compatibility.Material")] \ No newline at end of file +[assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Compatibility.Material")] diff --git a/src/Compatibility/Core/src/Tizen/Renderers/ActivityIndicatorRenderer.cs b/src/Compatibility/Core/src/Tizen/Renderers/ActivityIndicatorRenderer.cs deleted file mode 100644 index 42f7488c34d8..000000000000 --- a/src/Compatibility/Core/src/Tizen/Renderers/ActivityIndicatorRenderer.cs +++ /dev/null @@ -1,58 +0,0 @@ -using Microsoft.Maui.Controls.Platform; -using EColor = ElmSharp.Color; -using EProgressBar = ElmSharp.ProgressBar; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [System.Obsolete(Compatibility.Hosting.MauiAppBuilderExtensions.UseMapperInstead)] - public class ActivityIndicatorRenderer : ViewRenderer - { - static readonly EColor s_defaultColor = ThemeConstants.ProgressBar.ColorClass.Default; - - public ActivityIndicatorRenderer() - { - RegisterPropertyHandler(ActivityIndicator.ColorProperty, UpdateColor); - RegisterPropertyHandler(ActivityIndicator.IsRunningProperty, UpdateIsRunning); - } - - protected override void OnElementChanged(ElementChangedEventArgs e) - { - if (Control == null) - { - SetNativeControl(new EProgressBar(Forms.NativeParent) - { - IsPulseMode = true, - } - .SetSmallStyle()); - } - base.OnElementChanged(e); - } - - void UpdateColor(bool initialize) - { - if (initialize && Element.Color.IsDefault()) - return; - - Control.Color = (Element.Color.IsDefault()) ? s_defaultColor : Element.Color.ToNative(); - } - - void UpdateIsRunning() - { - if (Element.IsRunning && Element.IsEnabled) - { - Control.PlayPulse(); - } - else - { - Control.StopPulse(); - } - } - - protected override void UpdateIsEnabled(bool initialize) - { - base.UpdateIsEnabled(initialize); - UpdateIsRunning(); - } - - }; -} diff --git a/src/Compatibility/Core/src/Tizen/Renderers/BoxViewRenderer.cs b/src/Compatibility/Core/src/Tizen/Renderers/BoxViewRenderer.cs index 9823e21fb147..cd7fae1bd551 100644 --- a/src/Compatibility/Core/src/Tizen/Renderers/BoxViewRenderer.cs +++ b/src/Compatibility/Core/src/Tizen/Renderers/BoxViewRenderer.cs @@ -1,96 +1,38 @@ -using System.ComponentModel; +using NView = Tizen.NUI.BaseComponents.View; +using Tizen.UIExtensions.NUI; using Microsoft.Maui.Controls.Platform; -using Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native; -using EColor = ElmSharp.Color; namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen { [System.Obsolete(Compatibility.Hosting.MauiAppBuilderExtensions.UseMapperInstead)] - public class BoxViewRenderer : ViewRenderer + public class BoxViewRenderer : ViewRenderer { public BoxViewRenderer() { RegisterPropertyHandler(nameof(Element.CornerRadius), OnRadiusUpdate); + RegisterPropertyHandler(nameof(Element.Color), UpdateColor); } protected override void OnElementChanged(ElementChangedEventArgs e) { if (Control == null) { - SetNativeControl(new RoundRectangle(Forms.NativeParent)); + SetNativeControl(new NView()); } - - UpdateColor(); base.OnElementChanged(e); } - - protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) - { - if (e.PropertyName == BoxView.ColorProperty.PropertyName) - { - UpdateColor(); - } - base.OnElementPropertyChanged(sender, e); - } - - protected override void UpdateBackgroundColor(bool initialize) - { - if (initialize && Element.BackgroundColor.IsDefault()) - return; - - if (Element.Color.IsDefault()) - { - UpdateColor(); - } - } - - protected override void UpdateLayout() + void OnRadiusUpdate() { - base.UpdateLayout(); - Control.Draw(Control.Geometry); + int topLeft = Forms.ConvertToScaledPixel(Element.CornerRadius.TopLeft); + Control.CornerRadius = topLeft; } - protected override void UpdateOpacity(bool initialize) + void UpdateColor(bool init) { - if (initialize && Element.Opacity == 1d) + if (init && Element.Color.IsDefault()) return; - UpdateColor(); - } - - void OnRadiusUpdate(bool init) - { - int topLeft = Forms.ConvertToScaledPixel(Element.CornerRadius.TopLeft); - int topRight = Forms.ConvertToScaledPixel(Element.CornerRadius.TopRight); - int bottomLeft = Forms.ConvertToScaledPixel(Element.CornerRadius.BottomLeft); - int bottomRight = Forms.ConvertToScaledPixel(Element.CornerRadius.BottomRight); - Control.SetRadius(topLeft, topRight, bottomLeft, bottomRight); - if (!init) - { - Control.Draw(); - } - } - - void UpdateColor() - { - if (Element.Color.IsDefault()) - { - if (Element.BackgroundColor.IsDefault()) - { - // Set to default color. (Transparent) - Control.Color = EColor.Transparent; - } - else - { - // Use BackgroundColor only if color is default and background color is not default. - Control.Color = Element.BackgroundColor.MultiplyAlpha((float)Element.Opacity).ToNative(); - } - } - else - { - // Color has higer priority than BackgroundColor. - Control.Color = Element.Color.MultiplyAlpha((float)Element.Opacity).ToNative(); - } + Control.UpdateBackgroundColor(!Element.Color.IsDefault() ? Element.Color.ToNative() : Element.BackgroundColor.ToNative()); } } } \ No newline at end of file diff --git a/src/Compatibility/Core/src/Tizen/Renderers/ButtonRenderer.cs b/src/Compatibility/Core/src/Tizen/Renderers/ButtonRenderer.cs deleted file mode 100644 index 8933fb8cfb30..000000000000 --- a/src/Compatibility/Core/src/Tizen/Renderers/ButtonRenderer.cs +++ /dev/null @@ -1,172 +0,0 @@ -using System; -using Microsoft.Maui.Graphics; -using Microsoft.Maui.Controls.Platform; -using Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native; -using Microsoft.Maui.Devices; -using NIButton = Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Native.IButton; -using EButton = ElmSharp.Button; -using Specific = Microsoft.Maui.Controls.PlatformConfiguration.TizenSpecific.VisualElement; - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - [System.Obsolete(Compatibility.Hosting.MauiAppBuilderExtensions.UseMapperInstead)] - public class ButtonRenderer : ViewRenderer - { - public ButtonRenderer() - { - RegisterPropertyHandler(Button.TextProperty, UpdateText); - RegisterPropertyHandler(Button.FontFamilyProperty, UpdateFontFamily); - RegisterPropertyHandler(Button.FontSizeProperty, UpdateFontSize); - RegisterPropertyHandler(Button.FontAttributesProperty, UpdateFontAttributes); - RegisterPropertyHandler(Button.TextColorProperty, UpdateTextColor); - RegisterPropertyHandler(Button.ImageSourceProperty, UpdateBitmap); - RegisterPropertyHandler(Button.BorderColorProperty, UpdateBorder); - RegisterPropertyHandler(Button.CornerRadiusProperty, UpdateBorder); - RegisterPropertyHandler(Button.BorderWidthProperty, UpdateBorder); - } - - protected override void OnElementChanged(ElementChangedEventArgs