diff --git a/src/Compatibility/Core/src/AppHostBuilderExtensions.Tizen.cs b/src/Compatibility/Core/src/AppHostBuilderExtensions.Tizen.cs new file mode 100644 index 000000000000..e64e79b3dc8a --- /dev/null +++ b/src/Compatibility/Core/src/AppHostBuilderExtensions.Tizen.cs @@ -0,0 +1,34 @@ +using Microsoft.Maui.Hosting; +using Microsoft.Maui.LifecycleEvents; +using Microsoft.Maui.Controls.Compatibility; + +namespace Microsoft.Maui.Controls.Hosting +{ + public static partial class AppHostBuilderExtensions + { + internal static IAppHostBuilder ConfigureCompatibilityLifecycleEvents(this IAppHostBuilder builder) => + builder.ConfigureLifecycleEvents(events => events.AddTizen(OnConfigureLifeCycle)); + + static void OnConfigureLifeCycle(ITizenLifecycleBuilder tizen) + { + tizen.OnPreCreate((app) => + { + // This is the initial Init to set up any system services registered by + // Forms.Init(). This happens before any UI has appeared. + // This creates a dummy MauiContext. + + var services = MauiApplication.Current.Services; + MauiContext mauiContext = new MauiContext(services, CoreUIAppContext.GetInstance(MauiApplication.Current)); + ActivationState state = new ActivationState(mauiContext); + Forms.Init(state, new InitializationOptions(MauiApplication.Current) { Flags = InitializationFlags.SkipRenderers, DisplayResolutionUnit = DisplayResolutionUnit.DP() }); + }) + .OnMauiContextCreated((mauiContext) => + { + // This is the final Init that sets up the real context from the application. + + var state = new ActivationState(mauiContext!); + Forms.Init(state); + }); + } + } +} diff --git a/src/Compatibility/Core/src/AppHostBuilderExtensions.cs b/src/Compatibility/Core/src/AppHostBuilderExtensions.cs index d0b0b8f3237a..737360e90a14 100644 --- a/src/Compatibility/Core/src/AppHostBuilderExtensions.cs +++ b/src/Compatibility/Core/src/AppHostBuilderExtensions.cs @@ -35,6 +35,7 @@ using DefaultRenderer = Microsoft.Maui.Controls.Compatibility.Platform.iOS.Platform.DefaultRenderer; #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; diff --git a/src/Compatibility/Core/src/Compatibility.csproj b/src/Compatibility/Core/src/Compatibility.csproj index 1278d507f78c..16bb63fa62a1 100644 --- a/src/Compatibility/Core/src/Compatibility.csproj +++ b/src/Compatibility/Core/src/Compatibility.csproj @@ -22,15 +22,12 @@ - - - diff --git a/src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs b/src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs index 06785c6b6b6b..a6bd2055fe25 100644 --- a/src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs +++ b/src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs @@ -176,6 +176,11 @@ 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/Renderers/CarouselPageRenderer.cs b/src/Compatibility/Core/src/Tizen/Renderers/CarouselPageRenderer.cs index 8af7ac88feeb..088f532588db 100644 --- a/src/Compatibility/Core/src/Tizen/Renderers/CarouselPageRenderer.cs +++ b/src/Compatibility/Core/src/Tizen/Renderers/CarouselPageRenderer.cs @@ -173,8 +173,6 @@ void OnInnerLayoutUpdate() void OnCurrentPageChanged(object sender, EventArgs e) { - CustomFocusManager.StartReorderTabIndex(); - Element.UpdateFocusTreePolicy(); if (IsChangedByScroll()) diff --git a/src/Compatibility/Core/src/Tizen/Renderers/CustomFocusManager.cs b/src/Compatibility/Core/src/Tizen/Renderers/CustomFocusManager.cs index 2668fde47be4..cbd503ec04db 100644 --- a/src/Compatibility/Core/src/Tizen/Renderers/CustomFocusManager.cs +++ b/src/Compatibility/Core/src/Tizen/Renderers/CustomFocusManager.cs @@ -9,21 +9,15 @@ namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen { class CustomFocusManager : IDisposable { - static bool s_reorderTriggered; - static readonly ObservableCollection s_tabIndexList = new ObservableCollection(); - VisualElement _nextUp; VisualElement _nextDown; VisualElement _nextLeft; VisualElement _nextRight; VisualElement _nextForward; VisualElement _nextBackward; - int _tabIndex = -1; - bool _isTabStop = true; static CustomFocusManager() { - s_tabIndexList.CollectionChanged += TabIndexCollectionChanged; } public CustomFocusManager(VisualElement element, Widget nativeView) @@ -40,52 +34,6 @@ public CustomFocusManager(VisualElement element, Widget nativeView) VisualElement Element { get; } Widget NativeView { get; } - public int TabIndex - { - get - { - return _tabIndex; - } - set - { - if (IsTabStop) - { - if (_tabIndex > -1) - { - s_tabIndexList.Remove(this); - } - if (value > -1) - { - s_tabIndexList.Add(this); - } - } - _tabIndex = value; - } - } - - public bool IsTabStop - { - get - { - return _isTabStop; - } - set - { - if (TabIndex > -1) - { - if (_isTabStop) - { - s_tabIndexList.Remove(this); - } - if (value) - { - s_tabIndexList.Add(this); - } - } - _isTabStop = value; - } - } - public VisualElement NextUp { get => _nextUp; @@ -152,23 +100,6 @@ public void Dispose() GC.SuppressFinalize(this); } - public static void StartReorderTabIndex() - { - if (Device.IsInvokeRequired) - { - Device.BeginInvokeOnMainThread(() => - { - StartReorderTabIndex(); - }); - return; - } - if (!s_reorderTriggered) - { - s_reorderTriggered = true; - Device.BeginInvokeOnMainThread(ReorderTabIndex); - } - } - protected virtual void Dispose(bool disposing) { if (disposing) @@ -198,10 +129,6 @@ protected virtual void Dispose(bool disposing) NextBackward.PropertyChanged -= OnNextViewPropertyChanged; } } - if (s_tabIndexList.Contains(this)) - { - s_tabIndexList.Remove(this); - } } void SetUpFocus(VisualElement next, FocusDirection direction) @@ -251,36 +178,6 @@ FocusDirection GetFocusDirection(VisualElement nextView) return FocusDirection.Next; } - static void ReorderTabIndex() - { - s_reorderTriggered = false; - var list = s_tabIndexList.Where((t) => t.IsTabStop && ElementIsVisible(t)).OrderBy(x => x.Element.TabIndex); - CustomFocusManager first = null; - CustomFocusManager last = null; - foreach (var item in list) - { - if (first == null) - first = item; - - if (last != null) - { - item.NextBackward = last.Element; - last.NextForward = item.Element; - } - last = item; - } - if (first != null && last != null) - { - first.NextBackward = last.Element; - last.NextForward = first.Element; - } - } - - static void TabIndexCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - StartReorderTabIndex(); - } - static bool PageIsVisible(Page page) { if (page == null) diff --git a/src/Compatibility/Core/src/Tizen/Renderers/EntryRenderer.cs b/src/Compatibility/Core/src/Tizen/Renderers/EntryRenderer.cs index bf22fe2ef2eb..748adbe89e3c 100644 --- a/src/Compatibility/Core/src/Tizen/Renderers/EntryRenderer.cs +++ b/src/Compatibility/Core/src/Tizen/Renderers/EntryRenderer.cs @@ -121,14 +121,7 @@ void OnTextChanged(object sender, EventArgs e) void OnCompleted(object sender, EventArgs e) { - if (Element.ReturnType == ReturnType.Next) - { - FocusSearch(true)?.SetFocus(true); - } - else - { - Control.SetFocus(false); - } + Control.SetFocus(false); ((IEntryController)Element).SendCompleted(); } diff --git a/src/Compatibility/Core/src/Tizen/Renderers/FlyoutPageRenderer.cs b/src/Compatibility/Core/src/Tizen/Renderers/FlyoutPageRenderer.cs index 844e1456772a..6a04cb4c674f 100644 --- a/src/Compatibility/Core/src/Tizen/Renderers/FlyoutPageRenderer.cs +++ b/src/Compatibility/Core/src/Tizen/Renderers/FlyoutPageRenderer.cs @@ -141,9 +141,6 @@ void UpdateDetail(bool isInit) void UpdateIsPresented() { - // To update TabIndex order - CustomFocusManager.StartReorderTabIndex(); - _flyoutPage.IsPresented = Element.IsPresented; } diff --git a/src/Compatibility/Core/src/Tizen/Renderers/MasterDetailPageRenderer.cs b/src/Compatibility/Core/src/Tizen/Renderers/MasterDetailPageRenderer.cs index 572bdde849a4..15a8bf4a47bf 100644 --- a/src/Compatibility/Core/src/Tizen/Renderers/MasterDetailPageRenderer.cs +++ b/src/Compatibility/Core/src/Tizen/Renderers/MasterDetailPageRenderer.cs @@ -146,9 +146,6 @@ void UpdateDetailPage(bool isInit) void UpdateIsPresented() { - // To update TabIndex order - CustomFocusManager.StartReorderTabIndex(); - _mdpage.IsPresented = Element.IsPresented; } diff --git a/src/Compatibility/Core/src/Tizen/Renderers/TabbedPageRenderer.cs b/src/Compatibility/Core/src/Tizen/Renderers/TabbedPageRenderer.cs index 557e5afb1e2b..4982b4e229f3 100644 --- a/src/Compatibility/Core/src/Tizen/Renderers/TabbedPageRenderer.cs +++ b/src/Compatibility/Core/src/Tizen/Renderers/TabbedPageRenderer.cs @@ -417,9 +417,6 @@ void OnToolbarItemSelected(object sender, EToolbarItemEventArgs e) void OnCurrentPageChanged() { - // To update TabIndex order - CustomFocusManager.StartReorderTabIndex(); - if (_isUpdateByScroller || _isUpdateByToolbar || !_isInitialized) return; diff --git a/src/Compatibility/Core/src/Tizen/Renderers/VisualElementRenderer.cs b/src/Compatibility/Core/src/Tizen/Renderers/VisualElementRenderer.cs index 2878f8992c91..3347b538d5d3 100644 --- a/src/Compatibility/Core/src/Tizen/Renderers/VisualElementRenderer.cs +++ b/src/Compatibility/Core/src/Tizen/Renderers/VisualElementRenderer.cs @@ -74,8 +74,6 @@ protected VisualElementRenderer() RegisterPropertyHandler(VisualElement.RotationYProperty, UpdateTransformation); RegisterPropertyHandler(VisualElement.TranslationXProperty, UpdateTransformation); RegisterPropertyHandler(VisualElement.TranslationYProperty, UpdateTransformation); - RegisterPropertyHandler(VisualElement.TabIndexProperty, UpdateTabIndex); - RegisterPropertyHandler(VisualElement.IsTabStopProperty, UpdateIsTabStop); RegisterPropertyHandler(AutomationProperties.NameProperty, SetAccessibilityName); RegisterPropertyHandler(AutomationProperties.HelpTextProperty, SetAccessibilityDescription); @@ -508,29 +506,6 @@ protected virtual void SetLabeledBy(bool initialize) } } - protected Widget FocusSearch(bool forwardDirection) - { - VisualElement element = Element as VisualElement; - int maxAttempts = 0; - var tabIndexes = element?.GetTabIndexesOnParentPage(out maxAttempts); - if (tabIndexes == null) - return null; - - int tabIndex = Element.TabIndex; - int attempt = 0; - - do - { - element = element.FindNextElement(forwardDirection, tabIndexes, ref tabIndex) as VisualElement; - var renderer = Platform.GetRenderer(element); - if (renderer?.NativeView is Widget widget && widget.IsFocusAllowed) - { - return widget; - } - } while (!(element.IsFocused || ++attempt >= maxAttempts)); - return null; - } - internal virtual void SendVisualElementInitialized(VisualElement element, EvasObject nativeView) { element.SendViewInitialized(nativeView); @@ -1212,32 +1187,6 @@ protected virtual void ApplyTransformation() } } - void UpdateTabIndex() - { - if (!Forms.Flags.Contains(Flags.DisableTabIndex)) - { - if (Element is View && NativeView is Widget widget && widget.IsFocusAllowed) - { - _customFocusManager.Value.TabIndex = Element.TabIndex; - } - } - } - - void UpdateIsTabStop(bool init) - { - if (init && Element.IsTabStop) - { - return; - } - if (!Forms.Flags.Contains(Flags.DisableTabIndex)) - { - if (Element is View && NativeView is Widget widget && widget.IsFocusAllowed) - { - _customFocusManager.Value.IsTabStop = Element.IsTabStop; - } - } - } - EFocusDirection ConvertToNativeFocusDirection(string direction) { if (direction == XFocusDirection.Back) diff --git a/src/Controls/samples/Controls.Sample/Controls/BordelessEntry/BordelessEntryHandler.cs b/src/Controls/samples/Controls.Sample/Controls/BordelessEntry/BordelessEntryHandler.cs index 3a4fb7ea298b..6cf29c51de81 100644 --- a/src/Controls/samples/Controls.Sample/Controls/BordelessEntry/BordelessEntryHandler.cs +++ b/src/Controls/samples/Controls.Sample/Controls/BordelessEntry/BordelessEntryHandler.cs @@ -34,14 +34,13 @@ public static void MapBorder(BordelessEntryHandler handler, BordelessEntry borde public static void MapBorder(BordelessEntryHandler handler, BordelessEntry borderlessEntry) { } -#else +#elif TIZEN public static void MapBorder(BordelessEntryHandler handler, BordelessEntry borderlessEntry) { } -#elif TIZEN +#else public static void MapBorder(BordelessEntryHandler handler, BordelessEntry borderlessEntry) { - } #endif } diff --git a/src/Controls/samples/Controls.Sample/Controls/FocusEffect/FocusPlatformEffect.cs b/src/Controls/samples/Controls.Sample/Controls/FocusEffect/FocusPlatformEffect.cs index 8883f67e4fda..5af77c22fb7b 100644 --- a/src/Controls/samples/Controls.Sample/Controls/FocusEffect/FocusPlatformEffect.cs +++ b/src/Controls/samples/Controls.Sample/Controls/FocusEffect/FocusPlatformEffect.cs @@ -15,6 +15,8 @@ public class FocusPlatformEffect : PlatformEffect Android.Graphics.Color backgroundColor; #elif __IOS__ UIKit.UIColor backgroundColor; +#elif TIZEN + ElmSharp.Color backgroundColor; #endif public FocusPlatformEffect() @@ -33,6 +35,8 @@ protected override void OnAttached() Control.SetBackgroundColor(backgroundColor); #elif __IOS__ Control.BackgroundColor = backgroundColor = UIKit.UIColor.FromRGB(204, 153, 255); +#elif TIZEN + (Control as ElmSharp.Widget).BackgroundColor = backgroundColor = ElmSharp.Color.FromRgb(204, 153, 255); #endif } catch (Exception ex) @@ -75,6 +79,21 @@ protected override void OnElementPropertyChanged(PropertyChangedEventArgs args) Control.BackgroundColor = backgroundColor; } } +#elif TIZEN + if (args.PropertyName == "IsFocused") + { + if (Control is ElmSharp.Widget widget) + { + if (widget.BackgroundColor == backgroundColor) + { + widget.BackgroundColor = ElmSharp.Color.White; + } + else + { + widget.BackgroundColor = backgroundColor; + } + } + } #endif } catch (Exception ex) diff --git a/src/Controls/src/Core/Handlers/NavigationPage/NavigationPageHandler.Tizen.cs b/src/Controls/src/Core/Handlers/NavigationPage/NavigationPageHandler.Tizen.cs deleted file mode 100644 index 03583d02cfcf..000000000000 --- a/src/Controls/src/Core/Handlers/NavigationPage/NavigationPageHandler.Tizen.cs +++ /dev/null @@ -1,256 +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.Handlers; -using Tizen.UIExtensions.ElmSharp; -using TButton = Tizen.UIExtensions.ElmSharp.Button; -using TSpan = Tizen.UIExtensions.Common.Span; -using TTextAlignment = Tizen.UIExtensions.Common.TextAlignment; - -namespace Microsoft.Maui.Controls.Handlers -{ - public partial class NavigationPageHandler : - ViewHandler - { - readonly List _naviItemContentPartList = new List(); - TaskCompletionSource _currentTaskSource = null; - IDictionary _naviItemMap; - - Page PreviousPage => VirtualView.Navigation.NavigationStack.Count > 1 ? VirtualView.Navigation.NavigationStack[VirtualView.Navigation.NavigationStack.Count - 2] : null; - NaviItem CurrentNaviItem => NativeView.NavigationStack.Count > 0 ? NativeView.NavigationStack.Last() : null; - NaviItem PreviousNaviItem => NativeView.NavigationStack.Count > 1 ? NativeView.NavigationStack[NativeView.NavigationStack.Count - 2] : null; - - protected override Naviframe CreateNativeView() - { - return new Naviframe(NativeParent) - { - PreserveContentOnPop = true, - DefaultBackButtonEnabled = false, - }; - } - - protected override void ConnectHandler(Naviframe nativeView) - { - base.ConnectHandler(nativeView); - nativeView.AnimationFinished += OnAnimationFinished; - _naviItemMap = new Dictionary(); - - if (VirtualView == null) - return; - - VirtualView.PushRequested += OnPushRequested; - VirtualView.PopRequested += OnPopRequested; - VirtualView.InternalChildren.CollectionChanged += OnPageCollectionChanged; - - foreach (Page page in VirtualView.InternalChildren) - { - _naviItemMap[page] = NativeView.Push(CreateNavItem(page), SpanTitle(page.Title)); - page.PropertyChanged += NavigationBarPropertyChangedHandler; - - UpdateHasNavigationBar(page); - } - } - - protected override void DisconnectHandler(Naviframe nativeView) - { - base.DisconnectHandler(nativeView); - nativeView.AnimationFinished -= OnAnimationFinished; - - VirtualView.PushRequested -= OnPushRequested; - VirtualView.PopRequested -= OnPopRequested; - VirtualView.InternalChildren.CollectionChanged -= OnPageCollectionChanged; - } - - public static void MapPadding(NavigationPageHandler handler, NavigationPage view) { } - - public static void MapBarTextColor(NavigationPageHandler handler, NavigationPage view) - { - handler.UpdateTitle(view.CurrentPage); - } - - public static void MapBarBackground(NavigationPageHandler handler, NavigationPage view) { } - - public static void MapTitleIcon(NavigationPageHandler handler, NavigationPage view) { } - - public static void MapTitleView(NavigationPageHandler handler, NavigationPage view) { } - - void NavigationBarPropertyChangedHandler(object sender, System.ComponentModel.PropertyChangedEventArgs e) - { - // this handler is invoked only for child pages (contained on a navigation stack) - if (e.PropertyName == NavigationPage.HasNavigationBarProperty.PropertyName) - UpdateHasNavigationBar(sender as Page); - else if (e.PropertyName == NavigationPage.HasBackButtonProperty.PropertyName || - e.PropertyName == NavigationPage.BackButtonTitleProperty.PropertyName) - UpdateHasBackButton(sender as Page); - else if (e.PropertyName == Page.TitleProperty.PropertyName) - UpdateTitle(sender as Page); - } - - void OnPageCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) - { - if (e.OldItems != null) - foreach (Page page in e.OldItems) - page.PropertyChanged -= NavigationBarPropertyChangedHandler; - if (e.NewItems != null) - foreach (Page page in e.NewItems) - page.PropertyChanged += NavigationBarPropertyChangedHandler; - } - - void OnPushRequested(object sender, NavigationRequestedEventArgs nre) - { - if (nre.Animated || NativeView.NavigationStack.Count == 0) - { - _naviItemMap[nre.Page] = NativeView.Push(CreateNavItem(nre.Page), SpanTitle(nre.Page.Title)); - _currentTaskSource = new TaskCompletionSource(); - nre.Task = _currentTaskSource.Task; - - // There is no TransitionFinished (AnimationFinished) event after the first Push - if (NativeView.NavigationStack.Count == 1) - CompleteCurrentNavigationTask(); - } - else - { - _naviItemMap[nre.Page] = NativeView.InsertAfter(NativeView.NavigationStack.Last(), CreateNavItem(nre.Page), SpanTitle(nre.Page.Title)); - } - UpdateHasNavigationBar(nre.Page); - } - - void OnPopRequested(object sender, NavigationRequestedEventArgs nre) - { - if (VirtualView.InternalChildren.Count == NativeView.NavigationStack.Count) - { - nre.Page?.SendDisappearing(); - UpdateNavigationBar(PreviousPage, PreviousNaviItem); - - if (nre.Animated) - { - NativeView.Pop(); - - _currentTaskSource = new TaskCompletionSource(); - nre.Task = _currentTaskSource.Task; - - // There is no TransitionFinished (AnimationFinished) event after Pop the last page - if (NativeView.NavigationStack.Count == 0) - CompleteCurrentNavigationTask(); - } - else - { - CurrentNaviItem?.Delete(); - } - - if (_naviItemMap.ContainsKey(nre.Page)) - _naviItemMap.Remove(nre.Page); - } - } - - void OnAnimationFinished(object sender, EventArgs e) - { - CompleteCurrentNavigationTask(); - } - - void CompleteCurrentNavigationTask() - { - if (_currentTaskSource != null) - { - var tmp = _currentTaskSource; - _currentTaskSource = null; - tmp.SetResult(true); - } - } - - void UpdateHasNavigationBar(Page page) - { - NaviItem item = GetNaviItemForPage(page); - item.SetTabBarStyle(); - item.TitleBarVisible = (bool)page.GetValue(NavigationPage.HasNavigationBarProperty); - UpdateBarBackgroundColor(item); - } - - void UpdateNavigationBar(Page page, NaviItem item = null) - { - if (item == null) - item = GetNaviItemForPage(page); - - UpdateTitle(page, item); - UpdateBarBackgroundColor(item); - } - - void UpdateHasBackButton(Page page, NaviItem item = null) - { - if (item == null) - item = GetNaviItemForPage(page); - - TButton button = null; - - if ((bool)page.GetValue(NavigationPage.HasBackButtonProperty) && NativeView.NavigationStack.Count > 1) - { - button = CreateNavigationButton((string)page.GetValue(NavigationPage.BackButtonTitleProperty)); - } - item.SetBackButton(button); - } - - void UpdateTitle(Page page, NaviItem item = null) - { - if (item == null) - item = GetNaviItemForPage(page); - - item.SetTitle(SpanTitle(page.Title)); - } - - string SpanTitle(string Title) - { - TSpan span = new TSpan - { - Text = Title, - HorizontalTextAlignment = TTextAlignment.Center, - ForegroundColor = VirtualView.BarTextColor.ToNative() - }; - return span.GetMarkupText(); - } - - void UpdateBarBackgroundColor(NaviItem item) - { - item.TitleBarBackgroundColor = VirtualView.BarBackgroundColor.ToNativeEFL(); - } - - TButton CreateNavigationButton(string text) - { - var button = new TButton(NativeParent) - { - Text = text - }; - button.SetNavigationBackStyle(); - button.Clicked += (sender, e) => - { - if (!VirtualView.SendBackButtonPressed()) - Tizen.Applications.Application.Current.Exit(); - }; - _naviItemContentPartList.Add(button); - button.Deleted += NaviItemPartContentDeletedHandler; - return button; - } - - void NaviItemPartContentDeletedHandler(object sender, EventArgs e) - { - _naviItemContentPartList.Remove(sender as Widget); - } - - NaviItem GetNaviItemForPage(Page page) - { - NaviItem item; - if (_naviItemMap.TryGetValue(page, out item)) - { - return item; - } - return null; - } - - EvasObject CreateNavItem(Page page) - { - return page.ToNative(MauiContext); - } - } -} diff --git a/src/Core/src/Fonts/FontManager.Tizen.cs b/src/Core/src/Fonts/FontManager.Tizen.cs index 6d1a9ee6f512..06f993c56066 100644 --- a/src/Core/src/Fonts/FontManager.Tizen.cs +++ b/src/Core/src/Fonts/FontManager.Tizen.cs @@ -7,7 +7,7 @@ namespace Microsoft.Maui { public class FontManager : IFontManager { - readonly ConcurrentDictionary<(string family, float size, FontSlant slant), string> _fonts = new(); + readonly ConcurrentDictionary<(string? family, float size, FontSlant slant), string> _fonts = new(); readonly IFontRegistrar _fontRegistrar; readonly ILogger? _logger; @@ -21,17 +21,17 @@ public FontManager(IFontRegistrar fontRegistrar, ILogger? logger = public string GetFont(Font font) { - var size = (float)font.FontSize; + var size = (float)font.Size; - return GetFont(font.FontFamily, size, font.FontSlant, GetNativeFontFamily); + return GetFont(font.Family, size, font.Slant, GetNativeFontFamily); } - public string GetFontFamily(string fontFamliy) + public string GetFontFamily(string? fontFamliy) { if (string.IsNullOrEmpty(fontFamliy)) return ""; - var cleansedFont = CleanseFontName(fontFamliy); + var cleansedFont = CleanseFontName(fontFamliy??string.Empty); if (cleansedFont == null) return ""; @@ -48,17 +48,17 @@ public string GetFontFamily(string fontFamliy) } } - string GetFont(string family, float size, FontSlant slant, Func<(string, float, FontSlant), string> factory) + string GetFont(string? family, float size, FontSlant slant, Func<(string?, float, FontSlant), string> factory) { return _fonts.GetOrAdd((family, size, slant), factory); } - string GetNativeFontFamily((string family, float size, FontSlant slant) fontKey) + string GetNativeFontFamily((string? family, float size, FontSlant slant) fontKey) { if (string.IsNullOrEmpty(fontKey.family)) return ""; - var cleansedFont = CleanseFontName(fontKey.family); + var cleansedFont = CleanseFontName(fontKey.family??string.Empty); if (cleansedFont == null) return ""; diff --git a/src/Core/src/Fonts/IFontManager.Tizen.cs b/src/Core/src/Fonts/IFontManager.Tizen.cs index 7e5cfc9767f0..be870ebbc69c 100644 --- a/src/Core/src/Fonts/IFontManager.Tizen.cs +++ b/src/Core/src/Fonts/IFontManager.Tizen.cs @@ -4,6 +4,6 @@ public interface IFontManager { string GetFont(Font font); - string GetFontFamily(string font); + string GetFontFamily(string? font); } } \ No newline at end of file diff --git a/src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs b/src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs index 7b4aedc0e820..18c4a67e7dc8 100644 --- a/src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs +++ b/src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs @@ -54,7 +54,7 @@ public override void SetVirtualView(IView view) NativeView.Children.Clear(); - foreach (var child in VirtualView.Children) + foreach (var child in VirtualView) { NativeView.Children.Add(child.ToNative(MauiContext)); if (child.Handler is INativeViewHandler thandler) @@ -139,8 +139,8 @@ protected void OnLayoutUpdated(object? sender, LayoutEventArgs e) nativeGeometry.X -= VirtualView.Margin.Left; nativeGeometry.Y -= VirtualView.Margin.Top; - VirtualView.Measure(nativeGeometry.Width, nativeGeometry.Height); - VirtualView.Arrange(nativeGeometry); + VirtualView.LayoutManager.Measure(nativeGeometry.Width, nativeGeometry.Height); + VirtualView.LayoutManager.ArrangeChildren(nativeGeometry); } } } diff --git a/src/Core/src/Handlers/NavigationPage/NavigationPageHandler.Tizen.cs b/src/Core/src/Handlers/NavigationPage/NavigationPageHandler.Tizen.cs new file mode 100644 index 000000000000..454a1084293c --- /dev/null +++ b/src/Core/src/Handlers/NavigationPage/NavigationPageHandler.Tizen.cs @@ -0,0 +1,327 @@ +#nullable enable + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using ElmSharp; +using Microsoft.Maui.Handlers; +using Tizen.UIExtensions.ElmSharp; +using TButton = Tizen.UIExtensions.ElmSharp.Button; +using TSpan = Tizen.UIExtensions.Common.Span; +using TTextAlignment = Tizen.UIExtensions.Common.TextAlignment; + +namespace Microsoft.Maui.Handlers +{ + internal partial class NavigationPageHandler : + ViewHandler, INativeViewHandler + { + readonly List _naviItemContentPartList = new List(); + TaskCompletionSource? _currentTaskSource = null; + IDictionary? _naviItemMap; + + IView? PreviousPage => VirtualView.NavigationStack.Count > 1 ? VirtualView.NavigationStack[VirtualView.NavigationStack.Count - 2] : null; + NaviItem? CurrentNaviItem => NativeView.NavigationStack.Count > 0 ? NativeView.NavigationStack.Last() : null; + NaviItem? PreviousNaviItem => NativeView.NavigationStack.Count > 1 ? NativeView.NavigationStack[NativeView.NavigationStack.Count - 2] : null; + + protected override Naviframe CreateNativeView() + { + return new Naviframe(NativeParent) + { + PreserveContentOnPop = true, + DefaultBackButtonEnabled = false, + }; + } + + private static void PushAsyncTo(NavigationPageHandler arg1, INavigationView arg2, object? arg3) + { + if (arg3 is MauiNavigationRequestedEventArgs args) + arg1.OnPushRequested(args); + } + + private static void PopAsyncTo(NavigationPageHandler arg1, INavigationView arg2, object? arg3) + { + if (arg3 is MauiNavigationRequestedEventArgs args) + arg1.OnPopRequested(args); + } + + void OnPushRequested(MauiNavigationRequestedEventArgs e) + { + _ = _naviItemMap ?? throw new InvalidOperationException($"{nameof(_naviItemMap)} cannot be null."); + + if (e.Animated || NativeView.NavigationStack.Count == 0) + { + _naviItemMap[e.Page] = NativeView.Push(CreateNavItem(e.Page), SpanTitle(e.Page)); + _currentTaskSource = new TaskCompletionSource(); + e.Task = _currentTaskSource.Task; + + // There is no TransitionFinished (AnimationFinished) event after the first Push + if (NativeView.NavigationStack.Count == 1) + CompleteCurrentNavigationTask(); + } + else + { + _naviItemMap[e.Page] = NativeView.InsertAfter(NativeView.NavigationStack.Last(), CreateNavItem(e.Page), SpanTitle(e.Page)); + } + //UpdateHasNavigationBar(nre.Page); + } + + void OnPopRequested(MauiNavigationRequestedEventArgs e) + { + _ = _naviItemMap ?? throw new InvalidOperationException($"{nameof(_naviItemMap)} cannot be null."); + + if (VirtualView.NavigationStack.Count == NativeView.NavigationStack.Count) + { + //e.Page?.SendDisappearing(); + //UpdateNavigationBar(PreviousPage, PreviousNaviItem); + + if (e.Animated) + { + NativeView.Pop(); + + _currentTaskSource = new TaskCompletionSource(); + e.Task = _currentTaskSource.Task; + + // There is no TransitionFinished (AnimationFinished) event after Pop the last page + if (NativeView.NavigationStack.Count == 0) + CompleteCurrentNavigationTask(); + } + else + { + CurrentNaviItem?.Delete(); + } + + if (_naviItemMap.ContainsKey(e.Page)) + _naviItemMap.Remove(e.Page); + } + } + + protected override void ConnectHandler(Naviframe nativeView) + { + base.ConnectHandler(nativeView); + nativeView.AnimationFinished += OnAnimationFinished; + _naviItemMap = new Dictionary(); + + if (VirtualView == null) + return; + + //VirtualView.PushRequested += OnPushRequested; + //VirtualView.PopRequested += OnPopRequested; + //VirtualView.InternalChildren.CollectionChanged += OnPageCollectionChanged; + + foreach (var page in VirtualView.NavigationStack) + { + _naviItemMap[page] = NativeView.Push(CreateNavItem(page), SpanTitle(page)); + //page.PropertyChanged += NavigationBarPropertyChangedHandler; + + //UpdateHasNavigationBar(page); + } + } + + protected override void DisconnectHandler(Naviframe nativeView) + { + base.DisconnectHandler(nativeView); + nativeView.AnimationFinished -= OnAnimationFinished; + + //VirtualView.PushRequested -= OnPushRequested; + //VirtualView.PopRequested -= OnPopRequested; + //VirtualView.InternalChildren.CollectionChanged -= OnPageCollectionChanged; + } + + //public static void MapPadding(NavigationPageHandler handler, INavigationView view) { } + + //public static void MapBarTextColor(NavigationPageHandler handler, INavigationView view) + //{ + // //handler.UpdateTitle(view.CurrentPage); + //} + + public static void MapBarBackground(NavigationPageHandler handler, INavigationView view) { } + + public static void MapTitleIcon(NavigationPageHandler handler, INavigationView view) { } + + public static void MapTitleView(NavigationPageHandler handler, INavigationView view) { } + + //void NavigationBarPropertyChangedHandler(object sender, System.ComponentModel.PropertyChangedEventArgs e) + //{ + // // this handler is invoked only for child pages (contained on a navigation stack) + // if (e.PropertyName == INavigationView.HasNavigationBarProperty.PropertyName) + // UpdateHasNavigationBar(sender as Page); + // else if (e.PropertyName == NavigationPage.HasBackButtonProperty.PropertyName || + // e.PropertyName == NavigationPage.BackButtonTitleProperty.PropertyName) + // UpdateHasBackButton(sender as Page); + // else if (e.PropertyName == Page.TitleProperty.PropertyName) + // UpdateTitle(sender as Page); + //} + + //void OnPageCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + //{ + // if (e.OldItems != null) + // foreach (Page page in e.OldItems) + // page.PropertyChanged -= NavigationBarPropertyChangedHandler; + // if (e.NewItems != null) + // foreach (Page page in e.NewItems) + // page.PropertyChanged += NavigationBarPropertyChangedHandler; + //} + + //void OnPushRequested(object sender, NavigationRequestedEventArgs nre) + //{ + // if (nre.Animated || NativeView.NavigationStack.Count == 0) + // { + // _naviItemMap[nre.Page] = NativeView.Push(CreateNavItem(nre.Page), SpanTitle(nre.Page.Title)); + // _currentTaskSource = new TaskCompletionSource(); + // nre.Task = _currentTaskSource.Task; + + // // There is no TransitionFinished (AnimationFinished) event after the first Push + // if (NativeView.NavigationStack.Count == 1) + // CompleteCurrentNavigationTask(); + // } + // else + // { + // _naviItemMap[nre.Page] = NativeView.InsertAfter(NativeView.NavigationStack.Last(), CreateNavItem(nre.Page), SpanTitle(nre.Page.Title)); + // } + // UpdateHasNavigationBar(nre.Page); + //} + + //void OnPopRequested(object sender, NavigationRequestedEventArgs nre) + //{ + // if (VirtualView.InternalChildren.Count == NativeView.NavigationStack.Count) + // { + // nre.Page?.SendDisappearing(); + // UpdateNavigationBar(PreviousPage, PreviousNaviItem); + + // if (nre.Animated) + // { + // NativeView.Pop(); + + // _currentTaskSource = new TaskCompletionSource(); + // nre.Task = _currentTaskSource.Task; + + // // There is no TransitionFinished (AnimationFinished) event after Pop the last page + // if (NativeView.NavigationStack.Count == 0) + // CompleteCurrentNavigationTask(); + // } + // else + // { + // CurrentNaviItem?.Delete(); + // } + + // if (_naviItemMap.ContainsKey(nre.Page)) + // _naviItemMap.Remove(nre.Page); + // } + //} + + void OnAnimationFinished(object sender, EventArgs e) + { + CompleteCurrentNavigationTask(); + } + + void CompleteCurrentNavigationTask() + { + if (_currentTaskSource != null) + { + var tmp = _currentTaskSource; + _currentTaskSource = null; + tmp.SetResult(true); + } + } + + //void UpdateHasNavigationBar(IView page) + //{ + // NaviItem item = GetNaviItemForPage(page); + // item.SetTabBarStyle(); + // item.TitleBarVisible = (bool)page.GetValue(NavigationPage.HasNavigationBarProperty); + // UpdateBarBackgroundColor(item); + //} + + //void UpdateNavigationBar(Page page, NaviItem item = null) + //{ + // if (item == null) + // item = GetNaviItemForPage(page); + + // UpdateTitle(page, item); + // UpdateBarBackgroundColor(item); + //} + + //void UpdateHasBackButton(Page page, NaviItem item = null) + //{ + // if (item == null) + // item = GetNaviItemForPage(page); + + // TButton button = null; + + // if ((bool)page.GetValue(NavigationPage.HasBackButtonProperty) && NativeView.NavigationStack.Count > 1) + // { + // button = CreateNavigationButton((string)page.GetValue(NavigationPage.BackButtonTitleProperty)); + // } + // item.SetBackButton(button); + //} + + void UpdateTitle(IView page, NaviItem? item = null) + { + if (item == null) + item = GetNaviItemForPage(page); + + item?.SetTitle(SpanTitle(page)); + } + + string SpanTitle(IView view) + { + if (view is not IPage page) + return string.Empty; + else + { + var span = new TSpan + { + Text = page.Title, + HorizontalTextAlignment = TTextAlignment.Center, + //ForegroundColor = VirtualView.BarTextColor.ToNative() + }; + return span.GetMarkupText(); + } + } + + //void UpdateBarBackgroundColor(NaviItem item) + //{ + // item.TitleBarBackgroundColor = VirtualView.BarBackgroundColor.ToNativeEFL(); + //} + + //TButton CreateNavigationButton(string text) + //{ + // var button = new TButton(NativeParent) + // { + // Text = text + // }; + // button.SetNavigationBackStyle(); + // button.Clicked += (sender, e) => + // { + // if (!VirtualView.SendBackButtonPressed()) + // Tizen.Applications.Application.Current.Exit(); + // }; + // _naviItemContentPartList.Add(button); + // button.Deleted += NaviItemPartContentDeletedHandler; + // return button; + //} + + //void NaviItemPartContentDeletedHandler(object sender, EventArgs e) + //{ + // _naviItemContentPartList.Remove(sender as Widget); + //} + + NaviItem? GetNaviItemForPage(IView page) + { + _ = _naviItemMap ?? throw new InvalidOperationException($"{nameof(_naviItemMap)} cannot be null."); + + NaviItem item; + if (_naviItemMap.TryGetValue(page, out item)) + { + return item; + } + return null; + } + + EvasObject CreateNavItem(IView page) + { + return page.ToNative(MauiContext!); + } + } +} diff --git a/src/Core/src/Handlers/Picker/PickerHandler.Tizen.cs b/src/Core/src/Handlers/Picker/PickerHandler.Tizen.cs index bb2bbe5ef056..cc5063d5c7e5 100644 --- a/src/Core/src/Handlers/Picker/PickerHandler.Tizen.cs +++ b/src/Core/src/Handlers/Picker/PickerHandler.Tizen.cs @@ -68,7 +68,7 @@ void Reload() NativeView.UpdatePicker(VirtualView); } - public static void MapReload(PickerHandler handler, IPicker picker) => handler.Reload(); + public static void MapReload(PickerHandler handler, IPicker picker, object? args) => handler.Reload(); public static void MapTitleColor(PickerHandler handler, IPicker picker) { diff --git a/src/Core/src/Handlers/ScrollView/ScrollViewHandler.Tizen.cs b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.Tizen.cs new file mode 100644 index 000000000000..916b7c6c8cb4 --- /dev/null +++ b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.Tizen.cs @@ -0,0 +1,127 @@ +using System; +using Microsoft.Maui.Graphics; +using Tizen.UIExtensions.Common; +using Tizen.UIExtensions.ElmSharp; +using EContainer = ElmSharp.Container; +using EcoreMainloop = ElmSharp.EcoreMainloop; + +namespace Microsoft.Maui.Handlers +{ + public partial class ScrollViewHandler : ViewHandler + { + EContainer? _scrollCanvas; + + Box? Canvas => (Box?)_scrollCanvas; + + protected override ScrollView CreateNativeView() + { + _ = NativeParent ?? throw new InvalidOperationException($"{nameof(NativeParent)} cannot be null"); + var scrollView = new ScrollView(NativeParent); + _scrollCanvas = new Box(scrollView); + scrollView.SetContent(_scrollCanvas); + return scrollView; + } + + protected override void ConnectHandler(ScrollView nativeView) + { + base.ConnectHandler(nativeView); + _ = Canvas ?? throw new InvalidOperationException($"{nameof(Canvas)} cannot be null"); + + nativeView.Scrolled += OnScrolled; + Canvas.LayoutUpdated += OnContentLayoutUpdated; + } + + protected override void DisconnectHandler(ScrollView nativeView) + { + base.DisconnectHandler(nativeView); + _ = Canvas ?? throw new InvalidOperationException($"{nameof(Canvas)} cannot be null"); + + nativeView.Scrolled -= OnScrolled; + Canvas.LayoutUpdated -= OnContentLayoutUpdated; + } + + void ScrollAnimationEnded(object? sender, EventArgs e) + { + VirtualView.ScrollFinished(); + } + + void OnScrolled(object? sender, EventArgs e) + { + var region = NativeView.CurrentRegion.ToDP(); + VirtualView.HorizontalOffset = region.X; + VirtualView.VerticalOffset = region.Y; + } + + void OnContentLayoutUpdated(object? sender, LayoutEventArgs e) + { + UpdateContentSize(); + } + + void UpdateContentSize() + { + _ = Canvas ?? throw new InvalidOperationException($"{nameof(Canvas)} cannot be null"); + + // TODO: should consider Padding.HorizontalThickness/VerticalThickness here. + Canvas.MinimumWidth = VirtualView.ContentSize.Width.ToScaledPixel(); + Canvas.MinimumHeight = VirtualView.ContentSize.Height.ToScaledPixel(); + + // elm-scroller updates the CurrentRegion after render + EcoreMainloop.Post(() => + { + if (NativeView != null) + { + OnScrolled(NativeView, EventArgs.Empty); + } + }); + } + + public static void MapContent(ScrollViewHandler handler, IScrollView scrollView) + { + if (handler.MauiContext == null || scrollView.Content == null || handler.Canvas == null) + { + return; + } + + handler.Canvas.UnPackAll(); + handler.Canvas.PackEnd(scrollView.Content.ToNative(handler.MauiContext)); + handler.UpdateContentSize(); + } + + public static void MapContentSize(ScrollViewHandler handler, IScrollView scrollView) + { + handler.UpdateContentSize(); + } + + public static void MapHorizontalScrollBarVisibility(ScrollViewHandler handler, IScrollView scrollView) + { + handler.NativeView?.UpdateHorizontalScrollBarVisibility(scrollView.HorizontalScrollBarVisibility); + } + + public static void MapVerticalScrollBarVisibility(ScrollViewHandler handler, IScrollView scrollView) + { + handler.NativeView?.UpdateVerticalScrollBarVisibility(scrollView.VerticalScrollBarVisibility); + } + + public static void MapOrientation(ScrollViewHandler handler, IScrollView scrollView) + { + handler.NativeView?.UpdateOrientation(scrollView.Orientation); + } + + public static void MapRequestScrollTo(ScrollViewHandler handler, IScrollView scrollView, object? args) + { + if (args is ScrollToRequest request) + { + var x = request.HoriztonalOffset; + var y = request.VerticalOffset; + + var region = new Rectangle(x, y, scrollView.Width, scrollView.Height).ToEFLPixel(); + handler.NativeView.ScrollTo(region, true); + + if (request.Instant) + { + scrollView.ScrollFinished(); + } + } + } + } +} diff --git a/src/Core/src/Handlers/ScrollView/ScrollViewHandler.cs b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.cs index 2c715b6c34c4..5b2046a9fb78 100644 --- a/src/Core/src/Handlers/ScrollView/ScrollViewHandler.cs +++ b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.cs @@ -20,7 +20,7 @@ public partial class ScrollViewHandler : IScrollViewHandler [nameof(IScrollView.HorizontalScrollBarVisibility)] = MapHorizontalScrollBarVisibility, [nameof(IScrollView.VerticalScrollBarVisibility)] = MapVerticalScrollBarVisibility, [nameof(IScrollView.Orientation)] = MapOrientation, -#if __IOS__ +#if __IOS__ || TIZEN [nameof(IScrollView.ContentSize)] = MapContentSize, [nameof(IScrollView.IsEnabled)] = MapIsEnabled, #endif diff --git a/src/Core/src/Hosting/LifecycleEvents/AppHostBuilderExtensions.Tizen.cs b/src/Core/src/Hosting/LifecycleEvents/AppHostBuilderExtensions.Tizen.cs new file mode 100644 index 000000000000..91563d84046f --- /dev/null +++ b/src/Core/src/Hosting/LifecycleEvents/AppHostBuilderExtensions.Tizen.cs @@ -0,0 +1,37 @@ +using Microsoft.Maui.Hosting; +using Microsoft.Maui.LifecycleEvents; +using System; + +namespace Microsoft.Maui.LifecycleEvents +{ + public static partial class AppHostBuilderExtensions + { + internal static IAppHostBuilder ConfigureCrossPlatformLifecycleEvents(this IAppHostBuilder builder) => + builder.ConfigureLifecycleEvents(events => events.AddTizen(OnConfigureLifeCycle)); + + static void OnConfigureLifeCycle(ITizenLifecycleBuilder tizen) + { + tizen + .OnCreate((app) => + { + // OnCreate is only ever called once when the app is initally created + app.GetWindow().Created(); + }) + .OnResume(app => + { + app.GetWindow().Resumed(); + app.GetWindow().Activated(); + + }) + .OnPause(app => + { + app.GetWindow().Deactivated(); + app.GetWindow().Stopped(); + }) + .OnTerminate(app => + { + app.GetWindow().Destroying(); + }); + } + } +} diff --git a/src/Core/src/Platform/Tizen/CoreUIAppContext.cs b/src/Core/src/Platform/Tizen/CoreUIAppContext.cs index d6641f4f168e..9fcc6dfb728e 100644 --- a/src/Core/src/Platform/Tizen/CoreUIAppContext.cs +++ b/src/Core/src/Platform/Tizen/CoreUIAppContext.cs @@ -121,7 +121,7 @@ public void SetBackButtonPressedHandler(Func handler) static Window CreateDefaultWindow() { - return GetPreloadedWindow() ?? new Window("XamarinWindow"); + return GetPreloadedWindow() ?? new Window("MauiDefaultWindow"); } static Window? GetPreloadedWindow() diff --git a/src/Core/src/Platform/Tizen/CoreUIAppExtensions.cs b/src/Core/src/Platform/Tizen/CoreUIAppExtensions.cs new file mode 100644 index 000000000000..c730e41e1cbb --- /dev/null +++ b/src/Core/src/Platform/Tizen/CoreUIAppExtensions.cs @@ -0,0 +1,25 @@ +using System; +using Tizen.Applications; +using EWindow = ElmSharp.Window; + +namespace Microsoft.Maui +{ + internal static class CoreUIAppExtensions + { + public static IWindow GetWindow(this CoreUIApplication application) + { + if (MauiApplication.Current.VirtualWindow != null) + return MauiApplication.Current.VirtualWindow; + + var nativeWindow = MauiApplication.Current.MainWindow; + + foreach (var window in MauiApplication.Current.Application.Windows) + { + if (window?.Handler?.NativeView is EWindow win && win == nativeWindow) + return window; + } + + throw new InvalidOperationException("Window Not Found"); + } + } +} diff --git a/src/Core/src/Platform/Tizen/EntryExtensions.cs b/src/Core/src/Platform/Tizen/EntryExtensions.cs index bb2aeab857f1..87acb5941f48 100644 --- a/src/Core/src/Platform/Tizen/EntryExtensions.cs +++ b/src/Core/src/Platform/Tizen/EntryExtensions.cs @@ -61,9 +61,9 @@ public static void UpdateClearButtonVisibility(this Entry nativeEntry, IEntry en public static void UpdateFont(this Entry nativeEntry, ITextStyle textStyle, IFontManager fontManager) { nativeEntry.BatchBegin(); - nativeEntry.FontSize = textStyle.Font.FontSize; + nativeEntry.FontSize = textStyle.Font.Size; nativeEntry.FontAttributes = textStyle.Font.GetFontAttributes(); - nativeEntry.FontFamily = fontManager.GetFontFamily(textStyle.Font.FontFamily) ?? ""; + nativeEntry.FontFamily = fontManager.GetFontFamily(textStyle.Font.Family) ?? ""; nativeEntry.BatchCommit(); } diff --git a/src/Core/src/Platform/Tizen/HandlerExtensions.cs b/src/Core/src/Platform/Tizen/HandlerExtensions.cs index 43df1d04043b..2be109138318 100644 --- a/src/Core/src/Platform/Tizen/HandlerExtensions.cs +++ b/src/Core/src/Platform/Tizen/HandlerExtensions.cs @@ -20,10 +20,10 @@ public static EvasObject ToNative(this IElement view, IMauiContext context) handler = null; if (handler == null) - handler = context.Handlers.GetHandler(view.GetType()) as IViewHandler; + handler = context.Handlers.GetHandler(view.GetType()); if (handler == null) - throw new Exception($"Handler not found for view {view} or was not {nameof(IViewHandler)}."); + throw new Exception($"Handler not found for view {view}."); handler.SetMauiContext(context); diff --git a/src/Core/src/Platform/Tizen/LabelExtensions.cs b/src/Core/src/Platform/Tizen/LabelExtensions.cs index 7a8825c05e52..a514dcbaa3a0 100644 --- a/src/Core/src/Platform/Tizen/LabelExtensions.cs +++ b/src/Core/src/Platform/Tizen/LabelExtensions.cs @@ -20,9 +20,9 @@ public static void UpdateTextColor(this Label nativeLabel, ILabel label) public static void UpdateFont(this Label nativeLabel, ILabel label, IFontManager fontManager) { nativeLabel.BatchBegin(); - nativeLabel.FontSize = label.Font.FontSize; + nativeLabel.FontSize = label.Font.Size; nativeLabel.FontAttributes = label.Font.GetFontAttributes(); - nativeLabel.FontFamily = fontManager.GetFontFamily(label.Font.FontFamily)??""; + nativeLabel.FontFamily = fontManager.GetFontFamily(label.Font.Family)??""; nativeLabel.BatchCommit(); } @@ -49,7 +49,7 @@ public static void UpdateTextDecorations(this Label nativeLabel, ILabel label) public static FontAttributes GetFontAttributes(this Font font) { FontAttributes attributes = font.Weight == FontWeight.Bold ? FontAttributes.Bold : FontAttributes.None; - if (font.FontSlant != FontSlant.Default) + if (font.Slant != FontSlant.Default) { if (attributes == FontAttributes.None) attributes = FontAttributes.Italic; diff --git a/src/Core/src/Platform/Tizen/MauiApplication.cs b/src/Core/src/Platform/Tizen/MauiApplication.cs index 7cddf5f68485..cfc9c7b8f654 100644 --- a/src/Core/src/Platform/Tizen/MauiApplication.cs +++ b/src/Core/src/Platform/Tizen/MauiApplication.cs @@ -61,6 +61,7 @@ Window CreateNativeWindow() var activationState = new ActivationState(mauiContext); var window = Application.CreateWindow(activationState); + _virtualWindow = new WeakReference(window); tizenWindow.SetWindow(window, mauiContext); return tizenWindow; @@ -129,6 +130,17 @@ void ConfigureNativeServices(HostBuilderContext ctx, IServiceCollection services public abstract class MauiApplication : CoreUIApplication { + internal WeakReference? _virtualWindow; + internal IWindow? VirtualWindow + { + get + { + IWindow? window = null; + _virtualWindow?.TryGetTarget(out window); + return window; + } + } + protected MauiApplication() { Current = this; diff --git a/src/Core/src/Platform/Tizen/ScrollViewExtensions.cs b/src/Core/src/Platform/Tizen/ScrollViewExtensions.cs new file mode 100644 index 000000000000..52fd74710c6a --- /dev/null +++ b/src/Core/src/Platform/Tizen/ScrollViewExtensions.cs @@ -0,0 +1,55 @@ +using ElmSharp; +using Tizen.UIExtensions.ElmSharp; + +namespace Microsoft.Maui +{ + public static class ScrollViewExtensions + { + public static void UpdateVerticalScrollBarVisibility(this ScrollView scrollView, ScrollBarVisibility scrollBarVisibility) + { + scrollView.VerticalScrollBarVisiblePolicy = scrollBarVisibility.ToNative(); + } + + public static void UpdateHorizontalScrollBarVisibility(this ScrollView scrollView, ScrollBarVisibility scrollBarVisibility) + { + scrollView.HorizontalScrollBarVisiblePolicy = scrollBarVisibility.ToNative(); + } + + public static void UpdateOrientation(this ScrollView scrollView, ScrollOrientation scrollOrientation) + { + switch (scrollOrientation) + { + case ScrollOrientation.Horizontal: + scrollView.ScrollBlock = ScrollBlock.Vertical; + scrollView.HorizontalScrollBarVisiblePolicy = ScrollBarVisiblePolicy.Auto; + scrollView.VerticalScrollBarVisiblePolicy = ScrollBarVisiblePolicy.Invisible; + break; + case ScrollOrientation.Vertical: + scrollView.ScrollBlock = ScrollBlock.Horizontal; + scrollView.HorizontalScrollBarVisiblePolicy = ScrollBarVisiblePolicy.Invisible; + scrollView.VerticalScrollBarVisiblePolicy = ScrollBarVisiblePolicy.Auto; + break; + default: + scrollView.ScrollBlock = ScrollBlock.None; + scrollView.HorizontalScrollBarVisiblePolicy = ScrollBarVisiblePolicy.Auto; + scrollView.VerticalScrollBarVisiblePolicy = ScrollBarVisiblePolicy.Auto; + break; + } + } + + public static ScrollBarVisiblePolicy ToNative(this ScrollBarVisibility visibility) + { + switch (visibility) + { + case ScrollBarVisibility.Default: + return ScrollBarVisiblePolicy.Auto; + case ScrollBarVisibility.Always: + return ScrollBarVisiblePolicy.Visible; + case ScrollBarVisibility.Never: + return ScrollBarVisiblePolicy.Invisible; + default: + return ScrollBarVisiblePolicy.Auto; + } + } + } +} \ No newline at end of file diff --git a/src/Core/src/Platform/Tizen/SemanticExtensions.cs b/src/Core/src/Platform/Tizen/SemanticExtensions.cs new file mode 100644 index 000000000000..f641969d5648 --- /dev/null +++ b/src/Core/src/Platform/Tizen/SemanticExtensions.cs @@ -0,0 +1,19 @@ +using System; +using ElmSharp.Accessible; + +namespace Microsoft.Maui +{ + public static partial class SemanticExtensions + { + public static void SetSemanticFocus(this IFrameworkElement element) + { + if (element?.Handler?.NativeView == null) + throw new NullReferenceException("Can't access view from a null handler"); + + if (element.Handler.NativeView is not AccessibleObject) + return; + + //TODO : Need to implement + } + } +}