2015-03-06 00:36:41 +00:00
|
|
|
/**
|
2015-03-23 20:35:08 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* 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. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2015-03-06 00:36:41 +00:00
|
|
|
*
|
|
|
|
* @providesModule TabBarItemIOS
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var Image = require('Image');
|
|
|
|
var React = require('React');
|
|
|
|
var StaticContainer = require('StaticContainer.react');
|
|
|
|
var StyleSheet = require('StyleSheet');
|
|
|
|
var View = require('View');
|
|
|
|
|
2015-04-22 04:07:17 +00:00
|
|
|
var requireNativeComponent = require('requireNativeComponent');
|
2015-03-06 00:36:41 +00:00
|
|
|
|
|
|
|
var TabBarItemIOS = React.createClass({
|
|
|
|
propTypes: {
|
2015-04-02 20:35:03 +00:00
|
|
|
/**
|
|
|
|
* Little red bubble that sits at the top right of the icon.
|
|
|
|
*/
|
|
|
|
badge: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.string,
|
|
|
|
React.PropTypes.number,
|
|
|
|
]),
|
|
|
|
/**
|
|
|
|
* Items comes with a few predefined system icons. Note that if you are
|
|
|
|
* using them, the title and selectedIcon will be overriden with the
|
|
|
|
* system ones.
|
|
|
|
*/
|
|
|
|
systemIcon: React.PropTypes.oneOf([
|
|
|
|
'bookmarks',
|
|
|
|
'contacts',
|
|
|
|
'downloads',
|
|
|
|
'favorites',
|
|
|
|
'featured',
|
|
|
|
'history',
|
|
|
|
'more',
|
|
|
|
'most-recent',
|
|
|
|
'most-viewed',
|
|
|
|
'recents',
|
|
|
|
'search',
|
|
|
|
'top-rated',
|
|
|
|
]),
|
|
|
|
/**
|
|
|
|
* A custom icon for the tab. It is ignored when a system icon is defined.
|
|
|
|
*/
|
|
|
|
icon: Image.propTypes.source,
|
|
|
|
/**
|
|
|
|
* A custom icon when the tab is selected. It is ignored when a system
|
|
|
|
* icon is defined. If left empty, the icon will be tinted in blue.
|
|
|
|
*/
|
|
|
|
selectedIcon: Image.propTypes.source,
|
|
|
|
/**
|
|
|
|
* Callback when this tab is being selected, you should change the state of your
|
|
|
|
* component to set selected={true}.
|
|
|
|
*/
|
|
|
|
onPress: React.PropTypes.func,
|
|
|
|
/**
|
|
|
|
* It specifies whether the children are visible or not. If you see a
|
|
|
|
* blank content, you probably forgot to add a selected one.
|
|
|
|
*/
|
|
|
|
selected: React.PropTypes.bool,
|
2015-04-26 09:22:34 +00:00
|
|
|
/**
|
|
|
|
* React style object.
|
|
|
|
*/
|
2015-03-09 16:29:05 +00:00
|
|
|
style: View.propTypes.style,
|
2015-04-02 20:35:03 +00:00
|
|
|
/**
|
|
|
|
* Text that appears under the icon. It is ignored when a system icon
|
|
|
|
* is defined.
|
|
|
|
*/
|
|
|
|
title: React.PropTypes.string,
|
2015-03-06 00:36:41 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
hasBeenSelected: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount: function() {
|
|
|
|
if (this.props.selected) {
|
|
|
|
this.setState({hasBeenSelected: true});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-04-27 22:18:37 +00:00
|
|
|
componentWillReceiveProps: function(nextProps: { selected?: boolean }) {
|
2015-03-06 00:36:41 +00:00
|
|
|
if (this.state.hasBeenSelected || nextProps.selected) {
|
|
|
|
this.setState({hasBeenSelected: true});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var tabContents = null;
|
|
|
|
// if the tab has already been shown once, always continue to show it so we
|
|
|
|
// preserve state between tab transitions
|
|
|
|
if (this.state.hasBeenSelected) {
|
|
|
|
tabContents =
|
|
|
|
<StaticContainer shouldUpdate={this.props.selected}>
|
|
|
|
{this.props.children}
|
|
|
|
</StaticContainer>;
|
|
|
|
} else {
|
|
|
|
tabContents = <View />;
|
|
|
|
}
|
|
|
|
|
2015-04-02 20:35:03 +00:00
|
|
|
var badge = typeof this.props.badge === 'number' ?
|
|
|
|
'' + this.props.badge :
|
|
|
|
this.props.badge;
|
|
|
|
|
2015-03-06 00:36:41 +00:00
|
|
|
return (
|
2015-03-17 10:08:46 +00:00
|
|
|
<RCTTabBarItem
|
2015-08-25 12:55:20 +00:00
|
|
|
{...this.props}
|
|
|
|
icon={this.props.systemIcon || this.props.icon}
|
2015-04-22 04:07:17 +00:00
|
|
|
badge={badge}
|
2015-03-06 00:36:41 +00:00
|
|
|
style={[styles.tab, this.props.style]}>
|
|
|
|
{tabContents}
|
2015-03-17 10:08:46 +00:00
|
|
|
</RCTTabBarItem>
|
2015-03-06 00:36:41 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
tab: {
|
|
|
|
position: 'absolute',
|
2015-04-11 05:17:49 +00:00
|
|
|
top: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
left: 0,
|
2015-03-06 00:36:41 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-22 04:07:17 +00:00
|
|
|
var RCTTabBarItem = requireNativeComponent('RCTTabBarItem', TabBarItemIOS);
|
2015-03-06 00:36:41 +00:00
|
|
|
|
|
|
|
module.exports = TabBarItemIOS;
|