react-native-material-ui icon indicating copy to clipboard operation
react-native-material-ui copied to clipboard

How to toggle Drawer via Toolbar menu?

Open Kison opened this issue 6 years ago • 12 comments

Hi and thanks for great components. Could someone please explain on how to toggle Drawer state via Toolbar menu?

Kison avatar Mar 20 '18 12:03 Kison

I also need this. Would be great if the demo or the docs explained this :)

mezod avatar Apr 03 '18 14:04 mezod

I think your problem is about navigation, not react-native-material-ui.

A week ago, I just submitted my RN Starter on github

https://github.com/sunaryohadi/react-native-material-ui-starter

Not a fully react-native-material-ui demo though, but I hope this will help you.

sunaryohadi avatar Apr 04 '18 09:04 sunaryohadi

the problem for me is that I include <Drawer> directly into my component and nothing gets rendered, so the problem isn't even how I toggle it or in which route I put it, it simply doesn't render on iOS

mezod avatar Apr 04 '18 14:04 mezod

screen shot 2018-04-04 at 21 59 59

I am not so sure with @mezod problem. It just work fine for me. (just added Drawer tag example to my starter above)

sunaryohadi avatar Apr 04 '18 15:04 sunaryohadi

no worries, I checked your example, just to be sure I'm not doing anything wrong, all I do is:

import React from "react";
// import {} from "./styles";
import Icon from "react-native-ionicons";
import { variables } from "everydaycheckmobile/styles/variables";
import { Drawer, Avatar } from "react-native-material-ui";
import { View } from "react-native";

export default class Menu extends React.Component {
  render() {
    return (
      <View>
        <Drawer>
          <Drawer.Header>
            <Drawer.Header.Account
              avatar={<Avatar text="A" />}
              accounts={[
                { avatar: <Avatar text="B" /> },
                { avatar: <Avatar text="C" /> }
              ]}
              footer={{
                dense: true,
                centerElement: {
                  primaryText: "Reservio",
                  secondaryText: "[email protected]"
                },
                rightElement: "arrow-drop-down"
              }}
            />
          </Drawer.Header>
          <Drawer.Section
            divider
            items={[
              { icon: "bookmark-border", value: "Notifications" },
              { icon: "today", value: "Calendar", active: true },
              { icon: "people", value: "Clients" }
            ]}
          />
          <Drawer.Section
            title="Personal"
            items={[
              { icon: "info", value: "Info" },
              { icon: "settings", value: "Settings" }
            ]}
          />
        </Drawer>
      </View>
    );
  }
}

and then add it to the render of my screen:

render() {
    const { habits, habitsDates, user } = this.props;
    return (
      <MainScreen>
        <Menu />
        <MainNav habits={habits} showMenu={this.showMenu} />
        <SubNav user={user} />
      </MainScreen>
    );

(MainNav and SubNav get rendered) Also MainNav includes a MaterialUI Toolbar successfully so the ThemeProvider and the lib itself seem tobe properly imported. It's just the Drawer that doesn't get rendered at all

mezod avatar Apr 04 '18 15:04 mezod

hmm added style={{ flex: 1 }} to the container view and at least it displays something now :_

mezod avatar Apr 04 '18 15:04 mezod

@mezod's advice will get the drawer appear. But it is not clear from docs how to make the drawer toggle in and out. Is it even possible yet?

danielptm avatar Apr 08 '18 19:04 danielptm

@sunaryohadi is the swipe (from left side) supposed to work with the Drawer or this is something you also have to implement yourself?

mezod avatar Apr 09 '18 22:04 mezod

Not mine for sure. I guess, it's react-navigation default behaviour.

sunaryohadi avatar Apr 10 '18 03:04 sunaryohadi

I realized the drawer component works with react navigation. My problem is that the drawer renders okay, but does not slide from the side of the screen. It doesn't actually work as a drawer at all except it is just another screen component for react-navigation.

Anybody know how to fix this?

assetcorp avatar Sep 20 '18 20:09 assetcorp

i think you have to do the animation yourself...

mezod avatar Sep 20 '18 21:09 mezod

I found this lib https://github.com/react-native-community/react-native-side-menu useful on creating the drawer animation

nikoskleidis avatar Nov 08 '19 17:11 nikoskleidis