我正在尝试向导航栏添加一个右键以推送视图。我想在选项卡类中执行此操作。我正在使用导航示例中的代码,但我无法让右按钮工作。标签页加载正常,但是当我单击右键时,我收到以下消息:
message: undefined is not an object (evaluating 'this.props.navigator.push')"
主 app.js
'use strict';
var React = require('react-native');
var Tabs = require("./Tabs");
var {AppRegistry} = React;
var App = React.createClass({
render: function () {
return (
<Tabs/>
)
}
});
AppRegistry.registerComponent('App', () => App);
这是 tabs.js
'use strict';
var React = require('react-native');
var {
NavigatorIOS,
StyleSheet,
TabBarIOS,
Text,
View
} = React;
var TabBarItemIOS = TabBarIOS.Item;
var Search = require("./Search");
var Invites = require("./Invites");
var EmptyPage = React.createClass({
render: function() {
return (
<View style={styles.emptyPage}>
<Text style={styles.emptyPageText}>
{this.props.text}
</Text>
</View>
);
},
});
var TabBarExample = React.createClass({
statics: {
title: '<TabBarIOS>',
description: 'Tab-based navigation.'
},
getInitialState: function() {
return {
selectedTab: 'redTab',
notifCount: 0,
presses: 0,
};
},
render: function() {
return (
<TabBarIOS
selectedTab={this.state.selectedTab}>
<TabBarItemIOS
name="blueTab"
icon={_ix_DEPRECATED('favorites')}
accessibilityLabel="Blue Tab"
selected={this.state.selectedTab === 'blueTab'}
onPress={() => {
this.setState({
selectedTab: 'blueTab',
});
}}>
<NavigatorIOS
style={styles.natigator}
initialRoute={{
component: Search,
title: Search.title,
}}
/>
</TabBarItemIOS>
<TabBarItemIOS
accessibilityLabel="Red Tab"
name="redTab"
icon={_ix_DEPRECATED('history')}
badgeValue={this.state.notifCount ? String(this.state.notifCount) : null}
selected={this.state.selectedTab === 'redTab'}
onPress={() => {
this.setState({
selectedTab: 'redTab',
notifCount: this.state.notifCount + 1,
});
}}>
<NavigatorIOS
style={styles.natigator}
initialRoute={{
component: Invites,
title: Invites.title,
rightButtonTitle: 'New Invite',
onRightButtonPress: () => {
this.props.navigator.push({
title: "test",
component: EmptyPage,
rightButtonTitle: 'Cancel',
onRightButtonPress: () => {this.props.navigator.pop();}
});}
}}
/>
</TabBarItemIOS>
</TabBarIOS>
);
},
});
var styles = StyleSheet.create({
natigator: {
flex: 1,
},
tabContent: {
flex: 1,
alignItems: 'center',
},
tabText: {
color: 'white',
margin: 50,
},
});
// This is needed because the actual image may not exist as a file and
// is used by the native code to load a system image.
// TODO(nicklockwood): How can this fit our require system?
function _ix_DEPRECATED(imageUri) {
return {
uri: imageUri,
isStatic: true,
};
}
module.exports = TabBarExample;
导航有问题,我不明白如何加载 View 和 NavigationIOS;似乎我只能渲染带有视图的类或带有导航的类,但不能同时渲染两者。
任何帮助表示赞赏。