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.
25 /// TabView adds TabButtons and Views to TabBar and TabContent in TabView by <see cref="TabView.AddTab"/>.
26 /// TabView removes TabButtons and Views from TabBar and TabContent in TabView by <see cref="TabView.RemoveTab"/>.
27 /// TabView selects a view from the TabContent according to the selected TabButton in the TabBar.
31 /// var tabView = new TabView()
33 /// WidthSpecification = LayoutParamPolicies.MatchParent,
34 /// HeightSpecification = LayoutParamPolicies.MatchParent,
37 /// var tabButton = new TabButton()
42 /// var content = new View()
44 /// BackgroundColor = Color.Red,
45 /// WidthSpecification = LayoutParamPolicies.MatchParent,
46 /// HeightSpecification = LayoutParamPolicies.MatchParent,
49 /// tabView.AddTab(tabButton, content);
51 /// var tabButton2 = new TabButton()
56 /// var content2 = new View()
58 /// BackgroundColor = Color.Green,
59 /// WidthSpecification = LayoutParamPolicies.MatchParent,
60 /// HeightSpecification = LayoutParamPolicies.MatchParent,
63 /// tabView.AddTab(tabButton2, content2);
65 /// var tabButton3 = new TabButton()
70 /// var content3 = new View()
72 /// BackgroundColor = Color.Blue,
73 /// WidthSpecification = LayoutParamPolicies.MatchParent,
74 /// HeightSpecification = LayoutParamPolicies.MatchParent,
77 /// tabView.AddTab(tabButton3, content3);
81 /// <since_tizen> 9 </since_tizen>
82 public class TabView : Control
84 private TabBar tabBar = null;
86 private TabContent content = null;
89 /// Creates a new instance of TabView.
91 /// <since_tizen> 9 </since_tizen>
94 Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Vertical };
95 WidthSpecification = LayoutParamPolicies.MatchParent;
96 HeightSpecification = LayoutParamPolicies.MatchParent;
103 [EditorBrowsable(EditorBrowsableState.Never)]
104 public override void OnInitialize()
108 SetAccessibilityConstructor(Role.PageTabList);
111 private void InitTabBar()
118 tabBar = new TabBar();
119 tabBar.TabButtonSelected += tabButtonSelectedHandler;
124 private void InitContent()
131 content = new TabContent();
132 content.WidthSpecification = LayoutParamPolicies.MatchParent;
133 content.HeightSpecification = LayoutParamPolicies.MatchParent;
138 private void tabButtonSelectedHandler(object sender, TabButtonSelectedEventArgs args)
140 if ((content != null) && (content.ViewCount > args.Index))
142 content.Select(args.Index);
147 /// Gets TabBar of TabView.
149 /// <since_tizen> 9 </since_tizen>
159 /// Gets TabContent of TabView.
161 /// <since_tizen> 9 </since_tizen>
162 public TabContent Content
171 /// Adds a tab with tab button and content view.
173 /// <param name="tabButton">A tab button to be added.</param>
174 /// <param name="view">A content view to be added.</param>
175 /// <since_tizen> 9 </since_tizen>
176 public void AddTab(TabButton tabButton, View view)
180 TabBar.AddTabButton(tabButton);
185 Content.AddView(view);
190 /// Removes a tab at the specified index of TabView.
191 /// The indices of tabs(tab buttons and views) in TabView are basically the order of adding to TabView by <see cref="TabView.AddTab"/>.
192 /// So the index of a tab(tab button and view) in TabView can be changed whenever <see cref="TabView.AddTab"/> or <see cref="TabView.RemoveTab"/> is called.
194 /// <param name="index">The index of a tab(tab button and view) in TabView where the tab will be removed.</param>
195 /// <exception cref="ArgumentOutOfRangeException">Thrown when the index is less than 0, or greater than or equal to the number of tabs.</exception>
196 /// <since_tizen> 9 </since_tizen>
197 public void RemoveTab(int index)
199 var tabButton = TabBar.GetTabButton(index);
200 if (tabButton != null)
202 TabBar.RemoveTabButton(tabButton);
205 var view = Content.GetView(index);
208 Content.RemoveView(view);
213 [EditorBrowsable(EditorBrowsableState.Never)]
214 protected override void Dispose(DisposeTypes type)
221 if (type == DisposeTypes.Explicit)
225 tabBar.TabButtonSelected -= tabButtonSelectedHandler;
226 Utility.Dispose(tabBar);
231 Utility.Dispose(content);