我正在尝试使用 redux 在 react-native-router-flux 中实现 react-native-drawer。尝试按照此示例进行操作:https : //github.com/aksonov/react-native-router-flux/blob/master/docs/OTHER_INFO.md但仍然出现错误:Element type is invalid: expected a string (for built-in components) but got: object. Check the render method of 'DefaultRenderer'.
在 react-native-router-flux 中实现抽屉的正确方法是什么?
编辑 - 更新:但仍然收到错误“元素类型无效...”
快速说明:如果我执行 Actions.drawer 我会收到错误但是如果我执行 Actions.home 什么都没有发生但是仍然调用操作 REACT_NATIVE_ROUTER_FLUX_RESET
const RouterWithRedux = connect()(Router)
const store = configureStore()
export default class App extends Component {
render() {
return (
<Provider store={store}>
<RouterWithRedux>
<Scene key='root'>
<Scene component={Login} initial={true} key='login' title='Login'/>
<Scene key="drawer" component={NavDrawer} initial={true}>
<Scene component={Home} key='home' title='Home' type='reset'/>
</Scene>
</Scene>
</RouterWithRedux>
</Provider>
)
}
}
然后我在登录中按下一个按钮,它会触发Actions.
导航到。导航抽屉是:
import React, { PropTypes } from 'react'
import Drawer from 'react-native-drawer'
import { Actions, DefaultRenderer } from 'react-native-router-flux'
import NavDrawerPanel from './NavDrawerPanel'
export default class NavDrawer extends Component {
componentDidMount() {
Actions.refresh({key: 'drawer', ref: this.refs.navigation});
}
render() {
const state = this.props.navigationState;
const children = state.children;
return (
<Drawer
ref="navigation"
type="displace"
content={<NavDrawerPanel />}
tapToClose
openDrawerOffset={0.2}
panCloseMask={0.2}
negotiatePan
tweenHandler={(ratio) => ({
main: { opacity: Math.max(0.54, 1 - ratio) },
})}
>
<DefaultRenderer
navigationState={children[0]}
onNavigate={this.props.onNavigate}
/>
</Drawer>
);
}
}
而 NavDrawerPanel 是:
import React from 'react';
import {PropTypes} from "react";
import {
StyleSheet,
Text,
View,
} from "react-native";
import { Actions } from 'react-native-router-flux';
const NavDrawerPanel = (props, context) => {
const drawer = context.drawer;
return (
<View style={styles.container}>
<TouchableHighlight>
<Text>Home</Text>
</TouchableHighlight>
<TouchableHighlight>
<Text>Profile</Text>
</TouchableHighlight>
<TouchableHighlight>
<Text>Friends</Text>
</TouchableHighlight>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 30,
backgroundColor: 'black'
},
})
错误: