Dispatch Drawer does not work

Asked

Viewed 71 times

-1

am trying to implement a Drawer in my app. As I want only in one of my screens. While trying to implement, I felt some difficulties. So I did step by step not to get lost.

I created a button and I want to do Drawer open up when he goes clicked, but nothing is returning to me.

Follow the code below:

import React from 'react';
import { View, Button} from 'react-native';
import { createAppContainer, DrawerNavigator } from 'react-navigation';
import { createDrawerNavigator, DrawerActions } from 'react-navigation-drawer';
import TabsNav from './TabsLeadScreen';

const AppNavigator = createDrawerNavigator({
    Contact: {
        screen: TabsNav
    },
    Teste: {
        screen: TabsNav
    }
}, {});

const DrawerCustom = createAppContainer(AppNavigator);

function ShowScreen({ navigation }) {
    return (
        <View>
            <Button title="abrir" onPress={() => navigation.dispatch(DrawerActions.openDrawer())} />
            <DrawerCustom />
        </View>
    );
}

I’m using the

-React-navigation: ^4.0.10

-expo: ~37.0.3

Could someone help me?

Thank you!

  • Iae, use this link as an example. Any questions just comment https://answall.com/a/446384/160305

  • Oops, so I insert a template like yours, but when I give an onclick on the button to open, it keeps happening nothing... Ai insert a console.log to see the return of it, is returning false estou passando esse código navigation.dispatch(DrawerActions.openDrawer())

1 answer

0

If you only want it on a screen, create a button to open Drawer.

const Drawer = createDrawerNavigator({
    Home: {screen: Home,},
  },
  {
    contentComponent: DrawerContent,
    contentOptions: {
      activeTintColor: "#F05B66"
    },
    headerMode: "none",
    initialRouteName: "Home",
    drawerWidth: deviceWidth - 90,

  }
)

_Navigator.Dispatch(Draweractions.openDrawer())

const Logado = createStackNavigator(
  {
    Home: {screen: Home,}, 
    Painel: {screen: Painel,},
    Drawer: {screen: Drawer}
  },
  {
    initialRouteName: "Drawer",
    headerMode: "none",
    lazy: true,
    defaultNavigationOptions: {
      ...TransitionPresets.SlideFromRightIOS,
    },
  }
);
  • So when I try to make the onpress to give the DrawerActions.openDrawer()) it does not return anything, so I inserted a console.log to see what kind of return it is giving, its return is false... What might be?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.