0

我正在尝试将堆栈导航与抽屉导航一起使用。基本上我希望抽屉一直只出现在一个场景中。我试图这样做,但没有任何反应。我无法理解我做错了什么。

PS:我是 react-native 的新手。

ConversationListScreen.js

import React, { Component } from 'react';
import {
    View,
    Text,
    Button,
    TouchableNativeFeedback,
    Alert,
} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons';
import styles from './styles';

export default class ConversationListScreen extends Component
{
    static navigationOptions = {
        title: 'Hola',
        headerLeft: (
            <TouchableNativeFeedback onPress={() => Alert.alert('Hi!', 'I am a hamburger.')}>
                <View style={styles.toolBackground}>
                    <Icon name="menu" style={ styles.menuIcon }/>
                </View>
            </TouchableNativeFeedback>
        ),
        headerRight: (
            <TouchableNativeFeedback onPress={() => Alert.alert('Hi!', 'What you want to search?')}>
                <View style={styles.toolBackground}>
                    <Icon name="search" style={ styles.searchIcon }/>
                </View>
            </TouchableNativeFeedback>
        )
    };
    render() {
        return (
            <View>
            </View>
        );
    }
}

抽屉.js

import React, { Component } from 'react';
import {
    View,
    Text,
} from 'react-native';

export default class SideNav extends Component
{
    render() {
        return (
            <View>
                <Text>My first Drawer</Text>
            </View>
        );
    }
}

RouteConfig.js

import { StackNavigator, DrawerNavigator } from 'react-navigation';
import ConversationListScreen from './ConversationListScreen';
import Drawer from './Drawer';
import ChatScreen from './ChatScreen';

export const SideNav = DrawerNavigator({
    Drawer: { screen: Drawer},
});

export const Hola = StackNavigator({
    ConversationList: { screen: ConversationListScreen },
    Drawer: { screen: SideNav },
    Chat: { screen: ChatScreen },
});
4

3 回答 3

1

我有一个类似的问题,我最终做的是使用这个抽屉组件并将它包裹在你想要访问它的组件周围。例如,如果您只想从 ConversationListScreen 访问它,则将其导出为<Drawer><ConversationListScreen></Drawer>

于 2017-10-14T21:08:55.890 回答
0

这是一种解决方法。我们在 HomeScreenNavigator 中有两个屏幕,这是一个 stackNavigator。在 firstScreen 我们有一个到 secondScreen 的链接。在 secondScreen 中,我们有一个名为 ComponentWidthDrawer 的屏幕的drawerNavigator。这个组件有一个打开抽屉的按钮。我测试了它并且它正在工作。

class FirstComponent extends Component{
  render () {
    return (
      <View>
        <TouchableOpacity onPress={() => 
this.props.navigation.navigate("SecondScreen")}>
          <Text>Go to Second Component</Text>
        </TouchableOpacity>
      </View>
    )
  }
}
class ComponentWidthDrawer extends Component{
  render () {
    return (
      <View>
        <TouchableOpacity onPress={() => this.props.navigation.navigate("DrawerOpen")}>
          <Text>Open Menu</Text>
        </TouchableOpacity>
      </View>
    )
  }
}
const SecondComponent = DrawerNavigator({
  Drawer: {
    screen: ComponentWidthDrawer,
    navigationOptions: {
      drawerLabel: 'Videos'
    },
  }
})

const HomeScreenNavigator = StackNavigator(
  {
    FirstScreen : {
      screen: FirstComponent,
      navigationOptions:{
        header: false
      }
    },
    SecondScreen: {
      screen: SecondComponent,
      navigationOptions:{
        header: false
      }
    }
  }
);
于 2017-10-15T06:43:05.767 回答
0

我猜你不能在堆栈导航器中使用抽屉导航器作为场景。您应该在要使用的组件中导入 SideNav 并尝试将其渲染为组件

于 2017-10-15T05:14:41.690 回答