mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
new tabview examples (#5628)
* new tabview exmples * tabs limit example * minor code snippet edits
This commit is contained in:
committed by
Svetoslav
parent
9ec2839bde
commit
a316e53d54
@@ -6,22 +6,27 @@ description: "Examples for using TabView"
|
||||
previous_url: /ApiReference/ui/tab-view/HOW-TO
|
||||
---
|
||||
# TabView
|
||||
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.
|
||||
|
||||
> 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.
|
||||
|
||||
> 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).
|
||||
|
||||
The iOS and Android UX guidelines regarding the Tab controls differ greatly. The difference is described in the below points:
|
||||
|
||||
* The iOS tabs have their tab bar, which will be displayed always on the bottom and does not allow swipe gesture for changing tabs.
|
||||
* The Android tabs are on top and will enable the swipe navigation between the tabs.
|
||||
* 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.
|
||||
|
||||
### Declaring the TabView in xml.
|
||||
``` XML
|
||||
<Page>
|
||||
<TabView>
|
||||
<TabView.items>
|
||||
<TabViewItem title="Tab 1">
|
||||
<TabViewItem.view>
|
||||
<Label text="Label in Tab1" />
|
||||
</TabViewItem.view>
|
||||
// ...
|
||||
</TabViewItem>
|
||||
<TabViewItem title="Tab 2">
|
||||
<TabViewItem.view>
|
||||
<Label text="Label in Tab2" />
|
||||
</TabViewItem.view>
|
||||
// ...
|
||||
</TabViewItem>
|
||||
</TabView.items>
|
||||
</TabView>
|
||||
</Page>
|
||||
```
|
||||
@@ -37,11 +42,9 @@ Using a TabView requires the "ui/tab-view" module.
|
||||
{%snippet article-tabview-selectedIndexChanged%}
|
||||
### Using selectedIndexChanged event from xml
|
||||
```XML
|
||||
<Page>
|
||||
<TabView selectedIndexChanged="onSelectedIndexChanged">
|
||||
...
|
||||
</TabView>
|
||||
</Page>
|
||||
<TabView selectedIndexChanged="onSelectedIndexChanged">
|
||||
...
|
||||
</TabView>
|
||||
```
|
||||
```TypeScript
|
||||
export function onSelectedIndexChanged(args) {...}
|
||||
@@ -57,37 +60,81 @@ For the TabView component could be set three different styling properties
|
||||
* `textTransform` (coresponding CSS property `text-transform`) - setting up textTransform individual for every `TabViewItem`. Value options: `capitalize`, `lowercase`, `none`, `uppercase`.
|
||||
|
||||
```XML
|
||||
<TabView selectedTabTextColor="#00FF00" tabBackgroundColor="#FF0000" >
|
||||
<TabView.items>
|
||||
<TabViewItem title="Tab 1" textTransform="lowercase">
|
||||
<TabViewItem.view>
|
||||
<Label text="Label in Tab1" />
|
||||
</TabViewItem.view>
|
||||
</TabViewItem>
|
||||
<TabViewItem title="Tab 2" textTransform="lowercase">
|
||||
<TabViewItem.view>
|
||||
<Label text="Label in Tab2" />
|
||||
</TabViewItem.view>
|
||||
</TabViewItem>
|
||||
</TabView.items>
|
||||
<TabView selectedTabTextColor="#00FF00" tabBackgroundColor="#FF0000">
|
||||
<TabViewItem title="Tab 1" textTransform="lowercase">
|
||||
<Label text="Label in Tab1" />
|
||||
</TabViewItem>
|
||||
<TabViewItem title="Tab 2" textTransform="lowercase">
|
||||
<Label text="Label in Tab2" />
|
||||
</TabViewItem>
|
||||
</TabView>
|
||||
|
||||
```
|
||||
|
||||
* `androidSelectedTabHighlightColor`<sup>android specific property</sup> (coresponding CSS property `android-selected-tab-highlight-color`) - setup underline color of the `Tab`s in Android.
|
||||
|
||||
```XML
|
||||
<TabView androidSelectedTabHighlightColor="red">
|
||||
<TabView.items>
|
||||
<TabViewItem title="Tab 1" >
|
||||
<TabViewItem.view>
|
||||
<Label text="Label in Tab1"/>
|
||||
</TabViewItem.view>
|
||||
</TabViewItem>
|
||||
<TabViewItem title="Tab 2">
|
||||
<TabViewItem.view>
|
||||
<Label text="Label in Tab2" />
|
||||
</TabViewItem.view>
|
||||
</TabViewItem>
|
||||
</TabView.items>
|
||||
</TabView>
|
||||
```
|
||||
<TabViewItem title="Tab 1">
|
||||
<Label text="Label in Tab1" />
|
||||
</TabViewItem>
|
||||
<TabViewItem title="Tab 2">
|
||||
<Label text="Label in Tab2" />
|
||||
</TabViewItem>
|
||||
</TabView>
|
||||
```
|
||||
|
||||
## Tabs Limit <sup>Android Secific<sup>
|
||||
|
||||
Setting up the limit of the tabs, which should be pre-loaded on the left and right sides in Android.
|
||||
```XML
|
||||
<TabView id="tabViewContainer" androidOffscreenTabLimit="0">
|
||||
<TabViewItem title="NativeScript">
|
||||
<StackLayout>
|
||||
<Label text="NativeScript" class="m-15 h2 text-left" color="blue" />
|
||||
<ScrollView>
|
||||
<StackLayout height="100%">
|
||||
{% raw %}
|
||||
<Label text="{{content}}" textWrap="true" class="m-15" />
|
||||
{% endraw %}
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</StackLayout>
|
||||
</TabViewItem>
|
||||
<TabViewItem title="Icon">
|
||||
<StackLayout>
|
||||
<Image class="m-t-30 m-b-15" src="res://icon" width="80" height="80" />
|
||||
<Label text="NativeScript" textWrap="true" class="h2 m-x-auto" color="blue" />
|
||||
</StackLayout>
|
||||
</TabViewItem>
|
||||
</TabView>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Tabs Position <sup>Android Secific<sup>
|
||||
|
||||
Setting up the bottom Tabs position for Android.
|
||||
```XML
|
||||
<TabView id="tabViewContainer" androidTabsPosition="bottom">
|
||||
<TabViewItem title="NativeScript">
|
||||
<StackLayout>
|
||||
<Label text="NativeScript" class="m-15 h2 text-left" color="blue" />
|
||||
<ScrollView>
|
||||
<StackLayout height="100%">
|
||||
{% raw %}
|
||||
<Label text="{{content}}" textWrap="true" class="m-15" />
|
||||
{% endraw %}
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</StackLayout>
|
||||
</TabViewItem>
|
||||
<TabViewItem title="Icon">
|
||||
<StackLayout>
|
||||
<Image class="m-t-30 m-b-15" src="res://icon" width="80" height="80" />
|
||||
<Label text="NativeScript" textWrap="true" class="h2 m-x-auto" color="blue" />
|
||||
</StackLayout>
|
||||
</TabViewItem>
|
||||
</TabView>
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user