如何使用react-native-router-flux和redux实现侧面菜单

时间:2017-12-08 09:32:30

标签: react-native react-native-router-flux react-native-drawer

我尝试了几乎我在这里找到的解决方案,我发现此链接包含有关使用RNRF抽屉功能和redux的教程:https://github.com/aksonov/react-native-router-flux/blob/master/docs/OTHER_INFO.md 但链接不再起作用,有人可以帮助我吗?

这是我的Router.js

import React from 'react';
import { Scene, Router } from 'react-native-router-flux';
import HomeScreen from './screens/HomeScreen';
import LandingScreen from './screens/LandingScreen';
import ProfileScreen from './screens/ProfileScreen';
import EmailLoginScreen from './screens/EmailLoginScreen';
import FacebookLoginScreen from './screens/FacebookLoginScreen';
import SideMenu from './screens/SideMenu';

const RouterComponent = () => {
  return (
    <Router>
    <Scene overlay>
     <Scene key="lightbox" lightbox leftButtonTextStyle={{ color: 'green' }} backButtonTextStyle={{ color: 'red' }} initial>
      <Scene key="root">
        <Scene key='landing' component={LandingScreen} hideNavBar={true} initial  />
        <Scene key='fbLogin' component={FacebookLoginScreen} hideNavBar={true}  />
        <Scene key='emailLogin' component={EmailLoginScreen} title="Email Login"  />

        <Scene key='drawer' drawer contentComponent={SideMenu} title="Menu" >
          <Scene key='home' component={HomeScreen}   />
          <Scene key='profile' component={ProfileScreen} title="My Profile"  />
        </Scene>

      </Scene>
    </Scene>
    </Scene>
    </Router>
  );
};


export default RouterComponent;

这是我的SideMenu.js:

import React, { Component, PropTypes } from 'react';
import { StyleSheet, Text, View, ViewPropTypes } from 'react-native';
import { connect } from 'react-redux';
import { Actions } from 'react-native-router-flux';
import Button from 'react-native-button';
import { CardSection } from '../components/CardSection';

const contextTypes = {
  drawer: React.PropTypes.object,
};

const propTypes = {
  name: PropTypes.string,
  sceneStyle: ViewPropTypes.style,
  title: PropTypes.string,
};

const styles = StyleSheet.create({
  viewContainer: {
    flex: 1,
    backgroundColor: '#fff'
  },
  container: {
    padding: 15,
    height: 45,
    overflow: 'hidden',
    alignSelf: 'flex-start',
  },
  textStyle: {
    fontSize: 18,
    color: '#555',
  },
  nameContainer: {
    padding: 15,
    height: 45,
    overflow: 'hidden',
    alignSelf: 'flex-start',
  },
  name: {
    fontSize: 22,
    color: '#555',
    fontWeight: '400',
  }
});

class SideMenu extends Component {
  render() {
    return (
      <View style={[styles.viewContainer, this.props.sceneStyle]}>

      <CardSection style={{ flexDirection: 'column', padding: 30 }}>
        <Button
          containerStyle={styles.container}
          style={styles.name}
          onPress={() => { Actions.home(); }}
        >Home</Button>
      </CardSection>

        <CardSection style={{ flexDirection: 'column', padding: 30 }}>
          <Button
            containerStyle={styles.container}
            style={styles.name}
            onPress={() => { Actions.profile(); }}
          >Profile</Button>
        </CardSection>
      </View>
    );
  }
}

SideMenu.contextTypes = contextTypes;
SideMenu.propTypes = propTypes;

export default SideMenu;

错误: Debugger error

0 个答案:

没有答案