From c4e038af47fbfa56cc927adcdc3e7ca9269adcb4 Mon Sep 17 00:00:00 2001 From: Kangho Hur Date: Thu, 23 Sep 2021 21:07:36 +0900 Subject: [PATCH] Bump to latest (rc1) - ImageButtonHandler and Handler Re-usability (#2352) - Remove IBoxView (#2619) - Add SupportedOSPlatformVersion (#2565) - Merge all the .NET 6 projects/solutions (#2505) - Shadow Support (#570) - Add IndicatorView handler(#2038) --- ...ui.Tizen.sln => ._Microsoft.Maui.Tizen.sln | 0 ...osoft.Maui.Controls.MultiTargeting.targets | 4 +- Directory.Build.props | 2 +- .../Core/Platform/Tizen/DragGestureHandler.cs | 2 +- .../Platform/Tizen/Shell/ShellItemView.cs | 2 +- .../Core/Platform/Tizen/Shell/ShellNavBar.cs | 2 +- .../Handlers/BoxView/BoxViewHandler.Tizen.cs | 25 -------- .../Handlers/Button/ButtonHandler.Tizen.cs | 38 ++++++++---- src/Core/src/Handlers/Button/ButtonHandler.cs | 4 +- .../src/Handlers/Button/IButtonHandler.cs | 6 +- src/Core/src/Handlers/Image/IImageHandler.cs | 4 +- .../src/Handlers/Image/ImageHandler.Tizen.cs | 28 +++++---- src/Core/src/Handlers/Image/ImageHandler.cs | 8 ++- .../ImageButton/ImageButtonHandler.Tizen.cs | 19 ++++++ .../ImageButton/ImageButtonHandler.cs | 9 ++- .../IndicatorViewHandler.Tizen.cs | 60 ++++++++++++++++++ .../NavigationViewHandler.Tizen.cs | 2 +- .../FileImageSourceService.Tizen.cs | 13 ++-- .../FontImageSourceService.Tizen.cs | 13 ++-- .../src/ImageSources/IImageSourceService.cs | 2 +- .../src/ImageSources/ImageSourceExtensions.cs | 7 ++- .../src/ImageSources/ImageSourceService.cs | 2 +- .../ImageSources/ImageSourceServiceResult.cs | 4 +- .../StreamImageSourceService.Tizen.cs | 12 ++-- .../Tizen/ImageSourceServiceResult.cs | 39 ------------ .../UriImageSourceService.Tizen.cs | 12 ++-- .../src/Platform/ImageSourcePartLoader.cs | 7 ++- .../src/Platform/Tizen/BoxViewExtensions.cs | 12 ---- .../src/Platform/Tizen/ButtonExtensions.cs | 4 +- .../src/Platform/Tizen/ImageExtensions.cs | 61 +++++++++++++++++-- .../Tizen/MauiIndicatorViewExtensions.cs | 20 ++++++ src/Core/src/Platform/Tizen/ViewExtensions.cs | 6 ++ 32 files changed, 276 insertions(+), 153 deletions(-) rename Microsoft.Maui.Tizen.sln => ._Microsoft.Maui.Tizen.sln (100%) delete mode 100644 src/Core/src/Handlers/BoxView/BoxViewHandler.Tizen.cs create mode 100644 src/Core/src/Handlers/ImageButton/ImageButtonHandler.Tizen.cs create mode 100644 src/Core/src/Handlers/IndicatorView/IndicatorViewHandler.Tizen.cs delete mode 100644 src/Core/src/ImageSources/Tizen/ImageSourceServiceResult.cs delete mode 100644 src/Core/src/Platform/Tizen/BoxViewExtensions.cs create mode 100644 src/Core/src/Platform/Tizen/MauiIndicatorViewExtensions.cs diff --git a/Microsoft.Maui.Tizen.sln b/._Microsoft.Maui.Tizen.sln similarity index 100% rename from Microsoft.Maui.Tizen.sln rename to ._Microsoft.Maui.Tizen.sln diff --git a/.nuspec/Microsoft.Maui.Controls.MultiTargeting.targets b/.nuspec/Microsoft.Maui.Controls.MultiTargeting.targets index 324697c7a407..2c640ebb99ba 100644 --- a/.nuspec/Microsoft.Maui.Controls.MultiTargeting.targets +++ b/.nuspec/Microsoft.Maui.Controls.MultiTargeting.targets @@ -25,9 +25,9 @@ - + - + diff --git a/Directory.Build.props b/Directory.Build.props index 4435ae316cb5..7a6c124a5bc5 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,7 +5,7 @@ true true true - true + true true diff --git a/src/Controls/src/Core/Platform/Tizen/DragGestureHandler.cs b/src/Controls/src/Core/Platform/Tizen/DragGestureHandler.cs index eceef1d84191..7ff6dd73274a 100644 --- a/src/Controls/src/Core/Platform/Tizen/DragGestureHandler.cs +++ b/src/Controls/src/Core/Platform/Tizen/DragGestureHandler.cs @@ -177,7 +177,7 @@ async Task GetImageIconAsync(EvasObject parent) var services = Handler.MauiContext?.Services; var provider = services.GetService(typeof(IImageSourceServiceProvider)) as IImageSourceServiceProvider; var service = provider?.GetImageSourceService(mImage); - var result = await service.LoadImageAsync(mImage, image); + var result = await service.GetImageAsync(mImage, image); if (result == null) return null; return image; diff --git a/src/Controls/src/Core/Platform/Tizen/Shell/ShellItemView.cs b/src/Controls/src/Core/Platform/Tizen/Shell/ShellItemView.cs index 613e9e7045ce..b95a278daa12 100644 --- a/src/Controls/src/Core/Platform/Tizen/Shell/ShellItemView.cs +++ b/src/Controls/src/Core/Platform/Tizen/Shell/ShellItemView.cs @@ -447,7 +447,7 @@ EToolbarItem AppendTabsItem(string text, ImageSource iconSource) var provider = MauiContext.Services.GetRequiredService(); var service = provider.GetRequiredImageSourceService(iconSource); - _ = service.LoadImageAsync(iconSource, image); + _ = service.GetImageAsync(iconSource, image); item.SetIconPart(image); } diff --git a/src/Controls/src/Core/Platform/Tizen/Shell/ShellNavBar.cs b/src/Controls/src/Core/Platform/Tizen/Shell/ShellNavBar.cs index 92f3c5b8e6f9..bc0e27c5077c 100644 --- a/src/Controls/src/Core/Platform/Tizen/Shell/ShellNavBar.cs +++ b/src/Controls/src/Core/Platform/Tizen/Shell/ShellNavBar.cs @@ -265,7 +265,7 @@ async void UpdateMenuIcon() var provider = MauiContext.Services.GetRequiredService(); var service = provider.GetRequiredImageSourceService(source); - await service.LoadImageAsync(source, _menuIcon); + await service.GetImageAsync(source, _menuIcon); } _menuButton.SetIconPart(_menuIcon); _menuButton.Show(); diff --git a/src/Core/src/Handlers/BoxView/BoxViewHandler.Tizen.cs b/src/Core/src/Handlers/BoxView/BoxViewHandler.Tizen.cs deleted file mode 100644 index 630fd3fdc49c..000000000000 --- a/src/Core/src/Handlers/BoxView/BoxViewHandler.Tizen.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Microsoft.Maui.Graphics; - -namespace Microsoft.Maui.Handlers -{ - public partial class BoxViewHandler : ViewHandler - { - protected override MauiBoxView CreateNativeView() - { - return new MauiBoxView(NativeParent!) - { - Drawable = new BoxViewDrawable(VirtualView) - }; - } - - public static void MapColor(BoxViewHandler handler, IBoxView boxView) - { - handler.NativeView?.InvalidateBoxView(boxView); - } - - public static void MapCornerRadius(BoxViewHandler handler, IBoxView boxView) - { - handler.NativeView?.InvalidateBoxView(boxView); - } - } -} diff --git a/src/Core/src/Handlers/Button/ButtonHandler.Tizen.cs b/src/Core/src/Handlers/Button/ButtonHandler.Tizen.cs index 5f7ac9c8e270..2873777a351b 100644 --- a/src/Core/src/Handlers/Button/ButtonHandler.Tizen.cs +++ b/src/Core/src/Handlers/Button/ButtonHandler.Tizen.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Tizen.UIExtensions.ElmSharp; namespace Microsoft.Maui.Handlers @@ -17,7 +18,6 @@ protected override void ConnectHandler(Button nativeView) nativeView.Released += OnButtonClicked; nativeView.Clicked += OnButtonReleased; nativeView.Pressed += OnButtonPressed; - base.ConnectHandler(nativeView); } @@ -26,32 +26,40 @@ protected override void DisconnectHandler(Button nativeView) nativeView.Released -= OnButtonClicked; nativeView.Clicked -= OnButtonReleased; nativeView.Pressed -= OnButtonPressed; - base.DisconnectHandler(nativeView); } - public static void MapText(ButtonHandler handler, IButton button) + public static void MapText(IButtonHandler handler, IText button) { - handler.NativeView?.UpdateText(button); + handler.TypedNativeView?.UpdateText(button); } - public static void MapTextColor(ButtonHandler handler, IButton button) + public static void MapTextColor(IButtonHandler handler, ITextStyle button) { - handler.NativeView?.UpdateTextColor(button); + handler.TypedNativeView?.UpdateTextColor(button); } - //TODO : Need to impl - [MissingMapper] - public static void MapImageSource(ButtonHandler handler, IButton image) { } + public static void MapImageSource(IButtonHandler handler, IButton image) => + MapImageSourceAsync(handler, image).FireAndForget(handler); + + public static Task MapImageSourceAsync(IButtonHandler handler, IButton image) + { + if (image.ImageSource == null) + { + return Task.CompletedTask; + } + + return handler.ImageSourceLoader.UpdateImageSourceAsync(); + } [MissingMapper] - public static void MapCharacterSpacing(ButtonHandler handler, IButton button) { } + public static void MapCharacterSpacing(IButtonHandler handler, ITextStyle button) { } [MissingMapper] - public static void MapFont(ButtonHandler handler, IButton button) { } + public static void MapFont(IButtonHandler handler, ITextStyle button) { } [MissingMapper] - public static void MapPadding(ButtonHandler handler, IButton button) { } + public static void MapPadding(IButtonHandler handler, IButton button) { } void OnButtonClicked(object? sender, EventArgs e) { @@ -67,5 +75,11 @@ void OnButtonPressed(object? sender, EventArgs e) { VirtualView?.Pressed(); } + + void OnSetImageSource(Image? image) + { + NativeView.Image = image; + VirtualView.ImageSourceLoaded(); + } } } \ No newline at end of file diff --git a/src/Core/src/Handlers/Button/ButtonHandler.cs b/src/Core/src/Handlers/Button/ButtonHandler.cs index 7864e992d386..8be9163502b2 100644 --- a/src/Core/src/Handlers/Button/ButtonHandler.cs +++ b/src/Core/src/Handlers/Button/ButtonHandler.cs @@ -4,7 +4,9 @@ using NativeView = Google.Android.Material.Button.MaterialButton; #elif WINDOWS using NativeView = Microsoft.UI.Xaml.Controls.Button; -#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID) +#elif TIZEN +using NativeView = Tizen.UIExtensions.ElmSharp.Button; +#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID && !TIZEN) using NativeView = System.Object; #endif diff --git a/src/Core/src/Handlers/Button/IButtonHandler.cs b/src/Core/src/Handlers/Button/IButtonHandler.cs index 7fd23a5ecffa..cfeb6268ff64 100644 --- a/src/Core/src/Handlers/Button/IButtonHandler.cs +++ b/src/Core/src/Handlers/Button/IButtonHandler.cs @@ -4,7 +4,9 @@ using NativeView = Google.Android.Material.Button.MaterialButton; #elif WINDOWS using NativeView = Microsoft.UI.Xaml.Controls.Button; -#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID) +#elif TIZEN +using NativeView = Tizen.UIExtensions.ElmSharp.Button; +#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID && !TIZEN) using NativeView = System.Object; #endif @@ -16,4 +18,4 @@ public partial interface IButtonHandler : IViewHandler NativeView TypedNativeView { get; } ImageSourcePartLoader ImageSourceLoader { get; } } -} \ No newline at end of file +} diff --git a/src/Core/src/Handlers/Image/IImageHandler.cs b/src/Core/src/Handlers/Image/IImageHandler.cs index 41da517406f0..f465271aa990 100644 --- a/src/Core/src/Handlers/Image/IImageHandler.cs +++ b/src/Core/src/Handlers/Image/IImageHandler.cs @@ -4,7 +4,9 @@ using NativeView = Android.Widget.ImageView; #elif WINDOWS using NativeView = Microsoft.UI.Xaml.Controls.Image; -#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID) +#elif TIZEN +using NativeView = Tizen.UIExtensions.ElmSharp.Image; +#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID && !TIZEN) using NativeView = System.Object; #endif diff --git a/src/Core/src/Handlers/Image/ImageHandler.Tizen.cs b/src/Core/src/Handlers/Image/ImageHandler.Tizen.cs index 0073c5dbe7eb..ba8ee99c662e 100644 --- a/src/Core/src/Handlers/Image/ImageHandler.Tizen.cs +++ b/src/Core/src/Handlers/Image/ImageHandler.Tizen.cs @@ -18,7 +18,7 @@ protected override Image CreateNativeView() protected override void DisconnectHandler(Image nativeView) { base.DisconnectHandler(nativeView); - _sourceManager.Reset(); + SourceLoader.Reset(); } public override bool NeedsContainer => @@ -26,32 +26,38 @@ protected override void DisconnectHandler(Image nativeView) VirtualView?.Clip != null || base.NeedsContainer; - public static void MapBackground(ImageHandler handler, IImage image) + public static void MapBackground(IImageHandler handler, IImage image) { handler.UpdateValue(nameof(IViewHandler.ContainerView)); handler.GetWrappedNativeView()?.UpdateBackground(image); } - public static void MapAspect(ImageHandler handler, IImage image) => - handler.NativeView?.UpdateAspect(image); + public static void MapAspect(IImageHandler handler, IImage image) => + handler.TypedNativeView?.UpdateAspect(image); - public static void MapIsAnimationPlaying(ImageHandler handler, IImage image) => - handler.NativeView?.UpdateIsAnimationPlaying(image); + public static void MapIsAnimationPlaying(IImageHandler handler, IImage image) => + handler.TypedNativeView?.UpdateIsAnimationPlaying(image); - public static void MapSource(ImageHandler handler, IImage image) => + public static void MapSource(IImageHandler handler, IImage image) => MapSourceAsync(handler, image).FireAndForget(handler); - public static async Task MapSourceAsync(ImageHandler handler, IImage image) + public static async Task MapSourceAsync(IImageHandler handler, IImage image) { if (handler.NativeView == null) return; - var token = handler._sourceManager.BeginLoad(); + // TODO : fix it later + //return handler.SourceLoader.UpdateImageSourceAsync(); + var token = handler.SourceLoader.SourceManager.BeginLoad(); var provider = handler.GetRequiredService(); - var result = await handler.NativeView.UpdateSourceAsync(image, provider, token); + var result = await handler.TypedNativeView.UpdateSourceAsync(image, provider, token); + handler.SourceLoader.SourceManager.CompleteLoad(result); + } - handler._sourceManager.CompleteLoad(result); + void OnSetImageSource(Image? obj) + { + //Empty on purpose } } diff --git a/src/Core/src/Handlers/Image/ImageHandler.cs b/src/Core/src/Handlers/Image/ImageHandler.cs index 2d94766d3221..a8274b60d7f9 100644 --- a/src/Core/src/Handlers/Image/ImageHandler.cs +++ b/src/Core/src/Handlers/Image/ImageHandler.cs @@ -6,7 +6,9 @@ using NativeView = Android.Widget.ImageView; #elif WINDOWS using NativeView = Microsoft.UI.Xaml.Controls.Image; -#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID) +#elif TIZEN +using NativeView = Tizen.UIExtensions.ElmSharp.Image; +#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID && !TIZEN) using NativeView = System.Object; #endif @@ -16,7 +18,7 @@ public partial class ImageHandler : IImageHandler { public static IPropertyMapper Mapper = new PropertyMapper(ViewHandler.ViewMapper) { -#if __ANDROID__ || WINDOWS +#if __ANDROID__ || WINDOWS || TIZEN [nameof(IImage.Background)] = MapBackground, #endif [nameof(IImage.Aspect)] = MapAspect, @@ -46,4 +48,4 @@ public ImageHandler(IPropertyMapper mapper) : base(mapper ?? Mapper) NativeView IImageHandler.TypedNativeView => NativeView; } -} \ No newline at end of file +} diff --git a/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Tizen.cs b/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Tizen.cs new file mode 100644 index 000000000000..faf12900a4b3 --- /dev/null +++ b/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Tizen.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using ElmSharp; +using TImage = Tizen.UIExtensions.ElmSharp.Image; + +namespace Microsoft.Maui.Handlers +{ + //TODO: Need to impl + public partial class ImageButtonHandler : ViewHandler + { + protected override TImage CreateNativeView() => throw new NotImplementedException(); + + void OnSetImageSource(TImage? obj) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Core/src/Handlers/ImageButton/ImageButtonHandler.cs b/src/Core/src/Handlers/ImageButton/ImageButtonHandler.cs index 54f7576ea9c7..593da3706626 100644 --- a/src/Core/src/Handlers/ImageButton/ImageButtonHandler.cs +++ b/src/Core/src/Handlers/ImageButton/ImageButtonHandler.cs @@ -11,7 +11,12 @@ using NativeImage = Microsoft.UI.Xaml.Media.ImageSource; using NativeImageView = Microsoft.UI.Xaml.Controls.Image; using NativeView = Microsoft.UI.Xaml.FrameworkElement; -#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID) +#elif TIZEN +using NativeImage = Tizen.UIExtensions.ElmSharp.Image; +using NativeView = Tizen.UIExtensions.ElmSharp.Image; +using NativeImageView = Tizen.UIExtensions.ElmSharp.Image; +#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID && !TIZEN) +using NativeView = System.Object; using NativeImage = System.Object; using NativeImageView = System.Object; using NativeView = System.Object; @@ -55,4 +60,4 @@ public ImageButtonHandler(IPropertyMapper mapper) : base(mapper ?? Mapper) #endif ImageSourcePartLoader IImageHandler.SourceLoader => SourceLoader; } -} \ No newline at end of file +} diff --git a/src/Core/src/Handlers/IndicatorView/IndicatorViewHandler.Tizen.cs b/src/Core/src/Handlers/IndicatorView/IndicatorViewHandler.Tizen.cs new file mode 100644 index 000000000000..ed7fc53aa570 --- /dev/null +++ b/src/Core/src/Handlers/IndicatorView/IndicatorViewHandler.Tizen.cs @@ -0,0 +1,60 @@ +using System; +using Tizen.UIExtensions.ElmSharp; + +namespace Microsoft.Maui.Handlers +{ + public partial class IndicatorViewHandler : ViewHandler + { + protected override IndicatorView CreateNativeView() + { + _ = NativeParent ?? throw new ArgumentNullException(nameof(NativeParent)); + return new IndicatorView(NativeParent); + } + + protected override void ConnectHandler(IndicatorView nativeView) + { + base.ConnectHandler(nativeView); + NativeView.SelectedPosition += OnSelectedPosition; + } + + protected override void DisconnectHandler(IndicatorView nativeView) + { + base.DisconnectHandler(nativeView); + NativeView.SelectedPosition -= OnSelectedPosition; + } + + public static void MapCount(IndicatorViewHandler handler, IIndicatorView indicator) + { + handler.NativeView.UpdateIndicatorCount(indicator); + } + + public static void MapPosition(IndicatorViewHandler handler, IIndicatorView indicator) + { + handler.NativeView.UpdatePosition(indicator); + } + + //TODO : Need to impl + [MissingMapper] + public static void MapHideSingle(IndicatorViewHandler handler, IIndicatorView indicator) { } + + [MissingMapper] + public static void MapMaximumVisible(IndicatorViewHandler handler, IIndicatorView indicator) { } + + [MissingMapper] + public static void MapIndicatorSize(IndicatorViewHandler handler, IIndicatorView indicator) { } + + [MissingMapper] + public static void MapIndicatorColor(IndicatorViewHandler handler, IIndicatorView indicator) { } + + [MissingMapper] + public static void MapSelectedIndicatorColor(IndicatorViewHandler handler, IIndicatorView indicator) { } + + [MissingMapper] + public static void MapIndicatorShape(IndicatorViewHandler handler, IIndicatorView indicator) { } + + void OnSelectedPosition(object? sender, SelectedPositionChangedEventArgs e) + { + VirtualView.Position = e.SelectedPosition; + } + } +} \ No newline at end of file diff --git a/src/Core/src/Handlers/NavigationPage/NavigationViewHandler.Tizen.cs b/src/Core/src/Handlers/NavigationPage/NavigationViewHandler.Tizen.cs index 21a990f4dc48..6c9692d7caa0 100644 --- a/src/Core/src/Handlers/NavigationPage/NavigationViewHandler.Tizen.cs +++ b/src/Core/src/Handlers/NavigationPage/NavigationViewHandler.Tizen.cs @@ -13,7 +13,7 @@ namespace Microsoft.Maui.Handlers { - internal partial class NavigationViewHandler : + public partial class NavigationViewHandler : ViewHandler, INativeViewHandler { readonly List _naviItemContentPartList = new List(); diff --git a/src/Core/src/ImageSources/FileImageSourceService/FileImageSourceService.Tizen.cs b/src/Core/src/ImageSources/FileImageSourceService/FileImageSourceService.Tizen.cs index 0c545a8f94d2..ebcbb3d881d7 100644 --- a/src/Core/src/ImageSources/FileImageSourceService/FileImageSourceService.Tizen.cs +++ b/src/Core/src/ImageSources/FileImageSourceService/FileImageSourceService.Tizen.cs @@ -11,10 +11,10 @@ namespace Microsoft.Maui { public partial class FileImageSourceService { - public override Task?> LoadImageAsync(IImageSource imageSource, Image image, CancellationToken cancellationToken = default) => - LoadImageAsync((IFileImageSource)imageSource, image, cancellationToken); + public override Task?> GetImageAsync(IImageSource imageSource, Image image, CancellationToken cancellationToken = default) => + GetImageAsync((IFileImageSource)imageSource, image, cancellationToken); - public async Task?> LoadImageAsync(IFileImageSource imageSource, Image image, CancellationToken cancellationToken = default) + public async Task?> GetImageAsync(IFileImageSource imageSource, Image image, CancellationToken cancellationToken = default) { if (imageSource.IsEmpty) return null; @@ -24,17 +24,16 @@ public partial class FileImageSourceService { if (!string.IsNullOrEmpty(filename)) { - var isLoadComplate = await image.LoadAsync(GetPath(filename), cancellationToken); + var isLoadComplated = await image.LoadAsync(GetPath(filename), cancellationToken); - if (!isLoadComplate) + if (!isLoadComplated) { //If it fails, call the Load function to remove the previous image. image.Load(string.Empty); throw new InvalidOperationException("Unable to load image file."); } - var result = new ImageSourceServiceResult(isLoadComplate); - + var result = new ImageSourceServiceResult(image, () => image.Unrealize()); return result; } else diff --git a/src/Core/src/ImageSources/FontImageSourceService/FontImageSourceService.Tizen.cs b/src/Core/src/ImageSources/FontImageSourceService/FontImageSourceService.Tizen.cs index 3c4fa95ac4b5..2ded0740a9bb 100644 --- a/src/Core/src/ImageSources/FontImageSourceService/FontImageSourceService.Tizen.cs +++ b/src/Core/src/ImageSources/FontImageSourceService/FontImageSourceService.Tizen.cs @@ -9,10 +9,10 @@ namespace Microsoft.Maui { public partial class FontImageSourceService { - public override Task?> LoadImageAsync(IImageSource imageSource, Image image, CancellationToken cancellationToken = default) => - LoadImageAsync((IFontImageSource)imageSource, image, cancellationToken); + public override Task?> GetImageAsync(IImageSource imageSource, Image image, CancellationToken cancellationToken = default) => + GetImageAsync((IFontImageSource)imageSource, image, cancellationToken); - public async Task?> LoadImageAsync(IFontImageSource imageSource, Image image, CancellationToken cancellationToken = default) + public async Task?> GetImageAsync(IFontImageSource imageSource, Image image, CancellationToken cancellationToken = default) { if (imageSource.IsEmpty) return null; @@ -20,15 +20,14 @@ public partial class FontImageSourceService try { //TODO : Fix me correctly later. - var isLoadComplate = await image.LoadAsync(string.Empty, cancellationToken); + var isLoadComplated = await image.LoadAsync(string.Empty, cancellationToken); - if (!isLoadComplate) + if (!isLoadComplated) { throw new InvalidOperationException("Unable to load image file."); } - var result = new ImageSourceServiceResult(isLoadComplate); - + var result = new ImageSourceServiceResult(image, () => image.Unrealize()); return result; } catch (Exception ex) diff --git a/src/Core/src/ImageSources/IImageSourceService.cs b/src/Core/src/ImageSources/IImageSourceService.cs index 8c158aa3eebf..873564ba0df5 100644 --- a/src/Core/src/ImageSources/IImageSourceService.cs +++ b/src/Core/src/ImageSources/IImageSourceService.cs @@ -17,7 +17,7 @@ public interface IImageSourceService float scale = 1, CancellationToken cancellationToken = default); #elif TIZEN || __TIZEN__ - Task?> LoadImageAsync( + Task?> GetImageAsync( IImageSource imageSource, Tizen.UIExtensions.ElmSharp.Image image, CancellationToken cancellationToken = default); diff --git a/src/Core/src/ImageSources/ImageSourceExtensions.cs b/src/Core/src/ImageSources/ImageSourceExtensions.cs index 157ed9a703bc..0209f7cb8d28 100644 --- a/src/Core/src/ImageSources/ImageSourceExtensions.cs +++ b/src/Core/src/ImageSources/ImageSourceExtensions.cs @@ -10,7 +10,9 @@ using NativeImage = Android.Graphics.Drawables.Drawable; #elif WINDOWS using NativeImage = Microsoft.UI.Xaml.Media.ImageSource; -#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID) +#elif TIZEN +using NativeImage = Tizen.UIExtensions.ElmSharp.Image; +#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID && !TIZEN) using NativeImage = System.Object; #endif @@ -52,6 +54,9 @@ static async Task LoadImageResult(Task?> return imageSourceService.GetDrawableAsync(imageSource, mauiContext.Context!); #elif WINDOWS return imageSourceService.GetImageSourceAsync(imageSource); +#elif TIZEN + var nativeImage = new NativeImage(mauiContext.Context!.NativeParent!); + return imageSourceService.GetImageAsync(imageSource, nativeImage); #else throw new NotImplementedException(); #endif diff --git a/src/Core/src/ImageSources/ImageSourceService.cs b/src/Core/src/ImageSources/ImageSourceService.cs index 283fbf33cddf..76aca65d02c3 100644 --- a/src/Core/src/ImageSources/ImageSourceService.cs +++ b/src/Core/src/ImageSources/ImageSourceService.cs @@ -25,7 +25,7 @@ public ImageSourceService(ILogger? logger = null) float scale = 1, CancellationToken cancellationToken = default); #elif TIZEN || __TIZEN__ - public abstract Task?> LoadImageAsync( + public abstract Task?> GetImageAsync( IImageSource imageSource, Tizen.UIExtensions.ElmSharp.Image image, CancellationToken cancellationToken = default); diff --git a/src/Core/src/ImageSources/ImageSourceServiceResult.cs b/src/Core/src/ImageSources/ImageSourceServiceResult.cs index eaa7dd1f970f..0329f8ae1825 100644 --- a/src/Core/src/ImageSources/ImageSourceServiceResult.cs +++ b/src/Core/src/ImageSources/ImageSourceServiceResult.cs @@ -6,7 +6,9 @@ using NativeView = Android.Graphics.Drawables.Drawable; #elif WINDOWS using NativeView = Microsoft.UI.Xaml.Media.ImageSource; -#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID) +#elif TIZEN +using NativeView = Tizen.UIExtensions.ElmSharp.Image; +#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID && !TIZEN) using NativeView = System.Object; #endif diff --git a/src/Core/src/ImageSources/StreamImageSourceService/StreamImageSourceService.Tizen.cs b/src/Core/src/ImageSources/StreamImageSourceService/StreamImageSourceService.Tizen.cs index dc5047021045..8898426defd8 100644 --- a/src/Core/src/ImageSources/StreamImageSourceService/StreamImageSourceService.Tizen.cs +++ b/src/Core/src/ImageSources/StreamImageSourceService/StreamImageSourceService.Tizen.cs @@ -9,10 +9,10 @@ namespace Microsoft.Maui { public partial class StreamImageSourceService { - public override Task?> LoadImageAsync(IImageSource imageSource, Image image, CancellationToken cancellationToken = default) => - LoadImageAsync((IStreamImageSource)imageSource, image, cancellationToken); + public override Task?> GetImageAsync(IImageSource imageSource, Image image, CancellationToken cancellationToken = default) => + GetImageAsync((IStreamImageSource)imageSource, image, cancellationToken); - public async Task?> LoadImageAsync(IStreamImageSource imageSource, Image image, CancellationToken cancellationToken = default) + public async Task?> GetImageAsync(IStreamImageSource imageSource, Image image, CancellationToken cancellationToken = default) { if (imageSource.IsEmpty) return null; @@ -24,12 +24,12 @@ public partial class StreamImageSourceService if (stream == null) throw new InvalidOperationException("Unable to load image stream."); - var result = await image.LoadAsync(stream, cancellationToken); + var isLoadComplated = await image.LoadAsync(stream, cancellationToken); - if (!result) + if (!isLoadComplated) throw new InvalidOperationException("Unable to decode image from stream."); - return new ImageSourceServiceResult(result); + return new ImageSourceServiceResult(image, () => image.Unrealize()); } catch (Exception ex) { diff --git a/src/Core/src/ImageSources/Tizen/ImageSourceServiceResult.cs b/src/Core/src/ImageSources/Tizen/ImageSourceServiceResult.cs deleted file mode 100644 index 6e48ceaec7c1..000000000000 --- a/src/Core/src/ImageSources/Tizen/ImageSourceServiceResult.cs +++ /dev/null @@ -1,39 +0,0 @@ -#nullable enable -using System; - -namespace Microsoft.Maui -{ - public class ImageSourceServiceResult : IImageSourceServiceResult - { - Action? _dispose; - - public ImageSourceServiceResult(bool result, Action? dispose = null) - : this(result, false, dispose) - { - } - - public ImageSourceServiceResult(bool result, bool resolutionDependent, Action? dispose = null) - { - Value = result; - IsResolutionDependent = resolutionDependent; - _dispose = dispose; - } - - public bool Value { get; } - - public bool IsResolutionDependent { get; } - - public bool IsDisposed { get; private set; } - - public void Dispose() - { - if (IsDisposed) - return; - - IsDisposed = true; - - _dispose?.Invoke(); - _dispose = null; - } - } -} \ No newline at end of file diff --git a/src/Core/src/ImageSources/UriImageSourceService/UriImageSourceService.Tizen.cs b/src/Core/src/ImageSources/UriImageSourceService/UriImageSourceService.Tizen.cs index 32a588c1ea2d..36a7bdccf2c5 100644 --- a/src/Core/src/ImageSources/UriImageSourceService/UriImageSourceService.Tizen.cs +++ b/src/Core/src/ImageSources/UriImageSourceService/UriImageSourceService.Tizen.cs @@ -9,10 +9,10 @@ namespace Microsoft.Maui { public partial class UriImageSourceService { - public override Task?> LoadImageAsync(IImageSource imageSource, Image image, CancellationToken cancellationToken = default) => - LoadImageAsync((IUriImageSource)imageSource, image, cancellationToken); + public override Task?> GetImageAsync(IImageSource imageSource, Image image, CancellationToken cancellationToken = default) => + GetImageAsync((IUriImageSource)imageSource, image, cancellationToken); - public async Task?> LoadImageAsync(IUriImageSource imageSource, Image image, CancellationToken cancellationToken = default) + public async Task?> GetImageAsync(IUriImageSource imageSource, Image image, CancellationToken cancellationToken = default) { if (imageSource.IsEmpty) return null; @@ -21,12 +21,12 @@ public partial class UriImageSourceService try { - var result = await image.LoadAsync(uri, cancellationToken); + var isLoadComplated = await image.LoadAsync(uri, cancellationToken); - if (!result) + if (!isLoadComplated) throw new InvalidOperationException($"Unable to load image URI '{uri}'."); - return new ImageSourceServiceResult(result); + return new ImageSourceServiceResult(image, () => image.Unrealize()); } catch (Exception ex) { diff --git a/src/Core/src/Platform/ImageSourcePartLoader.cs b/src/Core/src/Platform/ImageSourcePartLoader.cs index bf5d3ddbc725..e269ad746567 100644 --- a/src/Core/src/Platform/ImageSourcePartLoader.cs +++ b/src/Core/src/Platform/ImageSourcePartLoader.cs @@ -11,7 +11,10 @@ #elif WINDOWS using NativeImage = Microsoft.UI.Xaml.Media.ImageSource; using NativeView = Microsoft.UI.Xaml.FrameworkElement; -#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID) +#elif TIZEN +using NativeImage = Tizen.UIExtensions.ElmSharp.Image; +using NativeView = Tizen.UIExtensions.ElmSharp.Image; +#elif NETSTANDARD || (NET6_0 && !IOS && !ANDROID && !TIZEN) using NativeView = System.Object; using NativeImage = System.Object; #endif @@ -56,7 +59,7 @@ public async Task UpdateImageSourceAsync() if (imageSource != null) { -#if __IOS__ || __ANDROID__ || WINDOWS +#if __IOS__ || __ANDROID__ || WINDOWS || TIZEN var result = await imageSource.UpdateSourceAsync(NativeView, ImageSourceServiceProvider, SetImage!, token) .ConfigureAwait(false); diff --git a/src/Core/src/Platform/Tizen/BoxViewExtensions.cs b/src/Core/src/Platform/Tizen/BoxViewExtensions.cs deleted file mode 100644 index 1c450ddd290b..000000000000 --- a/src/Core/src/Platform/Tizen/BoxViewExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.Maui.Graphics; - -namespace Microsoft.Maui -{ - public static class BoxViewExtensions - { - public static void InvalidateBoxView(this MauiBoxView nativeView, IBoxView boxView) - { - nativeView.Invalidate(); - } - } -} \ No newline at end of file diff --git a/src/Core/src/Platform/Tizen/ButtonExtensions.cs b/src/Core/src/Platform/Tizen/ButtonExtensions.cs index a64a5df690db..c517ae04a492 100644 --- a/src/Core/src/Platform/Tizen/ButtonExtensions.cs +++ b/src/Core/src/Platform/Tizen/ButtonExtensions.cs @@ -4,12 +4,12 @@ namespace Microsoft.Maui { public static class ButtonExtensions { - public static void UpdateTextColor(this Button nativeButton, IButton button) + public static void UpdateTextColor(this Button nativeButton, ITextStyle button) { nativeButton.TextColor = button.TextColor.ToNative(); } - public static void UpdateText(this Button nativeButton, IButton button) + public static void UpdateText(this Button nativeButton, IText button) { nativeButton.Text = button.Text ?? ""; } diff --git a/src/Core/src/Platform/Tizen/ImageExtensions.cs b/src/Core/src/Platform/Tizen/ImageExtensions.cs index e485c12abb63..bec10e6f2a5c 100644 --- a/src/Core/src/Platform/Tizen/ImageExtensions.cs +++ b/src/Core/src/Platform/Tizen/ImageExtensions.cs @@ -22,7 +22,7 @@ public static void UpdateIsAnimationPlaying(this Image nativeImage, IImageSource nativeImage.IsAnimationPlaying = image.IsAnimationPlaying; } - public static async Task?> UpdateSourceAsync(this Image nativeImage, IImageSourcePart image, IImageSourceServiceProvider services, CancellationToken cancellationToken = default) + public static async Task?> UpdateSourceAsync(this Image nativeImage, IImageSourcePart image, IImageSourceServiceProvider services, CancellationToken cancellationToken = default) { nativeImage.Clear(); @@ -40,10 +40,10 @@ public static void UpdateIsAnimationPlaying(this Image nativeImage, IImageSource try { var service = services.GetRequiredImageSourceService(imageSource); - var result = await service.LoadImageAsync(imageSource, nativeImage, cancellationToken); - var isLoaded = result?.Value; + var result = await service.GetImageAsync(imageSource, nativeImage, cancellationToken); + var isLoaded = result != null; - var applied = !cancellationToken.IsCancellationRequested && isLoaded == true && imageSource == image.Source; + var applied = !cancellationToken.IsCancellationRequested && isLoaded && imageSource == image.Source; // only set the image if we are still on the same one if (applied) @@ -75,5 +75,58 @@ public static void UpdateIsAnimationPlaying(this Image nativeImage, IImageSource return null; } + + public static async Task?> UpdateSourceAsync(this IImageSourcePart image, Image destinationContext, IImageSourceServiceProvider services, Action setImage, CancellationToken cancellationToken = default) + { + image.UpdateIsLoading(false); + + var imageSource = image.Source; + if (imageSource == null) + return null; + + var events = image as IImageSourcePartEvents; + + events?.LoadingStarted(); + image.UpdateIsLoading(true); + + try + { + var service = services.GetRequiredImageSourceService(imageSource); + var result = await service.GetImageAsync(imageSource, destinationContext, cancellationToken); + var tImage = result?.Value; + + var applied = !cancellationToken.IsCancellationRequested && tImage != null && imageSource == image.Source; + + // only set the image if we are still on the same one + if (applied) + { + setImage.Invoke(tImage); + destinationContext.UpdateIsAnimationPlaying(image); + } + + events?.LoadingCompleted(applied); + + return result; + } + catch (OperationCanceledException) + { + // no-op + events?.LoadingCompleted(false); + } + catch (Exception ex) + { + events?.LoadingFailed(ex); + } + finally + { + // only mark as finished if we are still working on the same image + if (imageSource == image.Source) + { + image.UpdateIsLoading(false); + } + } + + return null; + } } } diff --git a/src/Core/src/Platform/Tizen/MauiIndicatorViewExtensions.cs b/src/Core/src/Platform/Tizen/MauiIndicatorViewExtensions.cs new file mode 100644 index 000000000000..a221a9beb46c --- /dev/null +++ b/src/Core/src/Platform/Tizen/MauiIndicatorViewExtensions.cs @@ -0,0 +1,20 @@ +using Tizen.UIExtensions.ElmSharp; + +namespace Microsoft.Maui +{ + public static class MauiIndicatorViewExtensions + { + public static void UpdateIndicatorCount(this IndicatorView nativeView, IIndicatorView indicator) + { + nativeView.ClearIndex(); + nativeView.AppendIndex(indicator.Count); + nativeView.Update(0); + nativeView.UpdatePosition(indicator); + } + + public static void UpdatePosition(this IndicatorView nativeView, IIndicatorView indicator) + { + nativeView.UpdateSelectedIndex(indicator.Position); + } + } +} diff --git a/src/Core/src/Platform/Tizen/ViewExtensions.cs b/src/Core/src/Platform/Tizen/ViewExtensions.cs index cc399ed7294d..b7f400f0efb3 100644 --- a/src/Core/src/Platform/Tizen/ViewExtensions.cs +++ b/src/Core/src/Platform/Tizen/ViewExtensions.cs @@ -67,6 +67,12 @@ public static void UpdateClip(this EvasObject nativeView, IView view) wrapper.Clip = view.Clip; } + public static void UpdateShadow(this EvasObject nativeView, IView view) + { + if (nativeView is WrapperView wrapper) + wrapper.Shadow = view.Shadow; + } + public static void UpdateAutomationId(this EvasObject nativeView, IView view) { {