无法从react-native-tab-view调用操作

时间:2018-06-13 16:36:37

标签: react-native react-navigation react-native-tab-view

我正在使用来自标头的react-native-tab-view和react-navigation。 在我的名为Principal的组件中,我尝试连接AppActions.js中的一个操作,但是提升了" undefined"那个动作。

请帮助:

Principal组件:(我试图在HeaderButtons.Item的onPress中调用Action enableContactInclusion()

import * as React from 'react';
import { Dimensions } from 'react-native';
import { TabViewAnimated, SceneMap } from 'react-native-tab-view';
import { connect } from 'react-redux';
import { enableContactInclusion } from '../actions/AppActions';

//For the React_Navigation Header
import HeaderButtons from 'react-navigation-header-buttons';
import Ionicons from 'react-native-vector-icons/Ionicons';
import NavigatorService from '../services/navigator';

import TabBarMenu from './TabBarMenu';
import Conversas from './Conversas';
import Contatos from './Contatos';

const initialLayout = {
  height: 0,
  width: Dimensions.get('window').width,
};

class Principal extends React.Component {

    //For React Navigation
    static navigationOptions = {
            title: 'Example App',
            headerBackTitle: null,
            headerRight: (
                <HeaderButtons IconComponent={Ionicons} OverflowIcon={<Ionicons name="ios-more" size={23} color="white" />} iconSize={23} color="white">
                    <HeaderButtons.Item title="add" iconName="md-person-add" onPress={() => { this.props.enableContactInclusion(); NavigatorService.navigate('AdicionarContato'); }} />
                    <HeaderButtons.Item title="Sair" iconName="md-exit" onPress={() => alert('Sair!')} />
                </HeaderButtons>
            )
    }

    state = {
        index: 0,
        routes: [
        { key: 'first', title: 'Conversas' },
        { key: 'second', title: 'Contatos' },
        ],
    };

    _handleIndexChange = index => this.setState({ index });

    _renderHeader = props => <TabBarMenu {...props} />;

    _renderScene = SceneMap({
        first: Conversas,
        second: Contatos,
    });

    static newMethod() {
        return this;
    }

    render() {
        return (
            <TabViewAnimated
                navigationState={this.state}
                renderScene={this._renderScene}
                renderHeader={this._renderHeader}
                onIndexChange={this._handleIndexChange}
                initialLayout={initialLayout}
            />
        );
    }
}
//
export default connect(null, { enableContactInclusion })(Principal);

而且,我的AppActions.js :(我的行动在哪里)

import firebase from 'firebase';
import b64 from 'base-64';
import _ from 'lodash';

//import NavigatorService from '../services/navigator';
import constants from '../constants';

const types = constants.actions;


export const enableContactInclusion = () => {
    return { 
        type: types.ADICIONA_CONTATO_SUCESSO,
        payload: false 
    };
};

谢谢!

0 个答案:

没有答案