2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.ComponentModel;
19 using Tizen.NUI.BaseComponents;
21 namespace Tizen.NUI.Components
24 /// TabView is a class which contains a TabBar and TabContent and
25 /// selects a view from the TabContent according to the selected TabButton in the TabBar.
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public class TabView : Control
30 private TabBar tabBar = null;
32 private TabContent content = null;
35 /// Creates a new instance of TabView.
37 [EditorBrowsable(EditorBrowsableState.Never)]
40 Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Vertical };
41 WidthSpecification = LayoutParamPolicies.MatchParent;
42 HeightSpecification = LayoutParamPolicies.MatchParent;
48 private void InitTabBar()
55 tabBar = new TabBar();
56 tabBar.TabButtonSelected += tabButtonSelectedHandler;
61 private void InitContent()
68 content = new TabContent();
69 content.WidthSpecification = LayoutParamPolicies.MatchParent;
70 content.HeightSpecification = LayoutParamPolicies.MatchParent;
75 private void tabButtonSelectedHandler(object sender, TabButtonSelectedEventArgs args)
77 if ((content != null) && (content.ViewCount > args.Index))
79 content.Select(args.Index);
84 /// Gets TabBar of TabView.
86 [EditorBrowsable(EditorBrowsableState.Never)]
96 /// Gets TabContent of TabView.
98 [EditorBrowsable(EditorBrowsableState.Never)]
99 public TabContent Content
108 /// Adds a tab with tab button and content view.
110 /// <param name="tabButton">A tab button to be added.</param>
111 /// <param name="view">A content view to be added.</param>
112 [EditorBrowsable(EditorBrowsableState.Never)]
113 public void AddTab(TabButton tabButton, View view)
117 TabBar.AddTabButton(tabButton);
122 Content.AddView(view);
127 /// Removes a tab at the specified index of TabView.
129 /// <param name="index">The index of TabView where a tab will be removed.</param>
130 /// <exception cref="ArgumentOutOfRangeException">Thrown when the index is less than 0, or greater than or equal to the number of tabs.</exception>
131 [EditorBrowsable(EditorBrowsableState.Never)]
132 public void RemoveTab(int index)
134 var tabButton = TabBar.GetTabButton(index);
135 if (tabButton != null)
137 TabBar.RemoveTabButton(tabButton);
140 var view = Content.GetView(index);
143 Content.RemoveView(view);
148 /// Dispose TabView and all children on it.
150 /// <param name="type">Dispose type.</param>
151 [EditorBrowsable(EditorBrowsableState.Never)]
152 protected override void Dispose(DisposeTypes type)
159 if (type == DisposeTypes.Explicit)
163 tabBar.TabButtonSelected -= tabButtonSelectedHandler;
164 Utility.Dispose(tabBar);
169 Utility.Dispose(content);