summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs')
-rwxr-xr-x[-rw-r--r--]Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs144
1 files changed, 54 insertions, 90 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs
index 34e0235e..d2661197 100644..100755
--- a/Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs
+++ b/Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs
@@ -6,18 +6,15 @@ using EToolbarItem = ElmSharp.ToolbarItem;
using EToolbarItemEventArgs = ElmSharp.ToolbarItemEventArgs;
using EColor = ElmSharp.Color;
using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
-using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Platform.Tizen
{
public class TabbedPageRenderer : VisualElementRenderer<TabbedPage>, IVisualElementRenderer
{
- Box _outterLayout;
- Box _innerBox;
- Scroller _scroller;
+ Box _box;
Toolbar _toolbar;
+ EvasObject _content;
Dictionary<EToolbarItem, Page> _itemToItemPage = new Dictionary<EToolbarItem, Page>();
- IReadOnlyCollection<Element> Pages => (Element as IElementController).LogicalChildren;
public TabbedPageRenderer()
{
@@ -25,6 +22,7 @@ namespace Xamarin.Forms.Platform.Tizen
RegisterPropertyHandler(TabbedPage.TitleProperty, UpdateTitle);
//Register for current page change property
RegisterPropertyHandler("CurrentPage", CurrentPageChanged);
+ //TODO renderer should add item on EFL toolbar when new Page is added to TabbedPage
RegisterPropertyHandler(TabbedPage.BarBackgroundColorProperty, UpdateBarBackgroundColor);
}
@@ -33,7 +31,7 @@ namespace Xamarin.Forms.Platform.Tizen
if (_toolbar == null)
{
//Create box that holds toolbar and selected content
- _outterLayout = new Box(Forms.Context.MainWindow)
+ _box = new Box(Forms.Context.MainWindow)
{
AlignmentX = -1,
AlignmentY = -1,
@@ -41,9 +39,9 @@ namespace Xamarin.Forms.Platform.Tizen
WeightY = 1,
IsHorizontal = false,
};
- _outterLayout.Show();
+ _box.Show();
- //Create toolbar that is placed inside the _outterLayout
+ //Create toolbar that is placed inside the _box
_toolbar = new Toolbar(Forms.Context.MainWindow)
{
AlignmentX = -1,
@@ -53,91 +51,37 @@ namespace Xamarin.Forms.Platform.Tizen
if (Device.Idiom == TargetIdiom.Phone)
{
- //Set ShrinkMode to Expand as defauly only for Mobile profile
+ //Set ShrinkMode to Expand as default only for Mobile profile
_toolbar.ShrinkMode = ToolbarShrinkMode.Expand;
}
else if (Device.Idiom == TargetIdiom.TV)
{
- //According to TV UX Guideline, toolbar style should be set to "tabbar_with_title" in case of TabbedPage only for TV profile.
+ //According to TV UX Guideleine, toolbar style should be set to "tabbar_with_title" in case of TabbedPage
_toolbar.Style = "tabbar_with_title";
}
_toolbar.Show();
- //Add callback for Toolbar item selection
- _toolbar.Selected += OnToolbarItemSelected;
- _outterLayout.PackEnd(_toolbar);
+ //Add callback for item selection
+ _toolbar.Selected += OnCurrentPageChanged;
+ _box.PackEnd(_toolbar);
- _scroller = new Scroller(_outterLayout)
- {
- AlignmentX = -1,
- AlignmentY = -1,
- WeightX = 1,
- WeightY = 1,
- HorizontalPageScrollLimit = 1,
- ScrollBlock = ScrollBlock.Vertical,
- HorizontalScrollBarVisiblePolicy = ScrollBarVisiblePolicy.Invisible
- };
- _scroller.SetPageSize(1.0, 1.0);
- _scroller.PageScrolled += OnItemPageScrolled;
- _scroller.Resized += OnScrollerResized;
-
- _innerBox = new Box(Forms.Context.MainWindow)
- {
- AlignmentX = -1,
- AlignmentY = -1,
- WeightX = 1,
- WeightY = 1,
- IsHorizontal = true,
- };
- _scroller.SetContent(_innerBox);
- _scroller.Show();
-
- _outterLayout.PackEnd(_scroller);
-
- SetNativeControl(_outterLayout);
+ SetNativeControl(_box);
UpdateTitle();
}
base.OnElementChanged(e);
}
- void OnScrollerResized(object sender, System.EventArgs e)
- {
- foreach (var item in _itemToItemPage)
- {
- var nativeView = Platform.GetRenderer(item.Value).NativeView;
- nativeView.MinimumWidth = _scroller.Geometry.Width;
- nativeView.MinimumHeight = _scroller.Geometry.Height;
- }
- int index = Pages.IndexOf(_itemToItemPage[_toolbar.SelectedItem]);
- _scroller.ScrollTo(index, 0, true);
- }
-
- void OnItemPageScrolled(object sender, System.EventArgs e)
- {
- Page newPage = Element.GetPageByIndex(_scroller.HorizontalPageIndex);
- foreach (var pair in _itemToItemPage)
- {
- if (pair.Value == newPage)
- {
- pair.Key.IsSelected = true;
- return;
- }
- }
-
- }
-
protected override void Dispose(bool disposing)
{
- if (_outterLayout != null)
+ if (_box != null)
{
- _outterLayout.Unrealize();
- _outterLayout = null;
+ _box.Unrealize();
+ _box = null;
}
if (_toolbar != null)
{
- _toolbar.Selected -= OnToolbarItemSelected;
- _scroller.PageScrolled -= OnItemPageScrolled;
+ _toolbar.Selected -= OnCurrentPageChanged;
_toolbar.Unrealize();
_toolbar = null;
@@ -147,7 +91,7 @@ namespace Xamarin.Forms.Platform.Tizen
protected override void OnElementReady()
{
- FillToolbarAndContents();
+ FillToolbar();
base.OnElementReady();
}
@@ -200,53 +144,73 @@ namespace Xamarin.Forms.Platform.Tizen
}
}
- void FillToolbarAndContents()
+ void FillToolbar()
{
+ var logicalChildren = (Element as IElementController).LogicalChildren;
+
//add items to toolbar
- foreach (Page child in Pages)
+ foreach (Page child in logicalChildren)
{
+ var childRenderer = Platform.GetRenderer(child);
+ if (childRenderer != null)
+ {
+ childRenderer.NativeView.Hide();
+ }
+
EToolbarItem toolbarItem = _toolbar.Append(child.Title, string.IsNullOrEmpty(child.Icon) ? null : ResourcePath.GetPath(child.Icon));
if (Element.BarBackgroundColor != Color.Default)
{
toolbarItem.SetPartColor("bg", _toolbar.BackgroundColor);
}
_itemToItemPage.Add(toolbarItem, child);
-
- var childContent = Platform.GetOrCreateRenderer(child).NativeView;
- _innerBox.PackEnd(childContent);
-
if (Element.CurrentPage == child)
{
//select item on the toolbar and fill content
toolbarItem.IsSelected = true;
+ CreateNewPage();
}
child.PropertyChanged += OnPageTitleChanged;
}
}
- void OnToolbarItemSelected(object sender, EToolbarItemEventArgs e)
+ void OnCurrentPageChanged(object sender, EToolbarItemEventArgs e)
{
if (_toolbar.SelectedItem == null)
return;
- var oldPage = Element.CurrentPage;
- var newPage = _itemToItemPage[_toolbar.SelectedItem];
+ var selectedContent = Platform.GetRenderer(_itemToItemPage[e.Item]).NativeView;
- if (oldPage == newPage)
+ if (selectedContent == _content)
return;
- oldPage?.SendDisappearing();
-
- Element.CurrentPage = newPage;
- newPage?.SendAppearing();
+ //detach content from view without EvasObject changes
+ if (_content != null)
+ {
+ //hide content that should not be visible
+ _content.Hide();
+ //unpack content that is hiden an prepare for new content
+ _box.UnPack(_content);
+ Element.CurrentPage?.SendDisappearing();
+ }
+ Element.CurrentPage = _itemToItemPage[_toolbar.SelectedItem];
+ CreateNewPage();
+ }
- int index = MultiPage<Page>.GetIndex(newPage);
- _scroller.ScrollTo(index, 0, true);
+ void CreateNewPage()
+ {
+ //create EvasObject using renderer and remember to not destroy
+ //it for better performance (create once)
+ _content = Platform.GetOrCreateRenderer(Element.CurrentPage).NativeView;
+ _content.SetAlignment(-1, -1);
+ _content.SetWeight(1, 1);
+ _content.Show();
+ _box.PackEnd(_content);
+ Element.CurrentPage?.SendAppearing();
}
void CurrentPageChanged()
{
- foreach (var pair in _itemToItemPage)
+ foreach (KeyValuePair<EToolbarItem, Page> pair in _itemToItemPage)
{
if (pair.Value == Element.CurrentPage)
{