summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKangho Hur <kangho.hur@samsung.com>2017-06-22 11:44:15 (GMT)
committerKangho Hur <kangho.hur@samsung.com>2017-10-23 04:34:37 (GMT)
commit43b5fb2512b2154e9795715d695dfd3df9554e3a (patch)
treef92aebd66014a0df338a10ff95e43e30ac48a143
parent41f1461b6df2bdca937daf34803bdc9317c8ddfc (diff)
downloadxamarin-forms-43b5fb2512b2154e9795715d695dfd3df9554e3a.zip
xamarin-forms-43b5fb2512b2154e9795715d695dfd3df9554e3a.tar.gz
xamarin-forms-43b5fb2512b2154e9795715d695dfd3df9554e3a.tar.bz2
Remove scroller from TabbedPageRenderer
TASK=TCAPI-2487, TNET-1176 - This patch reverts 803e69866c687c3eefba4160068dd9eb38bcf1a4 Change-Id: I96007352b1911d2c11bd09742ef97eb20d1ff8c1
-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 34e0235..d266119 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)
{