Skip to content

Commit d7a35d9

Browse files
committed
Merge pull request ptomasroos#167 from Instrument/overlayTabBar
Adds tabBarPosition 'overlayTop', 'overlayBottom' with docs, example
2 parents 65c7c4d + ad7c6f9 commit d7a35d9

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

DefaultTabBar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ var DefaultTabBar = React.createClass({
7171
});
7272

7373
return (
74-
<View style={[styles.tabs, {backgroundColor : this.props.backgroundColor || null}]}>
74+
<View style={[styles.tabs, {backgroundColor : this.props.backgroundColor || null}, this.props.style, ]}>
7575
{this.props.tabs.map((tab, i) => this.renderTabOption(tab, i))}
7676
<Animated.View style={[tabUnderlineStyle, {left}]} />
7777
</View>

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
## react-native-scrollable-tab-view
23

34
This is probably my favorite navigation pattern on Android, I wish it
@@ -69,7 +70,9 @@ See
6970
the tab bar. The component has `goToPage`, `tabs`, `activeTab` and
7071
`ref` added to the props, and should implement `setAnimationValue` to
7172
be able to animate itself along with the tab content.
72-
- **`tabBarPosition`** _(String)_ - if `"top"`, the tab bar will render above the tabs. If `"bottom"`, the tab bar will render below the tabs. Defaults to `"top"`.
73+
- **`tabBarPosition`** _(String)_ Defaults to `"top"`.
74+
- `"bottom"` to position the tab bar below content.
75+
- `"overlayTop"` or `"overlayBottom"` for a semitransparent tab bar that overlays content. Custom tab bars must consume a style prop on their outer element to support this feature: `style={this.props.style}`.
7376
- **`onChangeTab`** _(Function)_ - function to call when tab changes, should accept 1 argument which is an Object containing two keys: `i`: the index of the tab that is selected, `ref`: the ref of the tab that is selected
7477
- **`onScroll`** _(Function)_ - function to call when the pages are sliding, should accept 1 argument which is an Float number representing the page position in the slide frame.
7578
- **`locked`** _(Bool)_ - disables horizontal dragging to scroll between tabs, default is false.

examples/FacebookTabsExample/FacebookTabBar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ var FacebookTabBar = React.createClass({
9999

100100
return (
101101
<View>
102-
<View style={styles.tabs}>
102+
<View style={[styles.tabs, this.props.style, ]}>
103103
{this.props.tabs.map((tab, i) => this.renderTabOption(tab, i))}
104104
</View>
105105
<Animated.View style={[tabUnderlineStyle, {left}]} />

examples/FacebookTabsExample/FacebookTabsExample.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ var {
99
} = React;
1010

1111
var FacebookTabBar = require('./FacebookTabBar');
12+
var DefaultTabBar = require('react-native-scrollable-tab-view/DefaultTabBar');
13+
const Icon = require('react-native-vector-icons/Ionicons');
1214

1315
var ScrollableTabView = require('react-native-scrollable-tab-view');
1416
var {
@@ -81,9 +83,35 @@ var ScrollableTabsExample = React.createClass({
8183
}
8284
});
8385

86+
// Using tabBarPosition='overlayTop' or 'overlayBottom' lets the content show through a
87+
// semitransparent tab bar. Note that if you build a custom tab bar component, its outer container
88+
// must consume a 'style' prop (e.g. <View style={this.props.style}) to support this feature.
89+
var OverlayExample = React.createClass({
90+
render() {
91+
return (
92+
<ScrollableTabView
93+
style={styles.container}
94+
renderTabBar={()=><DefaultTabBar backgroundColor='rgba(255, 255, 255, 0.5)' />}
95+
tabBarPosition='overlayTop'
96+
>
97+
<View tabLabel='Music' style={{flex:1, backgroundColor: '#CCFFFF'}}>
98+
<Icon name='android-volume-up' color='#2222CC' size={300} style={styles.icon} />
99+
</View>
100+
<View tabLabel='Food' style={{flex:1, backgroundColor: '#CCBBDD'}}>
101+
<Icon name='ios-nutrition' color='#22AACC' size={300} style={styles.icon} />
102+
</View>
103+
<View tabLabel='Drink' style={{flex:1, backgroundColor: '#EEFF33'}}>
104+
<Icon name='ios-pint' color='#22FFCC' size={300} style={styles.icon} />
105+
</View>
106+
</ScrollableTabView>
107+
)
108+
}
109+
});
110+
111+
module.exports = FacebookTabsExample;
84112
//module.exports = SimpleExample;
85113
//module.exports = ScrollableTabsExample;
86-
module.exports = FacebookTabsExample;
114+
//module.exports = OverlayExample;
87115

88116
var styles = StyleSheet.create({
89117
container: {
@@ -107,4 +135,9 @@ var styles = StyleSheet.create({
107135
shadowOpacity: 0.5,
108136
shadowRadius: 3,
109137
},
138+
icon: {
139+
width: 300,
140+
height: 300,
141+
alignSelf: 'center',
142+
}
110143
});

index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const ScrollableTabView = React.createClass({
2121
},
2222

2323
propTypes: {
24-
tabBarPosition: PropTypes.oneOf(['top', 'bottom', ]),
24+
tabBarPosition: PropTypes.oneOf(['top', 'bottom', 'overlayTop', 'overlayBottom', ]),
2525
initialPage: PropTypes.number,
2626
page: PropTypes.number,
2727
onChangeTab: PropTypes.func,
@@ -172,6 +172,7 @@ const ScrollableTabView = React.createClass({
172172
},
173173

174174
render() {
175+
let overlayTabs = (this.props.tabBarPosition === 'overlayTop' || this.props.tabBarPosition === 'overlayBottom');
175176
let tabBarProps = {
176177
goToPage: this.goToPage,
177178
tabs: this._children().map((child) => child.props.tabLabel),
@@ -192,12 +193,20 @@ const ScrollableTabView = React.createClass({
192193
if (this.props.tabBarInactiveTextColor) {
193194
tabBarProps.inactiveTextColor = this.props.tabBarInactiveTextColor;
194195
}
196+
if (overlayTabs) {
197+
tabBarProps.style = {
198+
position: 'absolute',
199+
left: 0,
200+
right: 0,
201+
[this.props.tabBarPosition === 'overlayTop' ? 'top' : 'bottom']: 0
202+
};
203+
}
195204

196205
return (
197206
<View style={[styles.container, this.props.style, ]} onLayout={this._handleLayout}>
198-
{this.props.tabBarPosition === 'top' ? this.renderTabBar(tabBarProps) : null}
207+
{this.props.tabBarPosition === 'top' && this.renderTabBar(tabBarProps)}
199208
{this.renderScrollableContent()}
200-
{this.props.tabBarPosition === 'bottom' ? this.renderTabBar(tabBarProps) : null}
209+
{(this.props.tabBarPosition === 'bottom' || overlayTabs) && this.renderTabBar(tabBarProps)}
201210
</View>
202211
);
203212
},

0 commit comments

Comments
 (0)