2015-03-06 00:36:41 +00:00
|
|
|
/**
|
2015-03-23 20:35:08 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-03-06 00:36:41 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2015-12-02 03:09:01 +00:00
|
|
|
* @noflow
|
2015-03-06 00:36:41 +00:00
|
|
|
*/
|
2018-05-11 02:06:46 +00:00
|
|
|
|
2015-03-06 00:36:41 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
const ColorPropType = require('ColorPropType');
|
|
|
|
const Image = require('Image');
|
|
|
|
const React = require('React');
|
2017-04-12 23:09:48 +00:00
|
|
|
const PropTypes = require('prop-types');
|
2018-03-03 23:04:46 +00:00
|
|
|
const StaticContainer = require('StaticContainer.react');
|
|
|
|
const StyleSheet = require('StyleSheet');
|
|
|
|
const View = require('View');
|
2015-03-06 00:36:41 +00:00
|
|
|
|
2017-03-24 07:22:57 +00:00
|
|
|
const ViewPropTypes = require('ViewPropTypes');
|
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
const requireNativeComponent = require('requireNativeComponent');
|
2015-03-06 00:36:41 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class TabBarItemIOS extends React.Component {
|
|
|
|
static propTypes = {
|
2017-03-24 07:22:57 +00:00
|
|
|
...ViewPropTypes,
|
2015-04-02 20:35:03 +00:00
|
|
|
/**
|
|
|
|
* Little red bubble that sits at the top right of the icon.
|
|
|
|
*/
|
2018-05-11 02:06:46 +00:00
|
|
|
badge: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
2016-11-29 19:37:47 +00:00
|
|
|
/**
|
|
|
|
* Background color for the badge. Available since iOS 10.
|
|
|
|
*/
|
|
|
|
badgeColor: ColorPropType,
|
2015-04-02 20:35:03 +00:00
|
|
|
/**
|
|
|
|
* Items comes with a few predefined system icons. Note that if you are
|
2015-12-15 17:08:39 +00:00
|
|
|
* using them, the title and selectedIcon will be overridden with the
|
2015-04-02 20:35:03 +00:00
|
|
|
* system ones.
|
|
|
|
*/
|
2017-04-12 23:09:48 +00:00
|
|
|
systemIcon: PropTypes.oneOf([
|
2015-04-02 20:35:03 +00:00
|
|
|
'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.
|
|
|
|
*/
|
2015-12-08 11:29:08 +00:00
|
|
|
icon: Image.propTypes.source,
|
2015-04-02 20:35:03 +00:00
|
|
|
/**
|
|
|
|
* 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}.
|
|
|
|
*/
|
2017-04-12 23:09:48 +00:00
|
|
|
onPress: PropTypes.func,
|
2016-05-03 12:39:21 +00:00
|
|
|
/**
|
|
|
|
* If set to true it renders the image as original,
|
|
|
|
* it defaults to being displayed as a template
|
|
|
|
*/
|
2017-04-12 23:09:48 +00:00
|
|
|
renderAsOriginal: PropTypes.bool,
|
2015-04-02 20:35:03 +00:00
|
|
|
/**
|
|
|
|
* It specifies whether the children are visible or not. If you see a
|
|
|
|
* blank content, you probably forgot to add a selected one.
|
|
|
|
*/
|
2017-04-12 23:09:48 +00:00
|
|
|
selected: PropTypes.bool,
|
2015-04-26 09:22:34 +00:00
|
|
|
/**
|
|
|
|
* React style object.
|
|
|
|
*/
|
2017-03-24 07:22:57 +00:00
|
|
|
style: ViewPropTypes.style,
|
2015-04-02 20:35:03 +00:00
|
|
|
/**
|
|
|
|
* Text that appears under the icon. It is ignored when a system icon
|
|
|
|
* is defined.
|
|
|
|
*/
|
2017-04-12 23:09:48 +00:00
|
|
|
title: PropTypes.string,
|
2016-12-19 14:26:07 +00:00
|
|
|
/**
|
|
|
|
*(Apple TV only)* When set to true, this view will be focusable
|
|
|
|
* and navigable using the Apple TV remote.
|
|
|
|
*
|
|
|
|
* @platform ios
|
|
|
|
*/
|
2017-04-12 23:09:48 +00:00
|
|
|
isTVSelectable: PropTypes.bool,
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-06 00:36:41 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
state = {
|
|
|
|
hasBeenSelected: false,
|
|
|
|
};
|
2015-03-06 00:36:41 +00:00
|
|
|
|
2018-02-08 18:26:45 +00:00
|
|
|
UNSAFE_componentWillMount() {
|
2015-03-06 00:36:41 +00:00
|
|
|
if (this.props.selected) {
|
|
|
|
this.setState({hasBeenSelected: true});
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-03-06 00:36:41 +00:00
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
UNSAFE_componentWillReceiveProps(nextProps: {selected?: boolean}) {
|
2015-03-06 00:36:41 +00:00
|
|
|
if (this.state.hasBeenSelected || nextProps.selected) {
|
|
|
|
this.setState({hasBeenSelected: true});
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-03-06 00:36:41 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2018-03-03 23:04:46 +00:00
|
|
|
const {style, children, ...props} = this.props;
|
2015-12-08 11:29:08 +00:00
|
|
|
|
2015-03-06 00:36:41 +00:00
|
|
|
// if the tab has already been shown once, always continue to show it so we
|
|
|
|
// preserve state between tab transitions
|
|
|
|
if (this.state.hasBeenSelected) {
|
2018-05-11 02:06:46 +00:00
|
|
|
var tabContents = (
|
2015-03-06 00:36:41 +00:00
|
|
|
<StaticContainer shouldUpdate={this.props.selected}>
|
2015-12-08 11:29:08 +00:00
|
|
|
{children}
|
2018-05-11 02:06:46 +00:00
|
|
|
</StaticContainer>
|
|
|
|
);
|
2015-03-06 00:36:41 +00:00
|
|
|
} else {
|
2015-12-08 11:29:08 +00:00
|
|
|
var tabContents = <View />;
|
2015-03-06 00:36:41 +00:00
|
|
|
}
|
2015-12-15 17:08:39 +00:00
|
|
|
|
2015-03-06 00:36:41 +00:00
|
|
|
return (
|
2018-05-11 02:06:46 +00:00
|
|
|
<RCTTabBarItem {...props} style={[styles.tab, style]}>
|
2015-03-06 00:36:41 +00:00
|
|
|
{tabContents}
|
2015-03-17 10:08:46 +00:00
|
|
|
</RCTTabBarItem>
|
2015-03-06 00:36:41 +00:00
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-03-06 00:36:41 +00:00
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
const styles = StyleSheet.create({
|
2015-03-06 00:36:41 +00:00
|
|
|
tab: {
|
|
|
|
position: 'absolute',
|
2015-04-11 05:17:49 +00:00
|
|
|
top: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
left: 0,
|
2018-05-11 02:06:46 +00:00
|
|
|
},
|
2015-03-06 00:36:41 +00:00
|
|
|
});
|
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
const RCTTabBarItem = requireNativeComponent('RCTTabBarItem', TabBarItemIOS);
|
2015-03-06 00:36:41 +00:00
|
|
|
|
|
|
|
module.exports = TabBarItemIOS;
|