forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add ShellHandler * Move ShellView into Platform/Tizen * Update ShellView * Move the code for embedded tizen resources to csproj * Add UIExtenstions for shell
- Loading branch information
1 parent
deeb541
commit d0311d6
Showing
21 changed files
with
2,622 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 12 additions & 4 deletions
16
src/Controls/src/Core/Handlers/Shell/ShellHandler.Tizen.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
using System; | ||
using Microsoft.Maui.Controls.Platform; | ||
using Microsoft.Maui.Handlers; | ||
using Tizen.UIExtensions.ElmSharp; | ||
|
||
namespace Microsoft.Maui.Controls.Handlers | ||
{ | ||
public partial class ShellHandler : ViewHandler<Shell, NavigationDrawer> | ||
public partial class ShellHandler : ViewHandler<Shell, ShellView> | ||
{ | ||
protected override NavigationDrawer CreateNativeView() => new NavigationDrawer(NativeParent); | ||
public override void SetVirtualView(IView view) | ||
{ | ||
base.SetVirtualView(view); | ||
NativeView.SetElement((Shell)view, MauiContext); | ||
} | ||
|
||
protected override ShellView CreateNativeView() | ||
{ | ||
return new ShellView(NativeParent); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/Controls/src/Core/Platform/Tizen/Extensions/ShellExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using Tizen.UIExtensions.Common; | ||
using TINavigtaionView = Tizen.UIExtensions.Shell.INavigationView; | ||
|
||
namespace Microsoft.Maui.Controls.Platform | ||
{ | ||
public static class ShellExtensions | ||
{ | ||
static double s_navigationViewFlyoutItemHeight = -1; | ||
public static double GetFlyoutItemHeight(this TINavigtaionView nav) | ||
{ | ||
if (s_navigationViewFlyoutItemHeight > 0) | ||
return s_navigationViewFlyoutItemHeight; | ||
return s_navigationViewFlyoutItemHeight = DeviceInfo.CalculateDoubleScaledSizeInLargeScreen(60); | ||
} | ||
|
||
static double s_navigationViewFlyoutItemWidth = -1; | ||
public static double GetFlyoutItemWidth(this TINavigtaionView nav) | ||
{ | ||
if (s_navigationViewFlyoutItemWidth > 0) | ||
return s_navigationViewFlyoutItemWidth; | ||
return s_navigationViewFlyoutItemWidth = DeviceInfo.CalculateDoubleScaledSizeInLargeScreen(200); | ||
} | ||
|
||
static double s_navigationViewFlyoutIconColumnSize = -1; | ||
public static double GetFlyoutIconColumnSize(this TINavigtaionView nav) | ||
{ | ||
if (s_navigationViewFlyoutIconColumnSize > 0) | ||
return s_navigationViewFlyoutIconColumnSize; | ||
return s_navigationViewFlyoutIconColumnSize = DeviceInfo.CalculateDoubleScaledSizeInLargeScreen(40); | ||
} | ||
|
||
static double s_navigationViewFlyoutIconSize = -1; | ||
public static double GetFlyoutIconSize(this TINavigtaionView nav) | ||
{ | ||
if (s_navigationViewFlyoutIconSize > 0) | ||
return s_navigationViewFlyoutIconSize; | ||
return s_navigationViewFlyoutIconSize = DeviceInfo.CalculateDoubleScaledSizeInLargeScreen(25); | ||
} | ||
|
||
static double s_navigationViewFlyoutMargin = -1; | ||
public static double GetFlyoutMargin(this TINavigtaionView nav) | ||
{ | ||
if (s_navigationViewFlyoutMargin > 0) | ||
return s_navigationViewFlyoutMargin; | ||
return s_navigationViewFlyoutMargin = DeviceInfo.CalculateDoubleScaledSizeInLargeScreen(10); | ||
} | ||
|
||
static double s_navigationViewFlyoutItemFontSize = -1; | ||
public static double GetFlyoutItemFontSize(this TINavigtaionView nav) | ||
{ | ||
if (s_navigationViewFlyoutItemFontSize > 0) | ||
return s_navigationViewFlyoutItemFontSize; | ||
return s_navigationViewFlyoutItemFontSize = DeviceInfo.CalculateDoubleScaledSizeInLargeScreen(25); | ||
} | ||
|
||
#region ShellMoreToolbar | ||
|
||
static double s_shellMoreToolBarIconPadding = -1; | ||
public static double GetIconPadding(this ShellMoreTabs self) | ||
{ | ||
if (s_shellMoreToolBarIconPadding > 0) | ||
return s_shellMoreToolBarIconPadding; | ||
return s_shellMoreToolBarIconPadding = DeviceInfo.CalculateDoubleScaledSizeInLargeScreen(15); | ||
} | ||
|
||
static double s_shellMoreToolBarIconSize = -1; | ||
public static double GetIconSize(this ShellMoreTabs self) | ||
{ | ||
if (s_shellMoreToolBarIconSize > 0) | ||
return s_shellMoreToolBarIconSize; | ||
return s_shellMoreToolBarIconSize = DeviceInfo.CalculateDoubleScaledSizeInLargeScreen(30); | ||
} | ||
#endregion | ||
|
||
#region ShellNavBar | ||
static double s_shellNavBarDefaultHeight = -1; | ||
public static double GetDefaultHeight(this ShellNavBar navBar) | ||
{ | ||
if (s_shellNavBarDefaultHeight > 0) | ||
return s_shellNavBarDefaultHeight; | ||
return s_shellNavBarDefaultHeight = DeviceInfo.CalculateDoubleScaledSizeInLargeScreen(70); | ||
} | ||
|
||
static double s_shellNavBarDefaultMenuSize = -1; | ||
public static double GetDefaultMenuSize(this ShellNavBar navBar) | ||
{ | ||
if (s_shellNavBarDefaultMenuSize > 0) | ||
return s_shellNavBarDefaultMenuSize; | ||
return s_shellNavBarDefaultMenuSize = DeviceInfo.CalculateDoubleScaledSizeInLargeScreen(Device.Idiom == TargetIdiom.TV ? 70 : 40); | ||
} | ||
|
||
static double s_shellNavBarDefaultMargin = -1; | ||
public static double GetDefaultMargin(this ShellNavBar navBar) | ||
{ | ||
if (s_shellNavBarDefaultMargin > 0) | ||
return s_shellNavBarDefaultMargin; | ||
return s_shellNavBarDefaultMargin = DeviceInfo.CalculateDoubleScaledSizeInLargeScreen(10); | ||
} | ||
|
||
static double s_shellNavBarTitleVDefaultMargin = -1; | ||
public static double GetDefaultTitleVMargin(this ShellNavBar navBar) | ||
{ | ||
if (s_shellNavBarTitleVDefaultMargin > 0) | ||
return s_shellNavBarTitleVDefaultMargin; | ||
return s_shellNavBarTitleVDefaultMargin = DeviceInfo.CalculateDoubleScaledSizeInLargeScreen(23); | ||
} | ||
|
||
static double s_shellNavBarTitleFontSize = -1; | ||
public static double GetDefaultTitleFontSize(this ShellNavBar navBar) | ||
{ | ||
if (s_shellNavBarTitleFontSize > 0) | ||
return s_shellNavBarTitleFontSize; | ||
return s_shellNavBarTitleFontSize = DeviceInfo.CalculateDoubleScaledSizeInLargeScreen(23); | ||
} | ||
#endregion | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
170 changes: 170 additions & 0 deletions
170
src/Controls/src/Core/Platform/Tizen/Shell/ShellFlyoutItemAdaptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Microsoft.Maui.Controls.Internals; | ||
using Microsoft.Maui.Handlers; | ||
using ElmSharp; | ||
using Tizen.UIExtensions.ElmSharp; | ||
|
||
namespace Microsoft.Maui.Controls.Platform | ||
{ | ||
public class ShellFlyoutItemAdaptor : ItemAdaptor | ||
{ | ||
Dictionary<EvasObject, View> _nativeFormsTable = new Dictionary<EvasObject, View>(); | ||
Dictionary<object, View> _dataBindedViewTable = new Dictionary<object, View>(); | ||
|
||
Shell _shell; | ||
View _headerCache; | ||
IMauiContext _context; | ||
|
||
protected Shell Shell => _shell; | ||
|
||
public bool HasHeader { get; set; } | ||
|
||
protected virtual DataTemplate DefaultItemTemplate => null; | ||
|
||
protected virtual DataTemplate DefaultMenuItemTemplate => null; | ||
|
||
public ShellFlyoutItemAdaptor(Shell shell, IMauiContext context, IEnumerable items, bool hasHeader) : base(items) | ||
{ | ||
_shell = shell; | ||
_context = context; | ||
HasHeader = hasHeader; | ||
} | ||
|
||
public override EvasObject CreateNativeView(EvasObject parent) | ||
{ | ||
return CreateNativeView(0, parent); | ||
} | ||
|
||
DataTemplate GetDataTemplate(int index) | ||
{ | ||
var item = (BindableObject)this[index]; | ||
DataTemplate dataTemplate = (Shell as IShellController)?.GetFlyoutItemDataTemplate(item); | ||
if (item is IMenuItemController) | ||
{ | ||
if (DefaultMenuItemTemplate != null && Shell.MenuItemTemplate == dataTemplate) | ||
dataTemplate = DefaultMenuItemTemplate; | ||
} | ||
else | ||
{ | ||
if (DefaultItemTemplate != null && Shell.ItemTemplate == dataTemplate) | ||
dataTemplate = DefaultItemTemplate; | ||
} | ||
|
||
var template = dataTemplate.SelectDataTemplate(item, Shell); | ||
|
||
return template; | ||
} | ||
|
||
public override EvasObject CreateNativeView(int index, EvasObject parent) | ||
{ | ||
|
||
var template = GetDataTemplate(index); | ||
|
||
if (template != null) | ||
{ | ||
var content = (View)template.CreateContent(); | ||
var native = content.ToNative(_context); | ||
|
||
_nativeFormsTable[native] = content; | ||
return native; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public override EvasObject GetFooterView(EvasObject parent) | ||
{ | ||
return null; | ||
} | ||
|
||
public override EvasObject GetHeaderView(EvasObject parent) | ||
{ | ||
if (!HasHeader) | ||
return null; | ||
|
||
_headerCache = ((IShellController)Shell).FlyoutHeader; | ||
|
||
if (_headerCache != null) | ||
{ | ||
var native = _headerCache.ToNative(_context); | ||
return native; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public override Size MeasureFooter(int widthConstraint, int heightConstraint) | ||
{ | ||
return new Size(0, 0); | ||
} | ||
|
||
public override Size MeasureHeader(int widthConstraint, int heightConstraint) | ||
{ | ||
return _headerCache?.Measure(DPExtensions.ConvertToScaledDP(widthConstraint), DPExtensions.ConvertToScaledDP(heightConstraint)).Request.ToEFLPixel() ?? new Size(0, 0); | ||
} | ||
|
||
public override Size MeasureItem(int widthConstraint, int heightConstraint) | ||
{ | ||
return MeasureItem(0, widthConstraint, heightConstraint); | ||
} | ||
|
||
public override Size MeasureItem(int index, int widthConstraint, int heightConstraint) | ||
{ | ||
if (_dataBindedViewTable.TryGetValue(this[index], out View createdView) && createdView != null) | ||
{ | ||
return createdView.Measure(DPExtensions.ConvertToScaledDP(widthConstraint), DPExtensions.ConvertToScaledDP(heightConstraint), MeasureFlags.IncludeMargins).Request.ToEFLPixel(); | ||
} | ||
|
||
return new Size(0, 0); | ||
} | ||
|
||
public override void RemoveNativeView(EvasObject native) | ||
{ | ||
native?.Unrealize(); | ||
} | ||
|
||
public override void SetBinding(EvasObject native, int index) | ||
{ | ||
if (_nativeFormsTable.TryGetValue(native, out View view)) | ||
{ | ||
ResetBindedView(view); | ||
view.BindingContext = this[index]; | ||
_dataBindedViewTable[this[index]] = view; | ||
|
||
view.MeasureInvalidated += OnItemMeasureInvalidated; | ||
Shell.AddLogicalChild(view); | ||
} | ||
} | ||
|
||
public override void UnBinding(EvasObject native) | ||
{ | ||
if (_nativeFormsTable.TryGetValue(native, out View view)) | ||
{ | ||
view.MeasureInvalidated -= OnItemMeasureInvalidated; | ||
ResetBindedView(view); | ||
} | ||
} | ||
|
||
void ResetBindedView(View view) | ||
{ | ||
if (view.BindingContext != null && _dataBindedViewTable.ContainsKey(view.BindingContext)) | ||
{ | ||
_dataBindedViewTable[view.BindingContext] = null; | ||
Shell.RemoveLogicalChild(view); | ||
view.BindingContext = null; | ||
} | ||
} | ||
|
||
void OnItemMeasureInvalidated(object sender, EventArgs e) | ||
{ | ||
var data = (sender as View)?.BindingContext ?? null; | ||
int index = GetItemIndex(data); | ||
if (index != -1) | ||
{ | ||
CollectionView?.ItemMeasureInvalidated(index); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.