简体   繁体   English

如何使用redux实现react-native-router-flux中的react-native-drawer?

[英]How to implement react-native-drawer in react-native-router-flux with redux?

I am trying to implement react-native-drawer in react-native-router-flux with redux. 我正在尝试使用redux在react-native-router-flux中实现react-native-drawer。 Tried following this example: https://github.com/aksonov/react-native-router-flux/blob/master/docs/OTHER_INFO.md but still getting an error: Element type is invalid: expected a string (for built-in components) but got: object. Check the render method of 'DefaultRenderer'. 尝试以下示例: 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'. Element type is invalid: expected a string (for built-in components) but got: object. Check the render method of 'DefaultRenderer'.

What the correct way to implement the drawer in react-native-router-flux? 在react-native-router-flux中实现抽屉的正确方法是什么?

EDIT - UPDATE: Yet still getting the error 'Element type is invalid...' 编辑 - 更新:但仍然得到错误'元素类型无效......'

Quick Note: If I do Actions.drawer I get the error but if I do Actions.home nothing happens but the action REACT_NATIVE_ROUTER_FLUX_RESET is still being called 快速注意:如果我做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>
    )
  }
}

Then I press a button in Login and it triggers Actions. 然后我在Login中按下一个按钮,它会触发Actions. to navigate to. 导航到。 The NavDrawer is: 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>
    );
  }
}

And NavDrawerPanel is: 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'
  },
})

Error: 错误:

在此输入图像描述

看到链接...只需在第一个答案中复制并粘贴抽屉组件...尝试此代码并替换为DefaultRenderer:

 <DefaultRenderer navigationState={children[0]} onNavigate={this.props.onNavigate}/>

I think the problem is in your component. 我认为问题出在你的组件中。

Note that you are importing the drawer view like this: 请注意您要导入抽屉视图,如下所示:

import NavDrawerPanel from './NavDrawerPanel'

but if you take a closer look at the NavDrawerPanel file there isn't a default export. 但是如果仔细查看NavDrawerPanel文件,则没有默认导出。 So instead of having 所以没有

const NavDrawerPanel

you should have: 你应该有:

export const NavDrawerPanel

The error is a bit misleading but it's referring to the drawer's view not the drawer's component itself. 错误有点误导,但它指的是抽屉的视图而不是抽屉的组件本身。 Let me know if that does the trick :) 让我知道如果这样做的伎俩:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 react-native-router-flux 不路由 - react-native-router-flux doesnt route react-native-router-flux标签栏实现 - react-native-router-flux tabbar implementation 抽屉上的React-native,react-native-router-flux和&自定义图标不起作用 - React-native, react-native-router-flux && Custom Icon on Drawer NOT working 使用 react-native-router-flux 反应原生网络 - React Native Networking with react-native-router-flux 当使用react-native-router-flux和react-redux时,道具没有被传递到组件中? - Props not being passed into component when using react-native-router-flux with react-redux? react-native-router-flux:组件中的嵌套路由器 - react-native-router-flux: Nested router in components React Native:如何在react-native-router-flux中为整个应用程序和单个场景设置背景颜色? - React Native: How to set background color for the whole app and individual scene in react-native-router-flux? React Native + react-native-router-flux:如何将hideNavBar应用于仅一个 <Scene/> ? - React Native + react-native-router-flux: How to apply hideNavBar to only one <Scene/>? 如何在 react-native-router-flux 的标题中使用 OptionsMenu(来自 react-native-options-menu)? - How to use OptionsMenu (from react-native-options-menu) in react-native-router-flux's header? React Native / Redux和react-native-router-flux:为什么Actions.key在动作创建者内部不起作用? - React Native/Redux and react-native-router-flux: Why doesn't Actions.key work inside an action creator?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM