From 49cfea617d0736e61f27d527a13a0d93bd048005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=AF=BC=EC=84=B1=ED=98=84/Common=20Platform=20Lab=28SR?= =?UTF-8?q?=29/Staff=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Wed, 3 Nov 2021 16:01:52 +0900 Subject: [PATCH] [Tizen] Remove TVNavigationDrawer TVNavigationView (#223) * [Tizen] Remove TVNavigationDrawer TVNavigationView * [Elmsharp] Update Tizen.UIExtensions version --- ...osoft.Maui.Controls.MultiTargeting.targets | 2 +- .../Tizen/Extensions/ShellExtensions.cs | 17 ++ .../Core/Platform/Tizen/Shell/ShellView.cs | 2 +- .../Tizen/Shell/TVNavigationDrawer.cs | 256 ------------------ .../Platform/Tizen/Shell/TVNavigationView.cs | 27 -- .../Platform/Tizen/Shell/ThemeConstants.cs | 5 - .../Core/Platform/Tizen/Shell/ThemeManager.cs | 18 -- 7 files changed, 19 insertions(+), 308 deletions(-) create mode 100644 src/Controls/src/Core/Platform/Tizen/Extensions/ShellExtensions.cs delete mode 100644 src/Controls/src/Core/Platform/Tizen/Shell/TVNavigationDrawer.cs delete mode 100644 src/Controls/src/Core/Platform/Tizen/Shell/TVNavigationView.cs diff --git a/.nuspec/Microsoft.Maui.Controls.MultiTargeting.targets b/.nuspec/Microsoft.Maui.Controls.MultiTargeting.targets index 2c640ebb99ba..44b45ad94555 100644 --- a/.nuspec/Microsoft.Maui.Controls.MultiTargeting.targets +++ b/.nuspec/Microsoft.Maui.Controls.MultiTargeting.targets @@ -124,6 +124,6 @@ - + diff --git a/src/Controls/src/Core/Platform/Tizen/Extensions/ShellExtensions.cs b/src/Controls/src/Core/Platform/Tizen/Extensions/ShellExtensions.cs new file mode 100644 index 000000000000..134b7962375d --- /dev/null +++ b/src/Controls/src/Core/Platform/Tizen/Extensions/ShellExtensions.cs @@ -0,0 +1,17 @@ +using Tizen.UIExtensions.Common; + +namespace Microsoft.Maui.Controls.Platform +{ + public static class ShellExtensions + { + public static DrawerBehavior ToNative(this FlyoutBehavior behavior) + { + if (behavior == FlyoutBehavior.Disabled) + return DrawerBehavior.Disabled; + else if (behavior == FlyoutBehavior.Locked) + return DrawerBehavior.Locked; + else + return DrawerBehavior.Drawer; + } + } +} \ No newline at end of file diff --git a/src/Controls/src/Core/Platform/Tizen/Shell/ShellView.cs b/src/Controls/src/Core/Platform/Tizen/Shell/ShellView.cs index bcd1eb39e8ef..30586cc35eef 100644 --- a/src/Controls/src/Core/Platform/Tizen/Shell/ShellView.cs +++ b/src/Controls/src/Core/Platform/Tizen/Shell/ShellView.cs @@ -192,7 +192,7 @@ protected virtual void UpdateFlyoutBehavior() { _ = Element ?? throw new InvalidOperationException($"{nameof(Element)} should have been set by base class."); - _navigationDrawer.IsSplit = (Element.FlyoutBehavior == FlyoutBehavior.Locked) ? true : false; + _navigationDrawer.DrawerBehavior = Element.FlyoutBehavior.ToNative(); } protected virtual void BuildMenu() diff --git a/src/Controls/src/Core/Platform/Tizen/Shell/TVNavigationDrawer.cs b/src/Controls/src/Core/Platform/Tizen/Shell/TVNavigationDrawer.cs deleted file mode 100644 index 2c15c235f8d8..000000000000 --- a/src/Controls/src/Core/Platform/Tizen/Shell/TVNavigationDrawer.cs +++ /dev/null @@ -1,256 +0,0 @@ -# nullable enable - -using System; -using ElmSharp; -using Tizen.UIExtensions.ElmSharp; -using EBox = ElmSharp.Box; -using EColor = ElmSharp.Color; -using TButton = Tizen.UIExtensions.ElmSharp.Button; -using ITNavigationView = Tizen.UIExtensions.ElmSharp.INavigationView; - -namespace Microsoft.Maui.Controls.Platform -{ - public class TVNavigationDrawer : EBox, INavigationDrawer, IFlyoutBehaviorObserver - { - EBox _drawerBox; - EBox _mainBox; - EvasObject? _main; - EvasObject? _drawer; - TButton _focusControlArea; - - FlyoutBehavior _behavior; - bool _isOpen; - - double _openRatio; - - public TVNavigationDrawer(EvasObject parent) : base(parent) - { - SetLayoutCallback(OnLayout); - - _drawerBox = new EBox(parent); - _drawerBox.Show(); - PackEnd(_drawerBox); - - _mainBox = new EBox(parent); - _mainBox.SetLayoutCallback(OnMainBoxLayout); - _mainBox.Show(); - PackEnd(_mainBox); - - _focusControlArea = new TButton(parent) - { - Color = EColor.Transparent, - BackgroundColor = EColor.Transparent - }; - _focusControlArea.SetEffectColor(EColor.Transparent); - _focusControlArea.Show(); - _mainBox.PackEnd(_focusControlArea); - - _behavior = FlyoutBehavior.Flyout; - - _drawerBox.KeyUp += (s, e) => - { - if (e.KeyName == "Return" || e.KeyName == "Right") - { - IsOpen = false; - } - }; - - _mainBox.KeyUp += (s, e) => - { - if (e.KeyName == "Left") - { - if (_focusControlArea.IsFocused) - IsOpen = true; - } - else - { - // Workaround to prevent unexpected movement of the focus to drawer during page pushing. - if (_behavior == FlyoutBehavior.Locked) - _drawerBox.AllowTreeFocus = true; - } - }; - - _mainBox.KeyDown += (s, e) => - { - if (e.KeyName != "Left") - { - // Workaround to prevent unexpected movement of the focus to drawer during page pushing. - if (_behavior == FlyoutBehavior.Locked) - _drawerBox.AllowTreeFocus = false; - } - }; - - UpdateFocusPolicy(); - } - - public event EventHandler? Toggled; - - public EvasObject TargetView => this; - - public EvasObject? NavigationView - { - get => _drawer; - set => UpdateNavigationView(value); - } - - public EvasObject? Main - { - get => _main; - set => UpdateMain(value); - } - - public bool IsOpen - { - get => _isOpen; - set => UpdateOpenState(value); - } - - public bool IsSplit { get; set; } - - public void UpdateBehavior(FlyoutBehavior behavior) - { - _behavior = behavior; - _focusControlArea.IsEnabled = _behavior == FlyoutBehavior.Flyout; - - var open = false; - - if (_behavior == FlyoutBehavior.Locked) - open = true; - else if (_behavior == FlyoutBehavior.Disabled) - open = false; - else - open = _drawerBox.IsFocused; - - UpdateOpenState(open); - } - - void UpdateNavigationView(EvasObject? navigationView) - { - if (_drawer != null) - { - _drawerBox.UnPack(_drawer); - _drawer.Hide(); - } - - _drawer = navigationView; - - if (_drawer != null) - { - _drawer.SetAlignment(-1, -1); - _drawer.SetWeight(1, 1); - _drawer.Show(); - _drawerBox.PackEnd(_drawer); - } - } - - void UpdateMain(EvasObject? main) - { - if (_main != null) - { - _mainBox.UnPack(_main); - _main.Hide(); - } - _main = main; - - if (_main != null) - { - _main.SetAlignment(-1, -1); - _main.SetWeight(1, 1); - _main.Show(); - _mainBox.PackStart(_main); - } - } - - void OnMainBoxLayout() - { - if (_main != null) - { - _main.Geometry = _mainBox.Geometry; - } - - var focusedButtonGeometry = _mainBox.Geometry; - focusedButtonGeometry.X = focusedButtonGeometry.X - 100; - focusedButtonGeometry.Width = 0; - focusedButtonGeometry.Height = (int)((_drawer as ITNavigationView)?.GetTvFlyoutItemHeight()).GetValueOrDefault(); - _focusControlArea.Geometry = focusedButtonGeometry; - } - - void OnLayout() - { - if (Geometry.Width == 0 || Geometry.Height == 0) - return; - - var bound = Geometry; - - var ratioMax = this.GetTvFlyoutRatio(Geometry.Width, Geometry.Height); - var ratioMin = (_behavior == FlyoutBehavior.Disabled) ? 0 : this.GetTvFlyoutRatioMin(); - var drawerWidthMax = (int)(bound.Width * ratioMax); - var drawerWidthMin = (int)(bound.Width * ratioMin); - - var drawerWidthOutBound = (int)((drawerWidthMax - drawerWidthMin) * (1 - _openRatio)); - var drawerWidthInBound = drawerWidthMax - drawerWidthOutBound; - - var drawerGeometry = bound; - drawerGeometry.Width = drawerWidthInBound; - _drawerBox.Geometry = drawerGeometry; - - var containerGeometry = bound; - containerGeometry.X = drawerWidthInBound; - containerGeometry.Width = (_behavior == FlyoutBehavior.Locked) ? (bound.Width - drawerWidthInBound) : (bound.Width - drawerWidthMin); - _mainBox.Geometry = containerGeometry; - } - - void UpdateOpenState(bool isOpen) - { - if (_behavior == FlyoutBehavior.Locked && !isOpen) - return; - - double endState = ((_behavior != FlyoutBehavior.Disabled) && isOpen) ? 1 : 0; - new Animation((r) => - { - _openRatio = r; - OnLayout(); - }, _openRatio, endState, Easing.SinOut).Commit(Shell.Current, "DrawerMove", finished: (f, aborted) => - { - if (!aborted) - { - if (_isOpen != isOpen) - { - _isOpen = isOpen; - UpdateFocusPolicy(); - Toggled?.Invoke(this, EventArgs.Empty); - } - } - }); - } - - void UpdateFocusPolicy() - { - if (_isOpen) - { - if (_behavior == FlyoutBehavior.Locked) - { - _drawerBox.AllowTreeFocus = true; - _mainBox.AllowTreeFocus = true; - } - else - { - _mainBox.AllowTreeFocus = false; - _drawerBox.AllowTreeFocus = true; - _drawerBox.SetFocus(true); - } - } - else - { - _mainBox.AllowTreeFocus = true; - _drawerBox.AllowTreeFocus = false; - _mainBox.SetFocus(true); - } - } - - void IFlyoutBehaviorObserver.OnFlyoutBehaviorChanged(FlyoutBehavior behavior) - { - UpdateBehavior(behavior); - } - } -} diff --git a/src/Controls/src/Core/Platform/Tizen/Shell/TVNavigationView.cs b/src/Controls/src/Core/Platform/Tizen/Shell/TVNavigationView.cs deleted file mode 100644 index e6b847ffa0d6..000000000000 --- a/src/Controls/src/Core/Platform/Tizen/Shell/TVNavigationView.cs +++ /dev/null @@ -1,27 +0,0 @@ -using ElmSharp; -using EColor = ElmSharp.Color; -using TNavigationView = Tizen.UIExtensions.ElmSharp.NavigationView; - -namespace Microsoft.Maui.Controls.Platform -{ - public class TVNavigationView : TNavigationView - { - EColor _backgroundColor; - - public TVNavigationView(EvasObject parent) : base(parent) - { - BackgroundColor = this.GetTvDefaultBackgroundColor().ToNativeEFL(); - } - - public override EColor BackgroundColor - { - get => _backgroundColor; - set - { - _backgroundColor = value; - base.BackgroundColor = _backgroundColor.IsDefault ? this.GetTvDefaultBackgroundColor().ToNativeEFL() : _backgroundColor; - } - } - - } -} diff --git a/src/Controls/src/Core/Platform/Tizen/Shell/ThemeConstants.cs b/src/Controls/src/Core/Platform/Tizen/Shell/ThemeConstants.cs index 1bf9fac34ed1..a4f602b6fb81 100644 --- a/src/Controls/src/Core/Platform/Tizen/Shell/ThemeConstants.cs +++ b/src/Controls/src/Core/Platform/Tizen/Shell/ThemeConstants.cs @@ -16,7 +16,6 @@ public class Resources public const int DefaultIconSize = 30; public const int DefaultIconPadding = 15; - public const double DefaultFlyoutRatio = 0.83; public const int DefaultFlyoutItemHeight = 60; public const int DefaultFlyoutItemWidth = 250; @@ -24,9 +23,6 @@ public class TV { public const int DefaultMenuSize = 70; - public const double DefaultFlyoutRatio = 0.3; - public const double DefaultFlyoutRatioMin = 0.05; - public const int DefaultFlyoutIconColumnSize = 40; public const int DefaultFlyoutIconSize = 25; @@ -38,7 +34,6 @@ public class ColorClass { public class TV { - public static readonly Graphics.Color DefaultBackgroundColor = Graphics.Colors.Black; public static readonly Graphics.Color DefaultFlyoutItemColor = Graphics.Colors.Transparent; public static readonly Graphics.Color DefaultFlyoutItemFocusedColor = new Graphics.Color(0.95f); } diff --git a/src/Controls/src/Core/Platform/Tizen/Shell/ThemeManager.cs b/src/Controls/src/Core/Platform/Tizen/Shell/ThemeManager.cs index 9d5c7b547ed7..30c6ad444048 100644 --- a/src/Controls/src/Core/Platform/Tizen/Shell/ThemeManager.cs +++ b/src/Controls/src/Core/Platform/Tizen/Shell/ThemeManager.cs @@ -116,16 +116,6 @@ public static double GetTvFlyoutItemFontSize(this ITNavigtaionView nav) return s_navigationViewFlyoutItemFontSize = DeviceInfo.CalculateDoubleScaledSizeInLargeScreen(ThemeConstants.Shell.Resources.TV.DefaultFlyoutItemfontSize); } - public static double GetTvFlyoutRatioMin(this INavigationDrawer drawer) - { - return ThemeConstants.Shell.Resources.TV.DefaultFlyoutRatioMin; - } - - public static Graphics.Color GetTvDefaultBackgroundColor(this ITNavigtaionView nav) - { - return ThemeConstants.Shell.ColorClass.TV.DefaultBackgroundColor; - } - public static Graphics.Color GetTvFlyoutItemColor(this ITNavigtaionView nav) { return ThemeConstants.Shell.ColorClass.TV.DefaultFlyoutItemColor; @@ -136,13 +126,5 @@ public static Graphics.Color GetTvFlyoutItemFocusedColor(this ITNavigtaionView n return ThemeConstants.Shell.ColorClass.TV.DefaultFlyoutItemFocusedColor; } #endregion - - #region TVNavigationDrawer - static double s_navigationDrawerRatio = -1; - public static double GetTvFlyoutRatio(this INavigationDrawer drawer, int width, int height) - { - return s_navigationDrawerRatio = (width > height) ? ThemeConstants.Shell.Resources.TV.DefaultFlyoutRatio : ThemeConstants.Shell.Resources.DefaultFlyoutRatio; - } - #endregion } }