mirror of
https://github.com/status-im/react-native.git
synced 2025-01-17 04:50:59 +00:00
5baffa03fd
- [ReactNative] Use deprecated ix in TabBarExample | Amjad Masad - [ReactNative] Expanded license on obj-c files | Christopher Chedeau - [ReactNative] Expanded license on js files | Christopher Chedeau - [ReactNative] Fix React Devtools integration | Alex Kotliarskyi - [Text] Account for font leading so descenders are not clipped | James Ide - [ReactNative] Expanded license on js packager files | Christopher Chedeau - more UIExplorer flow | Basil Hosmer - [react-packager] Pick up package changes while running | Amjad Masad - Added a graph view and a ReactNative metric that displays current queue and execution time for the JS thread. | Bryce Redd - [ReactNative] Add NativeModules and DeviceEventEmitter to react-native exports | Alex Kotliarskyi
100 lines
2.7 KiB
JavaScript
100 lines
2.7 KiB
JavaScript
/**
|
|
* 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
|
|
*/
|
|
'use strict';
|
|
|
|
var Image = require('Image');
|
|
var React = require('React');
|
|
var ReactIOSViewAttributes = require('ReactIOSViewAttributes');
|
|
var Dimensions = require('Dimensions');
|
|
var StaticContainer = require('StaticContainer.react');
|
|
var StyleSheet = require('StyleSheet');
|
|
var View = require('View');
|
|
|
|
var createReactIOSNativeComponentClass = require('createReactIOSNativeComponentClass');
|
|
var merge = require('merge');
|
|
|
|
var TabBarItemIOS = React.createClass({
|
|
propTypes: {
|
|
icon: Image.propTypes.source.isRequired,
|
|
onPress: React.PropTypes.func.isRequired,
|
|
selected: React.PropTypes.bool.isRequired,
|
|
badgeValue: React.PropTypes.string,
|
|
title: React.PropTypes.string,
|
|
style: View.propTypes.style,
|
|
},
|
|
|
|
getInitialState: function() {
|
|
return {
|
|
hasBeenSelected: false,
|
|
};
|
|
},
|
|
|
|
componentWillMount: function() {
|
|
if (this.props.selected) {
|
|
this.setState({hasBeenSelected: true});
|
|
}
|
|
},
|
|
|
|
componentWillReceiveProps: function(nextProps) {
|
|
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 />;
|
|
}
|
|
|
|
return (
|
|
<RCTTabBarItem
|
|
icon={this.props.icon.uri}
|
|
selectedIcon={this.props.selectedIcon && this.props.selectedIcon.uri}
|
|
onPress={this.props.onPress}
|
|
selected={this.props.selected}
|
|
badgeValue={this.props.badgeValue}
|
|
title={this.props.title}
|
|
style={[styles.tab, this.props.style]}>
|
|
{tabContents}
|
|
</RCTTabBarItem>
|
|
);
|
|
}
|
|
});
|
|
|
|
var styles = StyleSheet.create({
|
|
tab: {
|
|
position: 'absolute',
|
|
width: Dimensions.get('window').width,
|
|
height: Dimensions.get('window').height,
|
|
}
|
|
});
|
|
|
|
var RCTTabBarItem = createReactIOSNativeComponentClass({
|
|
validAttributes: merge(ReactIOSViewAttributes.UIView, {
|
|
title: true,
|
|
icon: true,
|
|
selectedIcon: true,
|
|
selected: true,
|
|
badgeValue: true,
|
|
}),
|
|
uiViewClassName: 'RCTTabBarItem',
|
|
});
|
|
|
|
module.exports = TabBarItemIOS;
|