This repository has been archived by the owner on May 1, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the MaterialShellRenderer for Tizen
- Loading branch information
Showing
31 changed files
with
1,770 additions
and
2 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,7 @@ | ||
namespace Xamarin.Forms.Material.Tizen | ||
{ | ||
public interface IFlyoutController | ||
{ | ||
void Open(); | ||
} | ||
} |
191 changes: 191 additions & 0 deletions
191
Xamarin.Forms.Material.Tizen/Shell/MaterialShellRenderer.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,191 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using ElmSharp; | ||
using Xamarin.Forms; | ||
using Xamarin.Forms.Platform.Tizen; | ||
using Tizen.NET.MaterialComponents; | ||
using Xamarin.Forms.Material.Tizen; | ||
using TForms = Xamarin.Forms.Platform.Tizen.Forms; | ||
using TNative = Xamarin.Forms.Material.Tizen.Native; | ||
using TPlatform = Xamarin.Forms.Platform.Tizen.Platform; | ||
|
||
[assembly: ExportRenderer(typeof(Shell), typeof(MaterialShellRenderer), new[] { typeof(VisualMarker.MaterialVisual) })] | ||
namespace Xamarin.Forms.Material.Tizen | ||
{ | ||
public class MaterialShellRenderer : VisualElementRenderer<Shell>, IFlyoutController | ||
{ | ||
MNavigationDrawer _native; | ||
ShellItemRenderer _shellItem; | ||
|
||
IDictionary<int, Element> _flyoutMenu = new Dictionary<int, Element>(); | ||
|
||
public static readonly Color DefaultBackgroundColor = Color.FromRgb(33, 150, 243); | ||
public static readonly Color DefaultForegroundColor = Color.White; | ||
public static readonly Color DefaultTitleColor = Color.White; | ||
|
||
public MaterialShellRenderer() | ||
{ | ||
RegisterPropertyHandler(Shell.CurrentItemProperty, UpdateCurrentItem); | ||
RegisterPropertyHandler(Shell.FlyoutBackgroundColorProperty, UpdateFlyoutBackgroundColor); | ||
RegisterPropertyHandler(Shell.FlyoutIsPresentedProperty, UpdateFlyoutIsPresented); | ||
} | ||
|
||
public override Rect GetNativeContentGeometry() | ||
{ | ||
var rect = base.GetNativeContentGeometry(); | ||
rect.X = 0; | ||
rect.Y = 0; | ||
return rect; | ||
} | ||
|
||
protected override void OnElementChanged(ElementChangedEventArgs<Shell> e) | ||
{ | ||
if (_native == null) | ||
{ | ||
_native = new MNavigationDrawer(TForms.NativeParent) | ||
{ | ||
NavigationView = new MNavigationView(TForms.NativeParent) | ||
}; | ||
SetNativeView(_native); | ||
|
||
_native.Toggled += OnFlyoutIsPresentedChanged; | ||
|
||
InitializeFlyout(); | ||
} | ||
|
||
base.OnElementChanged(e); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
((IShellController)Element).StructureChanged -= OnShellStructureChanged; | ||
if (_native != null) | ||
{ | ||
_native.Toggled -= OnFlyoutIsPresentedChanged; | ||
_native.NavigationView.MenuItemSelected -= OnItemSelected; | ||
} | ||
} | ||
base.Dispose(disposing); | ||
} | ||
|
||
void InitializeFlyout() | ||
{ | ||
((IShellController)Element).StructureChanged += OnShellStructureChanged; | ||
|
||
View flyoutHeader = ((IShellController)Element).FlyoutHeader; | ||
if (flyoutHeader != null) | ||
{ | ||
var headerView = TPlatform.GetOrCreateRenderer(flyoutHeader); | ||
(headerView as LayoutRenderer)?.RegisterOnLayoutUpdated(); | ||
|
||
Size request = flyoutHeader.Measure(TForms.ConvertToScaledDP(_native.NavigationView.MinimumWidth), TForms.ConvertToScaledDP(_native.NavigationView.MinimumHeight)).Request; | ||
headerView.NativeView.MinimumHeight = TForms.ConvertToScaledPixel(request.Height); | ||
|
||
_native.NavigationView.Header = headerView.NativeView; | ||
} | ||
|
||
BuildMenu(); | ||
_native.NavigationView.MenuItemSelected += OnItemSelected; | ||
} | ||
|
||
void UpdateCurrentItem() | ||
{ | ||
_shellItem?.Dispose(); | ||
if (Element.CurrentItem != null) | ||
{ | ||
_shellItem = new ShellItemRenderer(this, Element.CurrentItem); | ||
_shellItem.Control.SetAlignment(-1, -1); | ||
_shellItem.Control.SetWeight(1, 1); | ||
_native.Main = _shellItem.Control; | ||
} | ||
else | ||
{ | ||
_native.Main = null; | ||
} | ||
} | ||
|
||
void UpdateFlyoutBackgroundColor() | ||
{ | ||
_native.NavigationView.BackgroundColor = Element.FlyoutBackgroundColor.ToNative(); | ||
} | ||
|
||
void UpdateFlyoutIsPresented() | ||
{ | ||
_native.IsOpen = Element.FlyoutIsPresented; | ||
} | ||
|
||
void OnFlyoutIsPresentedChanged(object sender, EventArgs e) | ||
{ | ||
Element.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, _native.IsOpen); | ||
} | ||
|
||
void OnItemSelected(object sender, GenListItemEventArgs e) | ||
{ | ||
_flyoutMenu.TryGetValue(e.Item.Index - 1, out Element element); | ||
|
||
if (element != null) | ||
{ | ||
((IShellController)Element).OnFlyoutItemSelected(element); | ||
} | ||
} | ||
|
||
void OnShellStructureChanged(object sender, EventArgs e) | ||
{ | ||
BuildMenu(); | ||
} | ||
|
||
void BuildMenu() | ||
{ | ||
var groups = new List<MGroup>(); | ||
var flyoutGroups = ((IShellController)Element).GenerateFlyoutGrouping(); | ||
|
||
_flyoutMenu.Clear(); | ||
|
||
int index = 0; | ||
for (int i = 0; i < flyoutGroups.Count; i++) | ||
{ | ||
var flyoutGroup = flyoutGroups[i]; | ||
var items = new List<MItem>(); | ||
for (int j = 0; j < flyoutGroup.Count; j++) | ||
{ | ||
string title = null; | ||
string icon = null; | ||
if (flyoutGroup[j] is BaseShellItem shellItem) | ||
{ | ||
title = shellItem.Title; | ||
|
||
if (shellItem.FlyoutIcon is FileImageSource flyoutIcon) | ||
{ | ||
icon = flyoutIcon.File; | ||
} | ||
} | ||
else if (flyoutGroup[j] is MenuItem menuItem) | ||
{ | ||
title = menuItem.Text; | ||
if (menuItem.IconImageSource is FileImageSource source) | ||
{ | ||
icon = source.File; | ||
} | ||
} | ||
|
||
items.Add(new MItem(title, icon)); | ||
|
||
_flyoutMenu.Add(index, flyoutGroup[j]); | ||
index++; | ||
} | ||
|
||
var group = new MGroup(items); | ||
groups.Add(group); | ||
} | ||
|
||
_native.NavigationView.GroupMenu = groups; | ||
} | ||
|
||
void IFlyoutController.Open() | ||
{ | ||
_native.IsOpen = true; | ||
} | ||
} | ||
} |
Oops, something went wrong.