* limitations under the License.
*
*/
-using System;
+
using System.ComponentModel;
+using System.Collections.Generic;
using Tizen.NUI.BaseComponents;
namespace Tizen.NUI.Components
{
private bool autoNavigationContent = true;
+ private string title = null;
+
+ private View navigationContent = null;
+ private View titleContent = null;
+ private View actionContent = null;
+ private IEnumerable<View> actionContentViews = null;
+
private View defaultNavigationContent = null;
private View defaultTitleContent = null;
private View defaultActionContent = null;
- private View appBarNavigation = null;
- private View appBarTitle = null;
- private View appBarAction = null;
-
private AppBarStyle appBarStyle => ViewStyle as AppBarStyle;
private bool styleApplied = false;
if (type == DisposeTypes.Explicit)
{
- if (appBarNavigation == defaultNavigationContent)
+ if (navigationContent == defaultNavigationContent)
{
- if (appBarNavigation != null)
+ if (navigationContent != null)
{
- Utility.Dispose(appBarNavigation);
+ Utility.Dispose(navigationContent);
}
}
else
{
- if (appBarNavigation != null)
+ if (navigationContent != null)
{
- Utility.Dispose(appBarNavigation);
+ Utility.Dispose(navigationContent);
}
if (defaultNavigationContent != null)
}
}
- if (appBarTitle == defaultTitleContent)
+ if (titleContent == defaultTitleContent)
{
- if (appBarTitle != null)
+ if (titleContent != null)
{
- Utility.Dispose(appBarTitle);
+ Utility.Dispose(titleContent);
}
}
else
{
- if (appBarTitle != null)
+ if (titleContent != null)
{
- Utility.Dispose(appBarTitle);
+ Utility.Dispose(titleContent);
}
if (defaultTitleContent != null)
}
}
- if (appBarAction == defaultActionContent)
+ if (actionContent == defaultActionContent)
{
- if (appBarAction != null)
+ if (actionContent != null)
{
- Utility.Dispose(appBarAction);
+ Utility.Dispose(actionContent);
}
}
else
{
- if (appBarAction != null)
+ if (actionContent != null)
{
- Utility.Dispose(appBarAction);
+ Utility.Dispose(actionContent);
}
if (defaultActionContent != null)
{
get
{
- return appBarNavigation;
+ return navigationContent;
}
set
{
- if (appBarNavigation == value)
+ if (navigationContent == value)
{
return;
}
- if (appBarNavigation != null)
+ if (navigationContent != null)
{
- Remove(appBarNavigation);
+ Remove(navigationContent);
}
- appBarNavigation = value;
- if (appBarNavigation == null)
+ navigationContent = value;
+ if (navigationContent == null)
{
return;
}
}
/// <summary>
+ /// Title text of AppBar.
+ /// SetTitle sets title text to the default title content.
+ /// If TitleContent is not TextLabel, then Title does not set title text of the TitleContent.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string Title
+ {
+ get
+ {
+ return title;
+ }
+ set
+ {
+ if (title == value)
+ {
+ return;
+ }
+
+ title = value;
+
+ if (TitleContent is TextLabel textLabel)
+ {
+ textLabel.Text = title;
+ }
+ }
+ }
+
+ /// <summary>
/// Title content of AppBar. TitleContent is added to Children automatically.
- /// If TitleContent is set by user, then SetText does not set title text of the replaced TitleContent.
+ /// If TitleContent is not TextLabel, then Title does not set title text of the TitleContent.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public View TitleContent
{
get
{
- return appBarTitle;
+ return titleContent;
}
set
{
- if (appBarTitle == value)
+ if (titleContent == value)
{
return;
}
- if (appBarTitle != null)
+ if (titleContent != null)
{
- Remove(appBarTitle);
+ Remove(titleContent);
}
- appBarTitle = value;
- if (appBarTitle == null)
+ titleContent = value;
+ if (titleContent == null)
{
return;
}
+ if (titleContent is TextLabel textLabel)
+ {
+ textLabel.Text = Title;
+ }
+
ResetContent();
}
}
/// <summary>
+ /// Action views of AppBar.
+ /// Action views are added to ActionContent of AppBar.
+ /// The Action and ActionButton styles of AppBarStyle are applied to actions only by setting Actions.
+ /// If you do not want to apply Action and ActionButton styles to action views, then please use ActionContent.Add() instead.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public IEnumerable<View> Actions
+ {
+ get
+ {
+ return actionContentViews;
+ }
+ set
+ {
+ if (ActionContent == null)
+ {
+ actionContentViews = value;
+ return;
+ }
+
+ if (actionContentViews != null)
+ {
+ foreach (var oldAction in actionContentViews)
+ {
+ if (ActionContent.Children?.Contains(oldAction) == true)
+ {
+ ActionContent.Children.Remove(oldAction);
+ }
+ }
+ }
+
+ actionContentViews = value;
+
+ if (actionContentViews == null)
+ {
+ return;
+ }
+
+ foreach (var action in actionContentViews)
+ {
+ // Apply Action and ActionButton styles.
+ if ((action is Button) && (appBarStyle?.ActionButton != null))
+ {
+ action.ApplyStyle(appBarStyle.ActionButton);
+ }
+ else if (appBarStyle?.ActionView != null)
+ {
+ action.ApplyStyle(appBarStyle.ActionView);
+ }
+
+ ActionContent.Add(action);
+ }
+ }
+ }
+
+ /// <summary>
/// Action content of AppBar. ActionContent is added to Children automatically.
- /// Action content can contain action views and action buttons by AddActions.
- /// If ActionContent is set by user, then AddActions does not add actions to the replaced ActionContent.
- /// The Action and ActionButton styles of AppBarStyle are applied to actions only by AddActions.
- /// If ActionContent is set by user, then RemoveActions does not remove actions from the replaced ActionContent.
+ /// Action content contains action views and action buttons by Actions.
+ /// The Action and ActionButton styles of AppBarStyle are applied to actions only by setting Actions.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public View ActionContent
{
get
{
- return appBarAction;
+ return actionContent;
}
set
{
- if (appBarAction == value)
+ if (actionContent == value)
{
return;
}
- if (appBarAction != null)
+ var oldActionContent = actionContent;
+ actionContent = value;
+
+ // Add views first before remove previous action content
+ // not to cause Garbage Collector collects views.
+ if ((actionContent != null) && (Actions != null))
{
- Remove(appBarAction);
+ foreach (var action in Actions)
+ {
+ // Apply Action and ActionButton styles.
+ if ((action is Button) && (appBarStyle?.ActionButton != null))
+ {
+ action.ApplyStyle(appBarStyle.ActionButton);
+ }
+ else if (appBarStyle?.ActionView != null)
+ {
+ action.ApplyStyle(appBarStyle.ActionView);
+ }
+
+ actionContent.Add(action);
+ }
}
- appBarAction = value;
- if (appBarAction == null)
+ if (oldActionContent != null)
+ {
+ Remove(oldActionContent);
+ }
+
+ if (actionContent == null)
{
return;
}
if (autoNavigationContent == true)
{
- NavigationContent = DefaultNavigationContent;
+ if (NavigationContent == null)
+ {
+ NavigationContent = DefaultNavigationContent;
+ }
}
else if (NavigationContent == DefaultNavigationContent)
{
{
get
{
- //TODO: Do not set default navigation content if there is no previous page.
+ // TODO: Do not set default navigation content if there is no previous page.
if (defaultNavigationContent == null)
{
defaultNavigationContent = CreateDefaultNavigationContent();
base.ApplyStyle(viewStyle);
- //Apply Back Button style.
- if ((appBarStyle?.BackButton != null) && (DefaultNavigationContent is Button))
+ // Apply Back Button style.
+ if ((appBarStyle?.BackButton != null) && (DefaultNavigationContent is Button button))
{
- ((Button)DefaultNavigationContent)?.ApplyStyle(appBarStyle.BackButton);
+ button.ApplyStyle(appBarStyle.BackButton);
}
- //Apply Title style.
- if ((appBarStyle?.TitleTextLabel != null) && (DefaultTitleContent is TextLabel))
+ // Apply Title style.
+ if ((appBarStyle?.TitleTextLabel != null) && (DefaultTitleContent is TextLabel textLabel))
{
- ((TextLabel)DefaultTitleContent)?.ApplyStyle(appBarStyle.TitleTextLabel);
+ textLabel.ApplyStyle(appBarStyle.TitleTextLabel);
}
- //Apply ActionCellPadding style.
- if (DefaultActionContent?.Layout is LinearLayout)
+ // Apply ActionCellPadding style.
+ if (DefaultActionContent?.Layout is LinearLayout linearLayout)
{
- ((LinearLayout)DefaultActionContent?.Layout).CellPadding = new Size2D(appBarStyle?.ActionCellPadding?.Width ?? 0, appBarStyle?.ActionCellPadding?.Height ?? 0);
+ linearLayout.CellPadding = new Size2D(appBarStyle?.ActionCellPadding?.Width ?? 0, appBarStyle?.ActionCellPadding?.Height ?? 0);
}
- //Apply Action and ActionButton styles.
- if (DefaultActionContent?.ChildCount > 0)
+ // Apply Action and ActionButton styles.
+ if (DefaultActionContent?.Children != null)
{
foreach (var action in DefaultActionContent?.Children)
{
if ((action is Button) && (appBarStyle?.ActionButton != null))
{
- ((Button)action)?.ApplyStyle(appBarStyle.ActionButton);
+ action.ApplyStyle(appBarStyle.ActionButton);
}
else if (appBarStyle?.ActionView != null)
{
- action?.ApplyStyle(appBarStyle.ActionView);
+ action.ApplyStyle(appBarStyle.ActionView);
}
}
}
styleApplied = true;
- //Calculate children's positions based on padding sizes.
+ // Calculate children's positions based on padding sizes.
CalculatePosition();
}
/// <summary>
- /// Sets title text of AppBar.
- /// SetTitle sets title text to the default title content.
- /// Therefore, if TitleContent is set by user, then SetTitle does not set title text of the replaced TitleContent.
- /// </summary>
- /// <param name="title">Title text of AppBar.</param>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void SetTitle(string title)
- {
- if (DefaultTitleContent is TextLabel)
- {
- ((TextLabel)DefaultTitleContent).Text = title;
- }
- }
-
- /// <summary>
- /// Adds actions to ActionContent of AppBar.
- /// The Action and ActionButton styles of AppBarStyle are applied to the added actions.
- /// AddActions adds action views to the default action content.
- /// Therefore, if ActionContent is set by user, then AddActions does not add actions to the replaced ActionContent.
- /// </summary>
- /// <param name="actions">Actions to be added to ActionContent of AppBar.</param>
- /// <exception cref="ArgumentNullException">Thrown when the argument actions is null.</exception>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void AddActions(params View[] actions)
- {
- if (actions == null)
- {
- throw new ArgumentNullException(nameof(actions), "actions should not be null.");
- }
-
- foreach (var action in actions)
- {
- //Apply Action and ActionButton styles.
- if ((action is Button) && (appBarStyle?.ActionButton != null))
- {
- ((Button)action)?.ApplyStyle(appBarStyle.ActionButton);
- }
- else if (appBarStyle?.ActionView != null)
- {
- action?.ApplyStyle(appBarStyle.ActionView);
- }
-
- DefaultActionContent.Add(action);
- }
- }
-
- /// <summary>
- /// Removes actions from ActionContent of AppBar.
- /// RemoveActions removes action views from the default action content.
- /// Therefore, if ActionContent is set by user, then RemoveActions does not remove actions from the replaced ActionContent.
+ /// Gets AppBar style.
/// </summary>
- /// <param name="actions">Actions to be removed from ActionContent of AppBar.</param>
- /// <exception cref="ArgumentNullException">Thrown when the argument actions is null.</exception>
+ /// <returns>The default AppBar style.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
- public void RemoveActions(params View[] actions)
+ protected override ViewStyle CreateViewStyle()
{
- if (actions == null)
- {
- throw new ArgumentNullException(nameof(actions), "actions should not be null.");
- }
-
- foreach (var action in actions)
- {
- DefaultActionContent.Remove(action);
- }
+ return new AppBarStyle();
}
private void Initialize()
{
- //Navigation, Title and Action are located horizontally.
- var linearLayout = new LinearLayout()
+ // Navigation, Title and Action are located horizontally.
+ Layout = new LinearLayout()
{
LinearOrientation = LinearLayout.Orientation.Horizontal,
LinearAlignment = LinearLayout.Alignment.CenterVertical,
};
- Layout = linearLayout;
-
WidthSpecification = LayoutParamPolicies.MatchParent;
if (AutoNavigationContent == true)
backButton.Clicked += (object sender, ClickedEventArgs args) =>
{
- //The page of app bar is popped when default back button is clicked.
+ // The page of app bar is popped when default back button is clicked.
var page = GetParent() as Page;
if (page != null)
{
private View CreateDefaultActionContent()
{
- return new Control()
+ return new View()
{
Layout = new LinearLayout()
{
LinearOrientation = LinearLayout.Orientation.Horizontal,
- //Apply ActionCellPadding style.
+ // Apply ActionCellPadding style.
CellPadding = new Size2D(appBarStyle?.ActionCellPadding?.Width ?? 0, appBarStyle?.ActionCellPadding?.Height ?? 0),
},
Weight = 0.0f,
private void ResetContent()
{
- //To keep the order of NavigationContent, TitleContent and ActionContent,
- //the existing contents are removed and added again.
- if ((appBarNavigation != null) && Children.Contains(appBarNavigation))
+ // To keep the order of NavigationContent, TitleContent and ActionContent,
+ // the existing contents are removed and added again.
+ if ((navigationContent != null) && Children.Contains(navigationContent))
{
- Remove(appBarNavigation);
+ Remove(navigationContent);
}
- if ((appBarTitle != null) && Children.Contains(appBarTitle))
+ if ((titleContent != null) && Children.Contains(titleContent))
{
- Remove(appBarTitle);
+ Remove(titleContent);
}
- if ((appBarAction != null) && Children.Contains(appBarAction))
+ if ((actionContent != null) && Children.Contains(actionContent))
{
- Remove(appBarAction);
+ Remove(actionContent);
}
- if (appBarNavigation != null)
+ if (navigationContent != null)
{
- Add(appBarNavigation);
+ Add(navigationContent);
}
- if (appBarTitle != null)
+ if (titleContent != null)
{
- Add(appBarTitle);
+ Add(titleContent);
}
- if (appBarAction != null)
+ if (actionContent != null)
{
- Add(appBarAction);
+ Add(actionContent);
}
- //Calculate children's positions based on padding sizes.
+ // Calculate children's positions based on padding sizes.
CalculatePosition();
}
return;
}
- //Apply NavigationPadding style.
+ // Apply NavigationPadding style.
if ((NavigationContent != null) && (appBarStyle?.NavigationPadding != null))
{
if (NavigationContent.Margin.NotEqualTo(appBarStyle.NavigationPadding))
}
}
- //Apply ActionPadding style.
+ // Apply ActionPadding style.
if ((ActionContent != null) && (appBarStyle?.ActionPadding != null))
{
if (ActionContent.Margin.NotEqualTo(appBarStyle.ActionPadding))
}
}
}
-
- /// <summary>
- /// Gets AppBar style.
- /// </summary>
- /// <returns>The default AppBar style.</returns>
- [EditorBrowsable(EditorBrowsableState.Never)]
- protected override ViewStyle CreateViewStyle()
- {
- return new AppBarStyle();
- }
}
-}
+}
\ No newline at end of file