Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for deprecated Tabs component #3214

Merged
merged 4 commits into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ All properties of type `React.Component` will receive the same properties availa
## Tabs (`<Tabs>` or `<Scene tabs>`)
Can use all `props` listed above in `<Scene>` as `<Tabs>` is syntatic sugar for `<Scene tabs={true}>`.

| Property | Type | Default | Description |
|-----------------|----------|----------|--------------------------------------------|
| `wrap`     | `boolean` | `true` | Wrap each scene with own navbar automatically (if it is not another container). |
| `activeBackgroundColor` | `string` | | Specifies the active background color for the tab in focus |
| `activeTintColor`     | `string` | | Specifies the active tint color for tabbar icons |
| `inactiveBackgroundColor` | `string` | | Specifies the inactive background color for the tabs not in focus |
| `inactiveTintColor`     | `string` | | Specifies the inactive tint color for tabbar icons |
| `labelStyle` | `object` | | Overrides the styles for the tab label |
| `lazy`     | `boolean` | `false` | Won't render/mount the tab scene until the tab is active |
| `tabBarComponent` | `React.Component` | | React component to render custom tab bar |
| `tabBarPosition`     | `string` | | Specifies tabbar position. Defaults to `bottom` on iOS and `top` on Android. |
| `tabBarStyle` | `object` | | Override the tabbar styles |
| `tabStyle` | `object` | | Override the style for an individual tab of the tabbar |
| `showLabel`     | `boolean` | `true` | Boolean to show or not the tabbar icons labels |
| `tabBarOnPress`     | `function` | | Custom tab bar icon press. |
| `backToInitial`     | `boolean` | `false` | Back to initial screen on focused tab if tab icon was tapped. |
| `upperCaseLabel`     | `boolean` | `true` | Whether to make label uppercase, default is true. |
| `indicatorStyle`     | `object` | | Override the style for active tab indicator. |


## LegacyTabs (`<LegacyTabs>` or `<Scene tabs={true} legacy={true}>`)
Can use all `props` listed above in `<Scene>` as `<LegacyTabs>` is syntatic sugar for `<Scene tabs={true} legacy={true}>`.

| Property | Type | Default | Description |
|-----------------|----------|----------|--------------------------------------------|
| `wrap`     | `boolean` | `true` | Wrap each scene with own navbar automatically (if it is not another container). |
Expand Down
9 changes: 9 additions & 0 deletions src/LegacyTabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright (c) 2015-present, Pavel Aksonov
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*
*/
export default () => null;
73 changes: 40 additions & 33 deletions src/navigationStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
StatusBar, Image, Animated, Easing,
} from 'react-native';
import {
createTabNavigator as DEPRECATED_createTabNavigator,
createBottomTabNavigator,
createMaterialTopTabNavigator,
createDrawerNavigator,
Expand All @@ -24,6 +25,7 @@ import Modal from './Modal';
import Lightbox from './Lightbox';
import Drawer from './Drawer';
import Tabs from './Tabs';
import LegacyTabs from './LegacyTabs';
import Overlay from './Overlay';
import OverlayRenderer from './OverlayRenderer';
import createStackNavigatorHOC from './createStackNavigatorHOC';
Expand All @@ -47,60 +49,60 @@ export const actionMap = {
};

const reservedKeys = [
'children',
'refs',
'addRef',
'removeRef',
'back',
'children',
'create',
'execute',
'popTo',
'navigate',
'replace',
'refresh',
'dispatch',
'push',
'setParams',
'run',
'onEnter',
'onRight',
'onLeft',
'drawerClose',
'drawerOpen',
'execute',
'left',
'back',
'right',
'rightButton',
'leftButton',
'navBar',
'navigate',
'on',
'onEnter',
'onExit',
'onLeft',
'onRight',
'pop',
'popTo',
'push',
'refresh',
'refs',
'removeRef',
'renderLeftButton',
'renderRightButton',
'renderTitle',
'navBar',
'replace',
'right',
'rightButton',
'run',
'setParams',
'title',
'drawerOpen',
'drawerClose',
];

const dontInheritKeys = [
'backToInitial',
'children',
'component',
'contentComponent',
'tabBarComponent',
'modal',
'drawer',
'hideNavBar',
'hideTabBar',
'key',
'lightbox',
'overlay',
'tabs',
'modal',
'navigator',
'children',
'key',
'navTransparent',
'overlay',
'ref',
'style',
'tabBarComponent',
'tabs',
'title',
'navTransparent',
'type',
'hideNavBar',
'hideTabBar',
'backToInitial',
];

function getValue(value, params) {
Expand Down Expand Up @@ -590,7 +592,7 @@ class NavigationStore {
navigator, renderer, contentComponent, drawerWidth, drawerLockMode, tabBarComponent, tabBarPosition, lazy, duration, ...parentProps
} = scene.props;
let {
tabs, modal, lightbox, overlay, drawer, transitionConfig,
legacy, tabs, modal, lightbox, overlay, drawer, transitionConfig,
} = parentProps;
if (scene.type === Modal) {
modal = true;
Expand All @@ -600,6 +602,9 @@ class NavigationStore {
lightbox = true;
} else if (scene.type === Tabs) {
tabs = true;
} else if (scene.type === LegacyTabs) {
tabs = true;
legacy = true;
} else if (scene.type === Overlay) {
overlay = true;
}
Expand Down Expand Up @@ -678,7 +683,7 @@ class NavigationStore {
if (path) {
this.states[key].path = path;
}
// console.log(`KEY ${key} PATH ${path} DRAWER ${drawer} TABS ${tabs} WRAP ${wrap}`, JSON.stringify(commonProps));
// console.log(`KEY ${key} LEGACY {legacy} PATH ${path} DRAWER ${drawer} TABS ${tabs} WRAP ${wrap}`, JSON.stringify(commonProps));
const screen = {
screen: createWrapper(component, wrapBy, this) || this.processScene(child, commonProps, clones) || (lightbox && (() => null)),
navigationOptions: createNavigationOptions({
Expand Down Expand Up @@ -778,7 +783,9 @@ class NavigationStore {

if (tabs) {
let createTabNavigator = createMaterialTopTabNavigator;
if (tabBarPosition !== 'top') {
if (legacy) {
createTabNavigator = DEPRECATED_createTabNavigator;
} else if (tabBarPosition !== 'top') {
createTabNavigator = createBottomTabNavigator;
}
return createTabNavigator(res, {
Expand Down