Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tizen] Update ShellView #7287

Merged
merged 1 commit into from May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Controls/src/Core/Platform/Tizen/Shell/ShellItemView.cs
Expand Up @@ -33,8 +33,8 @@ public class ShellItemView : IAppearanceObserver, IDisposable
List<EToolbarItem> _tabsItems = new List<EToolbarItem>();

bool _disposed = false;
Color _tabBarBackgroudColor = ShellView.DefaultBackgroundColor;
Color _tabBarTitleColor = ShellView.DefaultTitleColor;
Color _tabBarBackgroudColor = TThemeConstants.Shell.ColorClass.DefaultBackgroundColor;
Color _tabBarTitleColor = TThemeConstants.Shell.ColorClass.DefaultTitleColor;

const string _dotsIcon = TThemeConstants.Shell.Resources.DotsIcon;

Expand Down Expand Up @@ -287,8 +287,8 @@ void IAppearanceObserver.OnAppearanceChanged(ShellAppearance appearance)
var tabBarBackgroudColor = (appearance as IShellAppearanceElement)?.EffectiveTabBarBackgroundColor;
var tabBarTitleColor = (appearance as IShellAppearanceElement)?.EffectiveTabBarTitleColor;

TabBarBackgroundColor = tabBarBackgroudColor.IsDefault() ? ShellView.DefaultBackgroundColor : (tabBarBackgroudColor?.ToPlatformEFL()).GetValueOrDefault();
TabBarTitleColor = tabBarTitleColor.IsDefault() ? ShellView.DefaultTitleColor : (tabBarTitleColor?.ToPlatformEFL()).GetValueOrDefault();
TabBarBackgroundColor = tabBarBackgroudColor.IsDefault() ? TThemeConstants.Shell.ColorClass.DefaultBackgroundColor : (tabBarBackgroudColor?.ToPlatformEFL()).GetValueOrDefault();
TabBarTitleColor = tabBarTitleColor.IsDefault() ? TThemeConstants.Shell.ColorClass.DefaultTitleColor : (tabBarTitleColor?.ToPlatformEFL()).GetValueOrDefault();
}

void UpdateTabsBackgroudColor(EColor color)
Expand Down
Expand Up @@ -19,7 +19,7 @@ public ShellMoreTabs(EvasObject parent) : base(parent)

Homogeneous = true;
SelectionMode = GenItemSelectionMode.Always;
BackgroundColor = ShellView.DefaultBackgroundColor;
BackgroundColor = TThemeConstants.Shell.ColorClass.DefaultBackgroundColor;
_defaultClass = new GenItemClass(TThemeConstants.GenItemClass.Styles.Full)
{
GetContentHandler = GetContent,
Expand Down
56 changes: 29 additions & 27 deletions src/Controls/src/Core/Platform/Tizen/Shell/ShellNavBar.cs
Expand Up @@ -2,9 +2,10 @@

using System;
using ElmSharp;
using Microsoft.Maui.Devices;
using Tizen.UIExtensions.Common.GraphicsView;
using Tizen.UIExtensions.ElmSharp;
using Tizen.UIExtensions.ElmSharp.GraphicsView;
using Microsoft.Maui.Devices;
using EBox = ElmSharp.Box;
using EColor = ElmSharp.Color;
using TButton = Tizen.UIExtensions.ElmSharp.Button;
Expand All @@ -28,14 +29,16 @@ public class ShellNavBar : EBox, IFlyoutBehaviorObserver, IDisposable

FlyoutBehavior _flyoutBehavior = FlyoutBehavior.Flyout;

EColor _backgroudColor = ShellView.DefaultBackgroundColor;
EColor _foregroundColor = ShellView.DefaultForegroundColor;
EColor _titleColor = ShellView.DefaultTitleColor;
EColor _backgroudColor = TThemeConstants.Shell.ColorClass.DefaultBackgroundColor;
EColor _foregroundColor = TThemeConstants.Shell.ColorClass.DefaultForegroundColor;
EColor _titleColor = TThemeConstants.Shell.ColorClass.DefaultTitleColor;

bool _hasBackButton = false;
private bool disposedValue;
bool _disposedValue;
bool _isTV = DeviceInfo.Idiom == DeviceIdiom.TV;

bool IsMenuIconVisible => _flyoutBehavior == FlyoutBehavior.Flyout || HasBackButton;

public ShellNavBar(IMauiContext context) : base(context?.GetPlatformParent())
{
MauiContext = context;
Expand Down Expand Up @@ -190,50 +193,46 @@ public void Dispose()
public void SetPage(Page page)
{
_page = page;
Title = page.Title;
Title = string.IsNullOrEmpty(page.Title) ? Shell.Current.CurrentContent.Title : page.Title;
SearchHandler = Shell.GetSearchHandler(page);
TitleView = Shell.GetTitleView(page);

UpdateMenuIcon();
}

protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
if (!_disposedValue)
{
if (disposing)
{
Unrealize();
}
disposedValue = true;
_disposedValue = true;
}
}

void UpdateMenuIcon()
{
if (HasBackButton)
{
if (_isTV)
{
_menuButton.Style = TThemeConstants.Button.Styles.Default;
}
_menuIcon.IconType = Tizen.UIExtensions.Common.GraphicsView.MaterialIcons.ArrowBack;
}
else if (_flyoutBehavior != FlyoutBehavior.Flyout)
if (!IsMenuIconVisible)
{
_menuButton.Hide();
}
else
{
_menuIcon.IconType = HasBackButton ? MaterialIcons.ArrowBack : MaterialIcons.Menu;

if (_isTV)
{
_menuButton.Style = TThemeConstants.Button.Styles.Default;
}
_menuIcon.IconType = Tizen.UIExtensions.Common.GraphicsView.MaterialIcons.Menu;

_menuIcon?.Show();
_menuButton.SetIconPart(_menuIcon);
_menuButton.Show();
}

_menuIcon?.Show();
_menuButton.SetIconPart(_menuIcon);
_menuButton.Show();
OnLayout();
}

void OnMenuClicked(object? sender, EventArgs e)
Expand Down Expand Up @@ -318,14 +317,17 @@ void OnLayout()
int titleVMargin = TDPExtensions.ConvertToScaledPixel(this.GetDefaultTitleVMargin());

var bound = Geometry;
var menuBound = new Rect(bound.X, bound.Y, 0, 0);

var menuBound = bound;
menuBound.X += menuMargin;
menuBound.Y += (menuBound.Height - menuSize) / 2;
menuBound.Width = menuSize;
menuBound.Height = menuSize;
if (IsMenuIconVisible)
{
menuBound.X += menuMargin;
menuBound.Y += (bound.Height - menuSize) / 2;
menuBound.Width = menuSize;
menuBound.Height = menuSize;

_menuButton.Geometry = menuBound;
_menuButton.Geometry = menuBound;
}

var contentBound = Geometry;
contentBound.X = menuBound.Right + titleHMargin;
Expand Down
Expand Up @@ -10,6 +10,7 @@
using EColor = ElmSharp.Color;
using EToolbarItem = ElmSharp.ToolbarItem;
using EToolbarItemEventArgs = ElmSharp.ToolbarItemEventArgs;
using TThemeConstants = Tizen.UIExtensions.ElmSharp.ThemeConstants;

namespace Microsoft.Maui.Controls.Platform
{
Expand All @@ -31,8 +32,8 @@ public class ShellSectionHandler : IAppearanceObserver, IShellSectionHandler
Dictionary<EToolbarItem, ShellContent> _itemToContent = new Dictionary<EToolbarItem, ShellContent>();
List<EToolbarItem> _tabsItems = new List<EToolbarItem>();

EColor _backgroundColor = ShellView.DefaultBackgroundColor;
EColor _foregroundColor = ShellView.DefaultForegroundColor;
EColor _backgroundColor = TThemeConstants.Shell.ColorClass.DefaultBackgroundColor;
EColor _foregroundColor = TThemeConstants.Shell.ColorClass.DefaultForegroundColor;

bool _disposed = false;

Expand Down Expand Up @@ -142,8 +143,8 @@ void IAppearanceObserver.OnAppearanceChanged(ShellAppearance appearance)
var backgroundColor = (appearance as IShellAppearanceElement)?.EffectiveTabBarBackgroundColor;
var foregroundColor = appearance?.ForegroundColor;

ToolbarBackgroundColor = backgroundColor.IsDefault() ? ShellView.DefaultBackgroundColor : (backgroundColor?.ToPlatformEFL()).GetValueOrDefault();
ToolbarForegroundColor = foregroundColor.IsDefault() ? ShellView.DefaultForegroundColor : (foregroundColor?.ToPlatformEFL()).GetValueOrDefault();
ToolbarBackgroundColor = backgroundColor.IsDefault() ? TThemeConstants.Shell.ColorClass.DefaultBackgroundColor : (backgroundColor?.ToPlatformEFL()).GetValueOrDefault();
ToolbarForegroundColor = foregroundColor.IsDefault() ? TThemeConstants.Shell.ColorClass.DefaultForegroundColor : (foregroundColor?.ToPlatformEFL()).GetValueOrDefault();
}

void UpdateDisplayedPage(Page page)
Expand Down
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Maui.Devices;
using ElmSharp;
using EBox = ElmSharp.Box;
using TThemeConstants = Tizen.UIExtensions.ElmSharp.ThemeConstants;

namespace Microsoft.Maui.Controls.Platform
{
Expand Down Expand Up @@ -154,9 +155,9 @@ void IAppearanceObserver.OnAppearanceChanged(ShellAppearance appearance)
var backgroundColor = appearance?.BackgroundColor;
var foregroundColor = appearance?.ForegroundColor;

_navBar.TitleColor = titleColor.IsDefault() ? ShellView.DefaultTitleColor : (titleColor?.ToPlatformEFL()).GetValueOrDefault();
_navBar.BackgroundColor = backgroundColor.IsDefault() ? ShellView.DefaultBackgroundColor : (backgroundColor?.ToPlatformEFL()).GetValueOrDefault();
_navBar.ForegroundColor = foregroundColor.IsDefault() ? ShellView.DefaultForegroundColor : (foregroundColor?.ToPlatformEFL()).GetValueOrDefault();
_navBar.TitleColor = titleColor.IsDefault() ? TThemeConstants.Shell.ColorClass.DefaultTitleColor : (titleColor?.ToPlatformEFL()).GetValueOrDefault();
_navBar.BackgroundColor = backgroundColor.IsDefault() ? TThemeConstants.Shell.ColorClass.DefaultBackgroundColor : (backgroundColor?.ToPlatformEFL()).GetValueOrDefault();
_navBar.ForegroundColor = foregroundColor.IsDefault() ? TThemeConstants.Shell.ColorClass.DefaultForegroundColor : (foregroundColor?.ToPlatformEFL()).GetValueOrDefault();
}


Expand Down
14 changes: 9 additions & 5 deletions src/Controls/src/Core/Platform/Tizen/Shell/ShellView.cs
Expand Up @@ -15,17 +15,12 @@
using TImage = Tizen.UIExtensions.ElmSharp.Image;
using TNavigationView = Tizen.UIExtensions.ElmSharp.NavigationView;
using TSelectedItemChangedEventArgs = Tizen.UIExtensions.ElmSharp.SelectedItemChangedEventArgs;
using TThemeConstants = Tizen.UIExtensions.ElmSharp.ThemeConstants;
using TDPExtensions = Tizen.UIExtensions.ElmSharp.DPExtensions;

namespace Microsoft.Maui.Controls.Platform
{
public class ShellView : EBox, IFlyoutBehaviorObserver
{
public static readonly EColor DefaultBackgroundColor = TThemeConstants.Shell.ColorClass.DefaultBackgroundColor;
public static readonly EColor DefaultForegroundColor = TThemeConstants.Shell.ColorClass.DefaultForegroundColor;
public static readonly EColor DefaultTitleColor = TThemeConstants.Shell.ColorClass.DefaultTitleColor;

INavigationDrawer _navigationDrawer;
ITNavigationView _navigationView;
FlyoutHeaderBehavior _headerBehavior;
Expand All @@ -46,6 +41,7 @@ public ShellView(EvasObject parent) : base(parent)
_navigationView = CreateNavigationView();
_navigationView.LayoutUpdated += OnNavigationViewLayoutUpdated;
_navigationView.Content = _itemsView = CreateItemsView();
_navigationDrawer.DrawerWidth = ThemeConstants.Shell.Resources.DefaultFlyoutItemWidth;

_navigationDrawer.NavigationView = _navigationView.TargetView;
_navigationDrawer.Toggled += OnDrawerToggled;
Expand Down Expand Up @@ -77,6 +73,7 @@ public virtual void SetElement(Shell shell, IMauiContext context)
MauiContext = context;

((IShellController)Element).StructureChanged += OnShellStructureChanged;
((IShellController)Element).AddFlyoutBehaviorObserver(this);
_lastSelected = null;

UpdateFlyoutIsPresented();
Expand Down Expand Up @@ -178,6 +175,13 @@ protected virtual void UpdateFlyoutIsPresented()
});
}

protected virtual void UpdateFlyoutWidth()
{
_ = Element ?? throw new InvalidOperationException($"{nameof(Element)} should have been set by base class.");

_navigationDrawer.DrawerWidth = Element.FlyoutWidth;
}

protected void OnDrawerToggled(object? sender, EventArgs e)
{
_ = Element ?? throw new InvalidOperationException($"{nameof(Element)} should have been set by base class.");
Expand Down