反应原生反应导航标题按钮事件
问题描述:
你好我试图绑定我的导航器右键中的功能,反应原生反应导航标题按钮事件
但它会给出错误。
这是我的代码:
import React, { Component } from 'react';
import Icon from 'react-native-vector-icons/FontAwesome';
import Modal from 'react-native-modalbox';
import { StackNavigator } from 'react-navigation';
import {
Text,
View,
Alert,
StyleSheet,
TextInput,
Button,
TouchableHighlight
} from 'react-native';
import NewsTab from './tabs/news-tab';
import CustomTabBar from './tabs/custom-tab-bar';
export default class MainPage extends Component {
constructor(props) {
super(props);
}
alertMe(){
Alert.alert("sss");
}
static navigationOptions = {
title: 'Anasayfa',
headerRight:
(<TouchableHighlight onPress={this.alertMe.bind(this)} >
<Text>asd</Text>
</TouchableHighlight>)
};
render() {
return(
<View>
</View>
);
}
}
而得到错误是这样的:
不确定是不是(评估 'this.alertMe.bind')
当我使用此方法的对象在渲染功能它工作得很好,但在NavigatonOption我无法得到处理它。我能为这个问题做些什么。
答
你应该在你使用这个功能的导航仪
static navigationOptions = ({ navigation }) => {
const { params = {} } = navigation.state;
return {
title: '[ Admin ]',
headerTitleStyle :{color:'#fff'},
headerStyle: {backgroundColor:'#3c3c3c'},
headerRight: <Icon style={{ marginLeft:15,color:'#fff' }} name={'bars'} size={25} onPress={() => params.handleSave()} />
};
};
使用componentwillmount以便它可以代表你在哪里调用函数。
componentDidMount() {
this.props.navigation.setParams({ handleSave: this._saveDetails });
}
,然后你可以,如果你正在使用这个**
你是一个生命的救星写你的逻辑在功能
**无需绑定功能。它将完全奏效。 –