diff --git a/Xamarin.Forms.Platform.Tizen/Native/TitleViewPage.cs b/Xamarin.Forms.Platform.Tizen/Native/TitleViewPage.cs new file mode 100644 index 000000000..e61b04fda --- /dev/null +++ b/Xamarin.Forms.Platform.Tizen/Native/TitleViewPage.cs @@ -0,0 +1,66 @@ +using System; +using ElmSharp; + +namespace Xamarin.Forms.Platform.Tizen.Native +{ + public class TitleViewPage : Native.Box + { + Native.Page _page = null; + View _titleView = null; + bool _hasNavigationBar = true; + + public TitleViewPage(EvasObject parent, Xamarin.Forms.Page page, View titleView) : base(parent) + { + _page = Platform.GetOrCreateRenderer(page).NativeView as Native.Page; + _titleView = titleView; + if (_titleView != null) + { + var renderer = Platform.GetOrCreateRenderer(_titleView); + (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated(); + + this.PackEnd(renderer.NativeView); + } + this.PackEnd(_page); + this.LayoutUpdated += OnLayoutUpdated; + } + + public bool HasNavigationBar + { + get + { + return _hasNavigationBar; + } + set + { + if (_hasNavigationBar != value) + { + _hasNavigationBar = value; + UpdatPageLayout(this, new LayoutEventArgs() { Geometry = this.Geometry }); + } + + } + } + + void OnLayoutUpdated(object sender, LayoutEventArgs e) + { + UpdatPageLayout(sender, e); + } + + void UpdatPageLayout(object sender, LayoutEventArgs e) + { + double dHeight = _titleView.Measure(Forms.ConvertToScaledDP(e.Geometry.Width), Forms.ConvertToScaledDP(e.Geometry.Height)).Request.Height; + int height = 0; + if (_hasNavigationBar) + { + height = Forms.ConvertToScaledPixel(dHeight); + } + + var renderer = Platform.GetOrCreateRenderer(_titleView); + renderer.NativeView.Move(e.Geometry.X, e.Geometry.Y); + renderer.NativeView.Resize(e.Geometry.Width, height); + + _page.Move(e.Geometry.X, e.Geometry.Y + height); + _page.Resize(e.Geometry.Width, e.Geometry.Height - height); + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/NavigationPageRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/NavigationPageRenderer.cs index 6338c73dc..9a91f70be 100644 --- a/Xamarin.Forms.Platform.Tizen/Renderers/NavigationPageRenderer.cs +++ b/Xamarin.Forms.Platform.Tizen/Renderers/NavigationPageRenderer.cs @@ -115,7 +115,7 @@ namespace Xamarin.Forms.Platform.Tizen foreach (Page page in pageController.InternalChildren) { - _naviItemMap[page] = _naviFrame.Push(Platform.GetRenderer(page).NativeView, SpanTitle(page.Title)); + _naviItemMap[page] = _naviFrame.Push(CreateNavItem(page), SpanTitle(page.Title)); page.PropertyChanged += NavigationBarPropertyChangedHandler; UpdateHasNavigationBar(page); @@ -177,6 +177,16 @@ namespace Xamarin.Forms.Platform.Tizen void UpdateHasNavigationBar(Page page) { NaviItem item = GetNaviItemForPage(page); + if (NavigationPage.GetTitleView(page) != null) + { + item.TitleBarVisible = false; + Native.TitleViewPage tvPage = item.Content as Native.TitleViewPage; + if (tvPage != null) + { + tvPage.HasNavigationBar = (bool)page.GetValue(NavigationPage.HasNavigationBarProperty); + } + return; + } //According to TV UX Guideline, item style should be set to "tabbar" in case of TabbedPage only for TV profile. if (Device.Idiom == TargetIdiom.TV) { @@ -434,7 +444,7 @@ namespace Xamarin.Forms.Platform.Tizen { if (nre.Animated || _naviFrame.NavigationStack.Count == 0) { - _naviItemMap[nre.Page] = _naviFrame.Push(Platform.GetOrCreateRenderer(nre.Page).NativeView, SpanTitle(nre.Page.Title)); + _naviItemMap[nre.Page] = _naviFrame.Push(CreateNavItem(nre.Page), SpanTitle(nre.Page.Title)); _currentTaskSource = new TaskCompletionSource(); nre.Task = _currentTaskSource.Task; @@ -444,7 +454,7 @@ namespace Xamarin.Forms.Platform.Tizen } else { - _naviItemMap[nre.Page] = _naviFrame.InsertAfter(_naviFrame.NavigationStack.Last(), Platform.GetOrCreateRenderer(nre.Page).NativeView, SpanTitle(nre.Page.Title)); + _naviItemMap[nre.Page] = _naviFrame.InsertAfter(_naviFrame.NavigationStack.Last(), CreateNavItem(nre.Page), SpanTitle(nre.Page.Title)); } UpdateHasNavigationBar(nre.Page); } @@ -463,8 +473,7 @@ namespace Xamarin.Forms.Platform.Tizen if (nre.Page == null) throw new ArgumentNullException("page"); - EvasObject page = Platform.GetOrCreateRenderer(nre.Page).NativeView; - _naviItemMap[nre.Page] = _naviFrame.InsertBefore(GetNaviItemForPage(nre.BeforePage), page, SpanTitle(nre.Page.Title)); + _naviItemMap[nre.Page] = _naviFrame.InsertBefore(GetNaviItemForPage(nre.BeforePage), CreateNavItem(nre.Page), SpanTitle(nre.Page.Title)); UpdateHasNavigationBar(nre.Page); } @@ -482,5 +491,23 @@ namespace Xamarin.Forms.Platform.Tizen tmp.SetResult(true); } } + + EvasObject CreateNavItem(Page page) + { + View titleView = NavigationPage.GetTitleView(page) as View; + EvasObject nativeView = null; + if (titleView != null) + { + titleView.Parent = this.Element; + nativeView = new Native.TitleViewPage(Forms.NativeParent, page, titleView); + nativeView.Show(); + } + else + { + nativeView = Platform.GetOrCreateRenderer(page).NativeView; + + } + return nativeView; + } } }