Swipeable tabs that can be your main navigation, or just a part of your page.
To see this in action, checkout the example project here.
<super-tabs height="100%">
<super-tab [tabRoot]="page1" title="First page"></super-tab>
<super-tab [tabRoot]="page2" title="Second page"></super-tab>
<super-tab [tabRoot]="page3" title="Third page"></super-tab>
</super-tabs>This module combines ion-segment, ion-slides and some magic to give you swipeable tabs. Each tab has it's own ion-nav, which means they each have their own state, controller ...etc.
npm i --save ionic2-super-tabs
import { SuperTabsModule } from 'ionic2-super-tabs';
@NgModule({
...
imports: [
...
SuperTabsModule
],
...
})
(optional) The index of the tab that is selected when the component is initialized. Defaults to 0.
(optional) The NavController of the parent page. This is helpful if you want to push new views to the parent page instead of the child page.
(optional) The color of the toolbar that contains the ion-segment. See colors for more information.
(optional) The color of the ion-segment component. See colors for more information.
(optional) The color of the slider. The slider is the line below the ion-segment that moves according to what tab is selected. See colors for more information. Defaults to primary.
The height of super-tabs component. Set this to 100% to fill the whole page, or any other value.
The root page for this tab
(optional) An object containing the params you would like to pass to this tab's root page
(optional) The title of the tab to display in the ion-segment-button.
(optional) The name of the icon to display in the ion-segment-button. This has to be a valid ion-icon name.
All color inputs takes color names like any other Ionic 2 component. Your color name must be defined in the $colors map in your variables.scss file.
export class MyPage {
page1: any = Page1Page;
page2: any = Page2Page;
page3: any = Page3Page;
}<super-tabs height="100%">
<super-tab [tabRoot]="page1" title="First page"></super-tab>
<super-tab [tabRoot]="page2" title="Second page"></super-tab>
<super-tab [tabRoot]="page3" title="Third page"></super-tab>
</super-tabs><super-tabs height="100%">
<super-tab [tabRoot]="page1" title="First page" icon="home"></super-tab>
<super-tab [tabRoot]="page2" title="Second page" icon="pin"></super-tab>
<super-tab [tabRoot]="page3" title="Third page" icon="heart"></super-tab>
</super-tabs>export class MyPage {
page1: any = Page1Page;
page2: any = Page2Page;
page3: any = Page3Page;
constructor(public navCtrl: NavController){}
}<super-tabs height="100%" selectedTabIndex="1" [rootNavCtrl]="navCtrl" tabsColor="light" toolbarColor="dark" sliderColor="light">
<super-tab [tabRoot]="page1" title="First page" icon="home"></super-tab>
<super-tab [tabRoot]="page2" title="Second page" icon="pin"></super-tab>
<super-tab [tabRoot]="page3" title="Third page" icon="heart"></super-tab>
</super-tabs>The main goal of this project is to provide a swipeable tabs component for Ionic 2 apps. The tabs must look and feel like the native material design tabs. The project has successfully achieved this goal, but there are a few improvements in mind:
- Disallow "over-swiping" at the begining/end of the tabs. Example: if you are on the first tab and you swipe to the right, the page will move and you will see a blank white area. This is default behaviour of the
ion-slidescomponent (Swiper by iDangero.us). - Allow tab swiping. This is useful if you want to have a large number of tabs and there isn't enough room to have all the
ion-segment-buttons to show up at the same time. - Experiment with using Angular 2 animations instead of pure CSS. (might provide better performance)
- Add a
modeoption that will be passed to theion-segment. Currently themodeis set tomdto provide consistent experience over all platforms. Some might want to haveiossegment buttons instead.
Suggestions and/or Pull Requests are welcome!