react-native-router-flux中的抽屉菜单没有显示任何内容

时间:2018-01-13 09:09:13

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

我希望在反应原生中使用flux有一个侧面菜单。但是,它没有显示任何内容。

App.js

const App = () => {
    return (
        <Router>
            <Scene key="root">
                <Scene
                    key="LoginScreen"
                    component={LoginScreen}
                    initial
                />
                <Scene
                    key="CodeValidationScreen"
                    component={CodeValidationScreen}
                />

                <Scene
                    key="ProfileScreen"
                    component={ProfileScreen}
                />

                <Scene
                    key="RegisterScreen"
                    component={RegisterScreen}
                />

                <Scene
                    key="CarsListScreen"
                    component={CarsListScreen}
                />

                <Scene
                    key="CarViewScreen"
                    component={CarViewScreen}
                />

                <Scene contentComponent={NavigationDrawer} drawer  key="drawer">
                    <Scene key="main">
                        <Scene
                            key="LogoutScreen"
                            component={LogoutScreen}
                        />
                    </Scene>
                </Scene>
            {/*<Scene key="drawer"  contentComponent={SideMenu} drawerPosition='right'>*/}
                {/*<Scene key="main" >*/}
                    {/*<Scene*/}
                        {/*key="home"*/}
                        {/*component={LoginScreen}*/}
                        {/*title="Home"*/}
                        {/*initial*/}
                    {/*/>*/}
                {/*</Scene>*/}
            {/*</Scene>*/}
            </Scene>

        </Router>
    )
};

index.js:

AppRegistry.registerComponent('sidemenu', () => App);

Drawer.js

export default class NavigationDrawer extends Component {
    constructor(props) {
        super(props);
    };
    render(){
        const state = this.props.navigationState;
        const children = state.children;
        return (
            <Drawer
                ref="navigation"
                open={state.open}
                onOpen={()=>Actions.refresh({key:state.key, open: true})}
                onClose={()=>Actions.refresh({key:state.key, open: false})}
                type="displace"
                content={<SideMenu />}
                tapToClose={true}
                openDrawerOffset={0.2}
                panCloseMask={0.2}
                negotiatePan={true}
                tweenHandler={(ratio) => ({
                    main: { opacity:Math.max(0.54,1-ratio) }
                })}>
                {this.props.children[0]}
                {/*<DefaultRenderer navigationState={children[0]} onNavigate={this.props.onNavigate} />*/}
            </Drawer>
        );
    }
}

SideMenu.js

export default class SideMenu extends Component<{}> {
    constructor(props) {
        super(props);

    };

    render() {
        return (
            <View style={styles.container}>
                <Text>menu items go here</Text>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        flexDirection: 'column',
        justifyContent: 'flex-start',
        alignItems: 'stretch',
        backgroundColor: '#F5FCFF',
        paddingRight: 20,
        paddingLeft: 20,
        paddingBottom: 10,
    },

});

showDrawer函数(当我点击一个按钮时,我希望SideMenu显示。):

_showDrawer  = () => {
    return () => {
            Actions.refresh({key: 'drawer', open: true });
};

这是我的所有代码。我可以在屏幕之间导航,但是,侧面菜单不起作用。我的错是什么?

2 个答案:

答案 0 :(得分:3)

   <Router>
        <Scene>
            <Scene
                key="login"
                component={LoginScreen}
                initial
                type="reset"
            />
            <Scene
                key="registerScreen"
                component={RegisterScreen}
            />

            <Scene
                key="codeValidationScreen"
                component={CodeValidationScreen}
            />

            <Drawer
                hideNavBar
                key="drawerMenu"
                contentComponent={SideMenu}
                drawerWidth={250}
                drawerPosition="right"
            >
                <Scene
                    key="profileScreen"
                    component={ProfileScreen}

                />
                <Scene
                    key="carsListScreen"
                    component={CarsListScreen}
                />

                <Scene
                    key="carViewScreen"
                    component={CarViewScreen}
                />

            </Drawer>
        </Scene>

    </Router>);

Actions.drawerMenu(params)

并且没有必要使用Drawer.js

答案 1 :(得分:0)

确保所有“场景和堆栈”都位于“抽屉”下,您想在其中查看抽屉菜单。