summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/Renderers
diff options
context:
space:
mode:
authorjh5.cho <jh5.cho@samsung.com>2017-04-04 21:02:55 +0900
committerKangho Hur <kangho.hur@samsung.com>2017-07-10 11:11:24 +0900
commitad4e38dcaa115d121bc0f1ea08ec37adfd33f4fa (patch)
tree69ee6600e3dfb38dadd98f0fbc31dec7167d5d19 /Xamarin.Forms.Platform.Tizen/Renderers
parent9f4a7c298b4e85bfc5acd7b63adce6c29343a686 (diff)
downloadxamarin-forms-ad4e38dcaa115d121bc0f1ea08ec37adfd33f4fa.tar.gz
xamarin-forms-ad4e38dcaa115d121bc0f1ea08ec37adfd33f4fa.tar.bz2
xamarin-forms-ad4e38dcaa115d121bc0f1ea08ec37adfd33f4fa.zip
[TabbedPageRenderer] Apply Slide Navigation on TabbedPage
TASK=TCAPI-2248 - Refactoring Code has done Change-Id: I79a44da01308f7aac273651a1dcbc370f9668c6c Signed-off-by: jh5.cho <jh5.cho@samsung.com>
Diffstat (limited to 'Xamarin.Forms.Platform.Tizen/Renderers')
-rwxr-xr-x[-rw-r--r--]Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs162
1 files changed, 104 insertions, 58 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs
index 36b9a074..bd891025 100644..100755
--- a/Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs
+++ b/Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs
@@ -6,15 +6,18 @@ using EToolbarItem = ElmSharp.ToolbarItem;
using EToolbarItemEventArgs = ElmSharp.ToolbarItemEventArgs;
using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
+using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Platform.Tizen
{
public class TabbedPageRenderer : VisualElementRenderer<TabbedPage>, IVisualElementRenderer
{
- Box _box;
- Toolbar _tpage;
- EvasObject _tcontent;
+ Box _outterLayout;
+ Box _innerBox;
+ Scroller _scroller;
+ Toolbar _toolbar;
Dictionary<EToolbarItem, Page> _itemToItemPage = new Dictionary<EToolbarItem, Page>();
+ IReadOnlyCollection<Element> Pages => (Element as IElementController).LogicalChildren;
public TabbedPageRenderer()
{
@@ -22,15 +25,14 @@ 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
}
protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
{
- if (_tpage == null)
+ if (_toolbar == null)
{
//Create box that holds toolbar and selected content
- _box = new Box(Forms.Context.MainWindow)
+ _outterLayout = new Box(Forms.Context.MainWindow)
{
AlignmentX = -1,
AlignmentY = -1,
@@ -38,60 +40,114 @@ namespace Xamarin.Forms.Platform.Tizen
WeightY = 1,
IsHorizontal = false,
};
- _box.Show();
+ _outterLayout.Show();
- //Create toolbar that is placed inside the _box
- _tpage = new Toolbar(Forms.Context.MainWindow)
+ //Create toolbar that is placed inside the _outterLayout
+ _toolbar = new Toolbar(Forms.Context.MainWindow)
{
AlignmentX = -1,
WeightX = 1,
SelectionMode = ToolbarSelectionMode.Always,
Style = "tabbar_with_title"
};
- _tpage.Show();
- //Add callback for item selection
- _tpage.Selected += OnCurrentPageChanged;
- _box.PackEnd(_tpage);
+ _toolbar.Show();
+ //Add callback for Toolbar item selection
+ _toolbar.Selected += OnToolbarItemSelected;
+ _outterLayout.PackEnd(_toolbar);
- SetNativeControl(_box);
+ _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);
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 (_box != null)
+ if (_outterLayout != null)
{
- _box.Unrealize();
- _box = null;
+ _outterLayout.Unrealize();
+ _outterLayout = null;
}
- if (_tpage != null)
+ if (_toolbar != null)
{
- _tpage.Selected -= OnCurrentPageChanged;
+ _toolbar.Selected -= OnToolbarItemSelected;
+ _scroller.PageScrolled -= OnItemPageScrolled;
- _tpage.Unrealize();
- _tpage = null;
+ _toolbar.Unrealize();
+ _toolbar = null;
}
base.Dispose(disposing);
}
protected override void OnElementReady()
{
- FillToolbar();
+ FillToolbarAndContents();
base.OnElementReady();
}
protected override void UpdateThemeStyle()
{
- _tpage.Style = Element.OnThisPlatform().GetStyle();
+ _toolbar.Style = Element.OnThisPlatform().GetStyle();
((IVisualElementController)Element).NativeSizeChanged();
}
void UpdateTitle()
{
- _tpage.Text = Element.Title;
+ _toolbar.Text = Element.Title;
}
void UpdateTitle(Page page)
@@ -111,60 +167,50 @@ namespace Xamarin.Forms.Platform.Tizen
}
}
- void FillToolbar()
+ void FillToolbarAndContents()
{
- var logicalChildren = (Element as IElementController).LogicalChildren;
-
//add items to toolbar
- foreach (Page child in logicalChildren)
+ foreach (Page child in Pages)
{
- var childRenderer = Platform.GetRenderer(child);
- if (childRenderer != null)
- {
- childRenderer.NativeView.Hide();
- }
-
- EToolbarItem toolbarItem = _tpage.Append(child.Title, string.IsNullOrEmpty(child.Icon) ? null : ResourcePath.GetPath(child.Icon));
+ EToolbarItem toolbarItem = _toolbar.Append(child.Title, string.IsNullOrEmpty(child.Icon) ? null : ResourcePath.GetPath(child.Icon));
_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;
- OnCurrentPageChanged(null, null);
}
child.PropertyChanged += OnPageTitleChanged;
}
}
- void OnCurrentPageChanged(object sender, EToolbarItemEventArgs e)
+ void OnToolbarItemSelected(object sender, EToolbarItemEventArgs e)
{
- if (_tpage.SelectedItem == null)
+ if (_toolbar.SelectedItem == null)
return;
- //detach content from view without EvasObject changes
- if (_tcontent != null)
- {
- //hide content that should not be visible
- _tcontent.Hide();
- //unpack content that is hiden an prepare for new content
- _box.UnPack(_tcontent);
- (Element.CurrentPage as IPageController)?.SendDisappearing();
- }
- Element.CurrentPage = _itemToItemPage[_tpage.SelectedItem];
-
- //create EvasObject using renderer and remember to not destroy
- //it for better performance (create once)
- _tcontent = Platform.GetOrCreateRenderer(Element.CurrentPage).NativeView;
- _tcontent.SetAlignment(-1, -1);
- _tcontent.SetWeight(1, 1);
- _tcontent.Show();
- _box.PackEnd(_tcontent);
- (Element.CurrentPage as IPageController)?.SendAppearing();
+
+ var oldPage = Element.CurrentPage;
+ var newPage = _itemToItemPage[_toolbar.SelectedItem];
+
+ if (oldPage == newPage)
+ return;
+
+ oldPage?.SendDisappearing();
+
+ Element.CurrentPage = newPage;
+ newPage?.SendAppearing();
+
+ int index = MultiPage<Page>.GetIndex(newPage);
+ _scroller.ScrollTo(index, 0, true);
}
void CurrentPageChanged()
{
- foreach (KeyValuePair<EToolbarItem, Page> pair in _itemToItemPage)
+ foreach (var pair in _itemToItemPage)
{
if (pair.Value == Element.CurrentPage)
{