From: Jiyun Yang Date: Tue, 6 Jul 2021 09:41:58 +0000 (+0900) Subject: [NUI] Fix picker not to use ViewStyle. (#3267) X-Git-Tag: accepted/tizen/unified/20231205.024657~1706 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=707b7851c000abd3bf291139be7991d1c91e1978;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Fix picker not to use ViewStyle. (#3267) ViewStyle is the last applied style which is not same as the current style. Hence it is not recommanded to use ViewStyle inside components code. (Please note that View.ViewStyle is deprecated and better not to use.) Signed-off-by: Jiyun Yang --- diff --git a/src/Tizen.NUI.Components/Controls/DatePicker.cs b/src/Tizen.NUI.Components/Controls/DatePicker.cs index 1cbb2c9..0d22c2b 100755 --- a/src/Tizen.NUI.Components/Controls/DatePicker.cs +++ b/src/Tizen.NUI.Components/Controls/DatePicker.cs @@ -61,7 +61,6 @@ namespace Tizen.NUI.Components private Picker dayPicker; private Picker monthPicker; private Picker yearPicker; - private DatePickerStyle datePickerStyle => ViewStyle as DatePickerStyle; /// /// Creates a new instance of DatePicker. @@ -69,7 +68,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public DatePicker() { - Initialize(); } /// @@ -79,7 +77,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public DatePicker(string style) : base(style) { - Initialize(); } /// @@ -89,7 +86,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public DatePicker(DatePickerStyle datePickerStyle) : base(datePickerStyle) { - Initialize(); } @@ -180,18 +176,35 @@ namespace Tizen.NUI.Components dayPicker.CurrentValue = currentDate.Day; monthPicker.CurrentValue = currentDate.Month; yearPicker.CurrentValue = currentDate.Year; + + Initialize(); } - + + /// + [EditorBrowsable(EditorBrowsableState.Never)] [SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "The CellPadding will be dispose when the date picker disposed")] + public override void ApplyStyle(ViewStyle viewStyle) + { + base.ApplyStyle(viewStyle); + + if (viewStyle is DatePickerStyle datePickerStyle && Layout is LinearLayout linearLayout) + { + linearLayout.CellPadding = new Size(datePickerStyle.CellPadding.Width, datePickerStyle.CellPadding.Height); + + yearPicker.ApplyStyle(datePickerStyle.Pickers); + monthPicker.ApplyStyle(datePickerStyle.Pickers); + dayPicker.ApplyStyle(datePickerStyle.Pickers); + } + } + private void Initialize() { HeightSpecification = LayoutParamPolicies.MatchParent; Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Horizontal, - CellPadding = new Size(datePickerStyle.CellPadding.Width, datePickerStyle.CellPadding.Height), }; PickersOrderSet(); diff --git a/src/Tizen.NUI.Components/Controls/Picker.cs b/src/Tizen.NUI.Components/Controls/Picker.cs index 38e3a21..57cd547 100755 --- a/src/Tizen.NUI.Components/Controls/Picker.cs +++ b/src/Tizen.NUI.Components/Controls/Picker.cs @@ -79,7 +79,8 @@ namespace Tizen.NUI.Components private View upLine; private View downLine; private IList itemList; - private PickerStyle pickerStyle => ViewStyle as PickerStyle; + private Vector2 size; + private TextLabelStyle itemTextLabel; /// /// Creates a new instance of Picker. @@ -87,7 +88,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public Picker() { - Initialize(); } /// @@ -97,7 +97,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public Picker(string style) : base(style) { - Initialize(); } /// @@ -107,7 +106,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public Picker(PickerStyle pickerStyle) : base(pickerStyle) { - Initialize(); } /// @@ -253,6 +251,8 @@ namespace Tizen.NUI.Components { base.OnInitialize(); SetAccessibilityConstructor(Role.List); + + Initialize(); } /// @@ -264,13 +264,30 @@ namespace Tizen.NUI.Components { base.ApplyStyle(viewStyle); + var pickerStyle = viewStyle as PickerStyle; + + if (pickerStyle == null) return; + + pickerScroller?.SetPickerStyle(pickerStyle); + //Apply StartScrollOffset style. - if (pickerStyle?.StartScrollOffset != null) + if (pickerStyle.StartScrollOffset != null) + { startScrollOffset = (int)pickerStyle.StartScrollOffset.Height; + } //Apply ItemTextLabel style. - if (pickerStyle?.ItemTextLabel != null) + if (pickerStyle.ItemTextLabel != null) { + if (itemTextLabel == null) + { + itemTextLabel = (TextLabelStyle)pickerStyle.ItemTextLabel.Clone(); + } + else + { + itemTextLabel.MergeDirectly(pickerStyle.ItemTextLabel); + } + itemHeight = (int)pickerStyle.ItemTextLabel.Size.Height; if (itemList != null) @@ -279,12 +296,34 @@ namespace Tizen.NUI.Components } //Apply PickerCenterLine style. - if (pickerStyle?.Divider != null && upLine != null && downLine != null) + if (pickerStyle.Divider != null && upLine != null && downLine != null) { upLine.ApplyStyle(pickerStyle.Divider); downLine.ApplyStyle(pickerStyle.Divider); downLine.PositionY = (int)pickerStyle.Divider.PositionY + itemHeight; } + + startScrollY = (itemHeight * dummyItemsForLoop) + startScrollOffset; + startY = startScrollOffset; + } + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override void OnRelayout(Vector2 size, RelayoutContainer container) + { + if (size == null) return; + + if (size.Equals(this.size)) + { + return; + } + + this.size = new Vector2(size); + + if (pickerScroller != null && itemList != null) + { + pickerScroller.ScrollAvailableArea = new Vector2(0, (itemList.Count * itemHeight) - size.Height); + } } private void Initialize() @@ -293,9 +332,10 @@ namespace Tizen.NUI.Components //Picker Using scroller internally. actually it is a kind of scroller which has infinity loop, //and item center align features. - pickerScroller = new PickerScroller(pickerStyle) + pickerScroller = new PickerScroller() { - Size = new Size(-1, pickerStyle.Size.Height), + WidthSpecification = LayoutParamPolicies.MatchParent, + HeightSpecification = LayoutParamPolicies.MatchParent, ScrollingDirection = ScrollableBase.Direction.Vertical, Layout = new LinearLayout() { @@ -306,6 +346,7 @@ namespace Tizen.NUI.Components ScrollAvailableArea = new Vector2(0, 10000), Name = "pickerScroller", }; + pickerScroller.Scrolling += OnScroll; pickerScroller.ScrollAnimationEnded += OnScrollAnimationEnded; pickerScroller.ScrollAnimationStarted += OnScrollAnimationStarted; @@ -320,11 +361,6 @@ namespace Tizen.NUI.Components onAnimation = false; loopEnabled = false; - startScrollOffset = (int)pickerStyle.StartScrollOffset.Height; - itemHeight = (int)pickerStyle.ItemTextLabel.Size.Height; - startScrollY = (itemHeight * dummyItemsForLoop) + startScrollOffset; - startY = startScrollOffset; - Add(pickerScroller); AddLine(); } @@ -401,11 +437,8 @@ namespace Tizen.NUI.Components //This is UI requirement. It helps where exactly center item is. private void AddLine() { - upLine = new View(pickerStyle.Divider); - downLine = new View(pickerStyle.Divider) - { - Position = new Position(0, (int)pickerStyle.Divider.PositionY + itemHeight), - }; + upLine = new View(); + downLine = new View(); Add(upLine); Add(downLine); @@ -433,7 +466,7 @@ namespace Tizen.NUI.Components Justification = "The items are added to itemList and are disposed in Picker.Dispose().")] private void AddPickerItem(bool loopEnabled, int idx) { - TextLabel temp = new TextLabel(pickerStyle.ItemTextLabel) + TextLabel temp = new TextLabel(itemTextLabel) { WidthSpecification = LayoutParamPolicies.MatchParent, Text = GetItemText(loopEnabled, idx), @@ -514,7 +547,10 @@ namespace Tizen.NUI.Components UpdateCurrentValue(); //Give a correct scroll area. - pickerScroller.ScrollAvailableArea = new Vector2(0, (itemList.Count * itemHeight) - pickerStyle.Size.Height); + if (size != null) + { + pickerScroller.ScrollAvailableArea = new Vector2(0, (itemList.Count * itemHeight) - size.Height); + } needItemUpdate = false; } @@ -531,15 +567,31 @@ namespace Tizen.NUI.Components private delegate float UserAlphaFunctionDelegate(float progress); private UserAlphaFunctionDelegate customScrollAlphaFunction; - public PickerScroller(PickerStyle pickerStyle) : base() + public PickerScroller() : base() { //Default rate is 0.998. this is for reduce scroll animation length. decelerationRate = 0.991f; - startScrollOffset = (int)pickerStyle.StartScrollOffset.Height; - itemHeight = (int)pickerStyle.ItemTextLabel.Size.Height; logValueOfDeceleration = (float)Math.Log(decelerationRate); } + public void SetPickerStyle(PickerStyle pickerStyle) + { + if (pickerStyle.StartScrollOffset != null) + { + startScrollOffset = (int)pickerStyle.StartScrollOffset.Height; + } + + if (pickerStyle.ItemTextLabel?.Size != null) + { + itemHeight = (int)pickerStyle.ItemTextLabel.Size.Height; + } + + if (pickerStyle.Size != null) + { + Size = new Size(-1, pickerStyle.Size.Height); + } + } + private float CustomScrollAlphaFunction(float progress) { if (panAnimationDelta == 0) diff --git a/src/Tizen.NUI.Components/Controls/TimePicker.cs b/src/Tizen.NUI.Components/Controls/TimePicker.cs index ec3e192..e6d683a 100755 --- a/src/Tizen.NUI.Components/Controls/TimePicker.cs +++ b/src/Tizen.NUI.Components/Controls/TimePicker.cs @@ -14,7 +14,6 @@ * */ using System; -using Tizen.NUI; using Tizen.NUI.BaseComponents; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -63,7 +62,6 @@ namespace Tizen.NUI.Components private Picker hourPicker; private Picker minutePicker; private Picker ampmPicker; - private TimePickerStyle timePickerStyle => ViewStyle as TimePickerStyle; /// /// Creates a new instance of TimePicker. @@ -71,7 +69,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public TimePicker() { - Initialize(); } /// @@ -81,7 +78,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public TimePicker(string style) : base(style) { - Initialize(); } /// @@ -91,7 +87,6 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public TimePicker(TimePickerStyle timePickerStyle) : base(timePickerStyle) { - Initialize(); } /// @@ -242,6 +237,8 @@ namespace Tizen.NUI.Components hourPicker.CurrentValue = currentTime.Hour; minutePicker.CurrentValue = currentTime.Minute; + + Initialize(); } /// @@ -253,6 +250,10 @@ namespace Tizen.NUI.Components { base.ApplyStyle(viewStyle); + var timePickerStyle = viewStyle as TimePickerStyle; + + if (timePickerStyle == null) return; + //Apply CellPadding. if (timePickerStyle?.CellPadding != null && Layout != null) ((LinearLayout)Layout).CellPadding = new Size2D(timePickerStyle.CellPadding.Width, timePickerStyle.CellPadding.Height); @@ -275,7 +276,6 @@ namespace Tizen.NUI.Components Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Horizontal, - CellPadding = new Size(timePickerStyle.CellPadding.Width, timePickerStyle.CellPadding.Height), }; Console.WriteLine("initialize");