TabBarItemIOS.ios.js
3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* 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.
*
* @providesModule TabBarItemIOS
* @noflow
*/
'use strict';
var ColorPropType = require('ColorPropType');
var Image = require('Image');
var React = require('React');
const PropTypes = require('prop-types');
var StaticContainer = require('StaticContainer.react');
var StyleSheet = require('StyleSheet');
var View = require('View');
const ViewPropTypes = require('ViewPropTypes');
var requireNativeComponent = require('requireNativeComponent');
class TabBarItemIOS extends React.Component {
static propTypes = {
...ViewPropTypes,
/**
* Little red bubble that sits at the top right of the icon.
*/
badge: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
/**
* Background color for the badge. Available since iOS 10.
*/
badgeColor: ColorPropType,
/**
* Items comes with a few predefined system icons. Note that if you are
* using them, the title and selectedIcon will be overridden with the
* system ones.
*/
systemIcon: 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: PropTypes.func,
/**
* If set to true it renders the image as original,
* it defaults to being displayed as a template
*/
renderAsOriginal: PropTypes.bool,
/**
* It specifies whether the children are visible or not. If you see a
* blank content, you probably forgot to add a selected one.
*/
selected: PropTypes.bool,
/**
* React style object.
*/
style: ViewPropTypes.style,
/**
* Text that appears under the icon. It is ignored when a system icon
* is defined.
*/
title: PropTypes.string,
/**
*(Apple TV only)* When set to true, this view will be focusable
* and navigable using the Apple TV remote.
*
* @platform ios
*/
isTVSelectable: PropTypes.bool,
};
state = {
hasBeenSelected: false,
};
UNSAFE_componentWillMount() {
if (this.props.selected) {
this.setState({hasBeenSelected: true});
}
}
UNSAFE_componentWillReceiveProps(nextProps: { selected?: boolean }) {
if (this.state.hasBeenSelected || nextProps.selected) {
this.setState({hasBeenSelected: true});
}
}
render() {
var {style, children, ...props} = this.props;
// if the tab has already been shown once, always continue to show it so we
// preserve state between tab transitions
if (this.state.hasBeenSelected) {
var tabContents =
<StaticContainer shouldUpdate={this.props.selected}>
{children}
</StaticContainer>;
} else {
var tabContents = <View />;
}
return (
<RCTTabBarItem
{...props}
style={[styles.tab, style]}>
{tabContents}
</RCTTabBarItem>
);
}
}
var styles = StyleSheet.create({
tab: {
position: 'absolute',
top: 0,
right: 0,
bottom: 0,
left: 0,
}
});
var RCTTabBarItem = requireNativeComponent('RCTTabBarItem', TabBarItemIOS);
module.exports = TabBarItemIOS;