diff options
-rw-r--r--[-rwxr-xr-x] | Xamarin.Forms.Platform.Tizen/Native/Dialog.cs | 2 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.Tizen/Native/Label.cs | 13 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs | 5 | ||||
-rwxr-xr-x[-rw-r--r--] | Xamarin.Forms.Platform.Tizen/Renderers/TabbedPageRenderer.cs | 162 |
4 files changed, 119 insertions, 63 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Native/Dialog.cs b/Xamarin.Forms.Platform.Tizen/Native/Dialog.cs index e616ff5a..8e0cb735 100755..100644 --- a/Xamarin.Forms.Platform.Tizen/Native/Dialog.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/Dialog.cs @@ -189,6 +189,8 @@ namespace Xamarin.Forms.Platform.Tizen.Native Dismissed += (s, e) => { OnDismissed(); + //Native control should be freed after dismissed event occurred. (this is EFL's law.) + Unrealize(); }; // Adds a handler for the Shown event. diff --git a/Xamarin.Forms.Platform.Tizen/Native/Label.cs b/Xamarin.Forms.Platform.Tizen/Native/Label.cs index 44eb5cb9..911ca317 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/Label.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/Label.cs @@ -342,6 +342,17 @@ namespace Xamarin.Forms.Platform.Tizen.Native } EdjeObject.EmitSignal(emission, "elm"); + + switch (LineBreakMode) + { + case LineBreakMode.NoWrap: + emission = "elm,state,horizontal,expandable"; + break; + default: + emission = "elm,state,horizontal,fixed"; + break; + } + EdjeObject.EmitSignal(emission, "elm"); } - } + } } diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs index be5de861..d1d9c96d 100644 --- a/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs +++ b/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs @@ -6,9 +6,6 @@ namespace Xamarin.Forms.Platform.Tizen public class LabelRenderer : ViewRenderer<Label, Native.Label> { - static readonly EColor s_defaultBackgroundColor = EColor.Transparent; - static readonly EColor s_defaultForegroundColor = EColor.Black; - static readonly EColor s_defaultTextColor = s_defaultForegroundColor; public LabelRenderer() { @@ -79,7 +76,7 @@ namespace Xamarin.Forms.Platform.Tizen void UpdateTextColor() { - Control.TextColor = Element.TextColor.IsDefault ? s_defaultTextColor : Element.TextColor.ToNative(); + Control.TextColor = Element.TextColor.ToNative(); } void UpdateTextAlignment() 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) { |