Skip to content

Commit

Permalink
[Tizen] Add TVShellView (#183)
Browse files Browse the repository at this point in the history
* [Tizen] Add TVShellView

* [Tizen] Update TVShellView

* [Tizen] Update NativeView for Shell

* [Tizen] Update ShellView

* [Tizen] Change default FlyoutBackgroundColor for TV

* [Tizen] Enable nullable
  • Loading branch information
shyunMin authored and rookiejava committed Apr 14, 2022
1 parent 1119b76 commit c223ec8
Show file tree
Hide file tree
Showing 20 changed files with 1,585 additions and 333 deletions.
12 changes: 10 additions & 2 deletions src/Controls/src/Core/Handlers/Shell/ShellHandler.Tizen.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Handlers;
using Tizen.UIExtensions.Common;

namespace Microsoft.Maui.Controls.Handlers
{
Expand All @@ -8,12 +9,19 @@ public partial class ShellHandler : ViewHandler<Shell, ShellView>
public override void SetVirtualView(IView view)
{
base.SetVirtualView(view);
NativeView.SetElement((Shell)view, MauiContext);
NativeView?.SetElement((Shell)view, MauiContext);
}

protected override ShellView CreateNativeView()
{
return new ShellView(NativeParent);
if (DeviceInfo.GetDeviceType() == DeviceType.TV)
{
return new TVShellView(NativeParent);
}
else
{
return new ShellView(NativeParent);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
using System;
#nullable enable

using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Handlers;
using ElmSharp;
using Microsoft.Maui.Controls.Internals;
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>();
Dictionary<object, View?> _dataBindedViewTable = new Dictionary<object, View?>();

Shell _shell;
View _headerCache;
View? _headerCache;
IMauiContext _context;

protected Shell Shell => _shell;

public bool HasHeader { get; set; }

protected virtual DataTemplate DefaultItemTemplate => null;
protected virtual DataTemplate? DefaultItemTemplate => null;

protected virtual DataTemplate DefaultMenuItemTemplate => null;
protected virtual DataTemplate? DefaultMenuItemTemplate => null;

public ShellFlyoutItemAdaptor(Shell shell, IMauiContext context, IEnumerable items, bool hasHeader) : base(items)
{
Expand All @@ -32,32 +33,37 @@ public ShellFlyoutItemAdaptor(Shell shell, IMauiContext context, IEnumerable ite
HasHeader = hasHeader;
}

public override EvasObject CreateNativeView(EvasObject parent)
public override EvasObject? CreateNativeView(EvasObject parent)
{
return CreateNativeView(0, parent);
}

DataTemplate GetDataTemplate(int index)
DataTemplate? GetDataTemplate(int index)
{
var item = (BindableObject)this[index];
DataTemplate dataTemplate = (Shell as IShellController)?.GetFlyoutItemDataTemplate(item);
if (item is IMenuItemController)
var item = this[index];
if (item != null && item is BindableObject bo)
{
if (DefaultMenuItemTemplate != null && Shell.MenuItemTemplate == dataTemplate)
dataTemplate = DefaultMenuItemTemplate;
DataTemplate? dataTemplate = (Shell as IShellController)?.GetFlyoutItemDataTemplate(bo);
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;
}
else
{
if (DefaultItemTemplate != null && Shell.ItemTemplate == dataTemplate)
dataTemplate = DefaultItemTemplate;
}

var template = dataTemplate.SelectDataTemplate(item, Shell);

return template;
return null;
}

public override EvasObject CreateNativeView(int index, EvasObject parent)
public override EvasObject? CreateNativeView(int index, EvasObject parent)
{

var template = GetDataTemplate(index);
Expand All @@ -74,12 +80,12 @@ public override EvasObject CreateNativeView(int index, EvasObject parent)
return null;
}

public override EvasObject GetFooterView(EvasObject parent)
public override EvasObject? GetFooterView(EvasObject parent)
{
return null;
}

public override EvasObject GetHeaderView(EvasObject parent)
public override EvasObject? GetHeaderView(EvasObject parent)
{
if (!HasHeader)
return null;
Expand Down Expand Up @@ -112,7 +118,8 @@ public override Size MeasureItem(int widthConstraint, int heightConstraint)

public override Size MeasureItem(int index, int widthConstraint, int heightConstraint)
{
if (_dataBindedViewTable.TryGetValue(this[index], out View createdView) && createdView != null)
var item = this[index];
if (item != null && _dataBindedViewTable.TryGetValue(item, out View? createdView) && createdView != null)
{
return createdView.Measure(DPExtensions.ConvertToScaledDP(widthConstraint), DPExtensions.ConvertToScaledDP(heightConstraint), MeasureFlags.IncludeMargins).Request.ToEFLPixel();
}
Expand All @@ -127,11 +134,15 @@ public override void RemoveNativeView(EvasObject native)

public override void SetBinding(EvasObject native, int index)
{
if (_nativeFormsTable.TryGetValue(native, out View view))
if (_nativeFormsTable.TryGetValue(native, out View? view))
{
ResetBindedView(view);
view.BindingContext = this[index];
_dataBindedViewTable[this[index]] = view;
var item = this[index];
if (item != null)
{
view.BindingContext = item;
_dataBindedViewTable[item] = view;
}

view.MeasureInvalidated += OnItemMeasureInvalidated;
Shell.AddLogicalChild(view);
Expand All @@ -140,7 +151,7 @@ public override void SetBinding(EvasObject native, int index)

public override void UnBinding(EvasObject native)
{
if (_nativeFormsTable.TryGetValue(native, out View view))
if (_nativeFormsTable.TryGetValue(native, out View? view))
{
view.MeasureInvalidated -= OnItemMeasureInvalidated;
ResetBindedView(view);
Expand All @@ -157,13 +168,16 @@ void ResetBindedView(View view)
}
}

void OnItemMeasureInvalidated(object sender, EventArgs e)
void OnItemMeasureInvalidated(object? sender, EventArgs e)
{
var data = (sender as View)?.BindingContext ?? null;
int index = GetItemIndex(data);
if (index != -1)
if (data != null)
{
CollectionView?.ItemMeasureInvalidated(index);
int index = GetItemIndex(data);
if (index != -1)
{
CollectionView?.ItemMeasureInvalidated(index);
}
}
}
}
Expand Down
Loading

0 comments on commit c223ec8

Please sign in to comment.