我試圖在react-native-router-flux和redux中實現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'.
如何使用redux在react-native-router-flux中實現react-native-drawer?
在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.
瀏覽到。該NavDrawer是:
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'
},
})
錯誤:
您可能忘記導出您的NavDrawPanel。很可能它只是缺少從NavDrawPanel模塊導出的對象。 – Nozim