Skip to content

Commit a316e53

Browse files
tsonevnSvetoslavTsenov
authored andcommitted
new tabview examples (NativeScript#5628)
* new tabview exmples * tabs limit example * minor code snippet edits
1 parent 9ec2839 commit a316e53

1 file changed

Lines changed: 88 additions & 41 deletions

File tree

tests/app/ui/tab-view/tab-view.md

Lines changed: 88 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,27 @@ description: "Examples for using TabView"
66
previous_url: /ApiReference/ui/tab-view/HOW-TO
77
---
88
# TabView
9+
The TabView is a component, which allows to navigate between different views. The general behaviour of the TabView component is to load its items on demand. This means that every TabViewItem view will be loaded when it is shown and will be unloaded when it disappears. Respectively loaded and unloaded events will be fired while showing or hiding each view. However, there are some specifics for each platform(iOS and Android), which are described in the notes below.
10+
11+
> Note (iOS specific): `UITabBarController` is used in the implementation, which means that only one `TabViewItem` can be shown at a given time and only one needs to be loaded. When the user selects a new `TabViewItem`, we load the new item and unload the previous one.
12+
13+
> Note (Android specific): In the Android implementation is used `ViewPager` controller, which allows using the `swipe` gesture to navigate to the next or previous tab. This means that only one `TabViewItem` can be shown, but multiple `TabViewItems` need to be loaded. Otherwise, after left or right swipe, you will not see the `TabViewItem`'s contents, after the swiping. By default, the ViewPager controller will pre-load one `TabViewItem` on the left and on on the right. Regarding that, if one of the items is already pre-loaded, it will not be loaded again. In the Android, we have exposed a property called `androidOffscreenTabLimit`, which allow specifying, how many components should be pre-load on the left and right (if you are setting up `androidOffscreenTabLimit` to 0, the Android TabView will match to the iOS TabView).
14+
15+
The iOS and Android UX guidelines regarding the Tab controls differ greatly. The difference is described in the below points:
16+
17+
* The iOS tabs have their tab bar, which will be displayed always on the bottom and does not allow swipe gesture for changing tabs.
18+
* The Android tabs are on top and will enable the swipe navigation between the tabs.
19+
* For Android we have `androidTabsPosition` property which has two options `top`(default value) and `bottom`. Setting up this property to `bottom` allows mimicking Bottom Tab Navigation control(provided by android support library v25 release). Setting the Tabs at the bottom will disable the swipe navigation and the items preloading functionality.
20+
921
### Declaring the TabView in xml.
1022
``` XML
11-
<Page>
1223
<TabView>
13-
<TabView.items>
1424
<TabViewItem title="Tab 1">
15-
<TabViewItem.view>
16-
<Label text="Label in Tab1" />
17-
</TabViewItem.view>
25+
// ...
1826
</TabViewItem>
1927
<TabViewItem title="Tab 2">
20-
<TabViewItem.view>
21-
<Label text="Label in Tab2" />
22-
</TabViewItem.view>
28+
// ...
2329
</TabViewItem>
24-
</TabView.items>
2530
</TabView>
2631
</Page>
2732
```
@@ -37,11 +42,9 @@ Using a TabView requires the "ui/tab-view" module.
3742
{%snippet article-tabview-selectedIndexChanged%}
3843
### Using selectedIndexChanged event from xml
3944
```XML
40-
<Page>
41-
<TabView selectedIndexChanged="onSelectedIndexChanged">
42-
...
43-
</TabView>
44-
</Page>
45+
<TabView selectedIndexChanged="onSelectedIndexChanged">
46+
...
47+
</TabView>
4548
```
4649
```TypeScript
4750
export function onSelectedIndexChanged(args) {...}
@@ -57,37 +60,81 @@ For the TabView component could be set three different styling properties
5760
* `textTransform` (coresponding CSS property `text-transform`) - setting up textTransform individual for every `TabViewItem`. Value options: `capitalize`, `lowercase`, `none`, `uppercase`.
5861

5962
```XML
60-
<TabView selectedTabTextColor="#00FF00" tabBackgroundColor="#FF0000" >
61-
<TabView.items>
62-
<TabViewItem title="Tab 1" textTransform="lowercase">
63-
<TabViewItem.view>
64-
<Label text="Label in Tab1" />
65-
</TabViewItem.view>
66-
</TabViewItem>
67-
<TabViewItem title="Tab 2" textTransform="lowercase">
68-
<TabViewItem.view>
69-
<Label text="Label in Tab2" />
70-
</TabViewItem.view>
71-
</TabViewItem>
72-
</TabView.items>
63+
<TabView selectedTabTextColor="#00FF00" tabBackgroundColor="#FF0000">
64+
<TabViewItem title="Tab 1" textTransform="lowercase">
65+
<Label text="Label in Tab1" />
66+
</TabViewItem>
67+
<TabViewItem title="Tab 2" textTransform="lowercase">
68+
<Label text="Label in Tab2" />
69+
</TabViewItem>
7370
</TabView>
71+
7472
```
7573

7674
* `androidSelectedTabHighlightColor`<sup>android specific property</sup> (coresponding CSS property `android-selected-tab-highlight-color`) - setup underline color of the `Tab`s in Android.
7775

7876
```XML
7977
<TabView androidSelectedTabHighlightColor="red">
80-
<TabView.items>
81-
<TabViewItem title="Tab 1" >
82-
<TabViewItem.view>
83-
<Label text="Label in Tab1"/>
84-
</TabViewItem.view>
85-
</TabViewItem>
86-
<TabViewItem title="Tab 2">
87-
<TabViewItem.view>
88-
<Label text="Label in Tab2" />
89-
</TabViewItem.view>
90-
</TabViewItem>
91-
</TabView.items>
92-
</TabView>
93-
```
78+
<TabViewItem title="Tab 1">
79+
<Label text="Label in Tab1" />
80+
</TabViewItem>
81+
<TabViewItem title="Tab 2">
82+
<Label text="Label in Tab2" />
83+
</TabViewItem>
84+
</TabView>
85+
```
86+
87+
## Tabs Limit <sup>Android Secific<sup>
88+
89+
Setting up the limit of the tabs, which should be pre-loaded on the left and right sides in Android.
90+
```XML
91+
<TabView id="tabViewContainer" androidOffscreenTabLimit="0">
92+
<TabViewItem title="NativeScript">
93+
<StackLayout>
94+
<Label text="NativeScript" class="m-15 h2 text-left" color="blue" />
95+
<ScrollView>
96+
<StackLayout height="100%">
97+
{% raw %}
98+
<Label text="{{content}}" textWrap="true" class="m-15" />
99+
{% endraw %}
100+
</StackLayout>
101+
</ScrollView>
102+
</StackLayout>
103+
</TabViewItem>
104+
<TabViewItem title="Icon">
105+
<StackLayout>
106+
<Image class="m-t-30 m-b-15" src="res://icon" width="80" height="80" />
107+
<Label text="NativeScript" textWrap="true" class="h2 m-x-auto" color="blue" />
108+
</StackLayout>
109+
</TabViewItem>
110+
</TabView>
111+
```
112+
113+
---
114+
115+
## Tabs Position <sup>Android Secific<sup>
116+
117+
Setting up the bottom Tabs position for Android.
118+
```XML
119+
<TabView id="tabViewContainer" androidTabsPosition="bottom">
120+
<TabViewItem title="NativeScript">
121+
<StackLayout>
122+
<Label text="NativeScript" class="m-15 h2 text-left" color="blue" />
123+
<ScrollView>
124+
<StackLayout height="100%">
125+
{% raw %}
126+
<Label text="{{content}}" textWrap="true" class="m-15" />
127+
{% endraw %}
128+
</StackLayout>
129+
</ScrollView>
130+
</StackLayout>
131+
</TabViewItem>
132+
<TabViewItem title="Icon">
133+
<StackLayout>
134+
<Image class="m-t-30 m-b-15" src="res://icon" width="80" height="80" />
135+
<Label text="NativeScript" textWrap="true" class="h2 m-x-auto" color="blue" />
136+
</StackLayout>
137+
</TabViewItem>
138+
</TabView>
139+
140+
```

0 commit comments

Comments
 (0)