From 30ec18a9523f7eb7f77b62ff75de05eb0b8aba77 Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Wed, 7 Jul 2021 13:42:08 +0900 Subject: [PATCH] [NUI] Fix AppBar not to use ViewStyle. (#3269) ViewStyle is the last applied style which is not the 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 --- .../Controls/Navigation/AppBar.cs | 76 ++++++++++++++-------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/src/Tizen.NUI.Components/Controls/Navigation/AppBar.cs b/src/Tizen.NUI.Components/Controls/Navigation/AppBar.cs index 14936c2..3bb879d 100755 --- a/src/Tizen.NUI.Components/Controls/Navigation/AppBar.cs +++ b/src/Tizen.NUI.Components/Controls/Navigation/AppBar.cs @@ -41,7 +41,10 @@ namespace Tizen.NUI.Components private View defaultTitleContent = null; private View defaultActionContent = null; - private AppBarStyle appBarStyle => ViewStyle as AppBarStyle; + private Extents navigationPadding; + private Extents actionPadding; + private ViewStyle actionViewStyle; + private ButtonStyle actionButtonStyle; private bool styleApplied = false; @@ -297,13 +300,13 @@ namespace Tizen.NUI.Components foreach (var action in actionContentViews) { // Apply Action and ActionButton styles. - if ((action is Button) && (appBarStyle?.ActionButton != null)) + if ((action is Button) && (actionButtonStyle != null)) { - action.ApplyStyle(appBarStyle.ActionButton); + action.ApplyStyle(actionButtonStyle); } - else if (appBarStyle?.ActionView != null) + else if (actionViewStyle != null) { - action.ApplyStyle(appBarStyle.ActionView); + action.ApplyStyle(actionViewStyle); } ActionContent.Add(action); @@ -341,13 +344,13 @@ namespace Tizen.NUI.Components foreach (var action in Actions) { // Apply Action and ActionButton styles. - if ((action is Button) && (appBarStyle?.ActionButton != null)) + if ((action is Button) && (actionButtonStyle != null)) { - action.ApplyStyle(appBarStyle.ActionButton); + action.ApplyStyle(actionButtonStyle); } - else if (appBarStyle?.ActionView != null) + else if (actionViewStyle != null) { - action.ApplyStyle(appBarStyle.ActionView); + action.ApplyStyle(actionViewStyle); } actionContent.Add(action); @@ -485,22 +488,39 @@ namespace Tizen.NUI.Components base.ApplyStyle(viewStyle); + var appBarStyle = viewStyle as AppBarStyle; + + if (appBarStyle == null) + { + return; + } + + if (appBarStyle.NavigationPadding != null) + { + navigationPadding = new Extents(appBarStyle.NavigationPadding); + } + + if (appBarStyle.ActionPadding != null) + { + actionPadding = new Extents(appBarStyle.ActionPadding); + } + // Apply Back Button style. - if ((appBarStyle?.BackButton != null) && (DefaultNavigationContent is Button button)) + if ((appBarStyle.BackButton != null) && (DefaultNavigationContent is Button button)) { button.ApplyStyle(appBarStyle.BackButton); } // Apply Title style. - if ((appBarStyle?.TitleTextLabel != null) && (DefaultTitleContent is TextLabel textLabel)) + if ((appBarStyle.TitleTextLabel != null) && (DefaultTitleContent is TextLabel textLabel)) { textLabel.ApplyStyle(appBarStyle.TitleTextLabel); } // Apply ActionCellPadding style. - if (DefaultActionContent?.Layout is LinearLayout linearLayout) + if (DefaultActionContent?.Layout is LinearLayout linearLayout && appBarStyle.ActionCellPadding != null) { - linearLayout.CellPadding = new Size2D(appBarStyle?.ActionCellPadding?.Width ?? 0, appBarStyle?.ActionCellPadding?.Height ?? 0); + linearLayout.CellPadding = new Size2D(appBarStyle.ActionCellPadding.Width, appBarStyle.ActionCellPadding.Height); } // Apply Action and ActionButton styles. @@ -508,17 +528,24 @@ namespace Tizen.NUI.Components { foreach (var action in DefaultActionContent?.Children) { - if ((action is Button) && (appBarStyle?.ActionButton != null)) + if ((action is Button) && (appBarStyle.ActionButton != null)) { action.ApplyStyle(appBarStyle.ActionButton); } - else if (appBarStyle?.ActionView != null) + else if (appBarStyle.ActionView != null) { action.ApplyStyle(appBarStyle.ActionView); } } } + if (actionButtonStyle == null) actionButtonStyle = (ButtonStyle)appBarStyle.ActionButton.Clone(); + else actionButtonStyle.MergeDirectly(appBarStyle.ActionButton); + + if (actionViewStyle == null) actionViewStyle = (ViewStyle)appBarStyle.ActionView.Clone(); + else actionViewStyle.MergeDirectly(appBarStyle.ActionView); + + styleApplied = true; // Calculate children's positions based on padding sizes. @@ -558,7 +585,7 @@ namespace Tizen.NUI.Components private View CreateDefaultNavigationContent() { - var backButton = new Button(appBarStyle?.BackButton ?? null); + var backButton = new Button(); backButton.Clicked += (object sender, ClickedEventArgs args) => { @@ -579,7 +606,7 @@ namespace Tizen.NUI.Components private View CreateDefaultTitleContent() { - return new TextLabel(appBarStyle?.TitleTextLabel ?? null) + return new TextLabel() { HeightSpecification = LayoutParamPolicies.MatchParent, Weight = 1.0f, @@ -593,9 +620,6 @@ namespace Tizen.NUI.Components Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Horizontal, - - // Apply ActionCellPadding style. - CellPadding = new Size2D(appBarStyle?.ActionCellPadding?.Width ?? 0, appBarStyle?.ActionCellPadding?.Height ?? 0), }, Weight = 0.0f, }; @@ -647,20 +671,20 @@ namespace Tizen.NUI.Components } // Apply NavigationPadding style. - if ((NavigationContent != null) && (appBarStyle?.NavigationPadding != null)) + if ((NavigationContent != null) && (navigationPadding != null)) { - if (NavigationContent.Margin.NotEqualTo(appBarStyle.NavigationPadding)) + if (NavigationContent.Margin.NotEqualTo(navigationPadding)) { - NavigationContent.Margin.CopyFrom(appBarStyle.NavigationPadding); + NavigationContent.Margin.CopyFrom(navigationPadding); } } // Apply ActionPadding style. - if ((ActionContent != null) && (appBarStyle?.ActionPadding != null)) + if ((ActionContent != null) && (actionPadding != null)) { - if (ActionContent.Margin.NotEqualTo(appBarStyle.ActionPadding)) + if (ActionContent.Margin.NotEqualTo(actionPadding)) { - ActionContent.Margin.CopyFrom(appBarStyle.ActionPadding); + ActionContent.Margin.CopyFrom(actionPadding); } } } -- 2.7.4