Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Slide back menu when opened #11

Closed
houdayec opened this issue Jul 9, 2020 · 5 comments
Closed

Improvement: Slide back menu when opened #11

houdayec opened this issue Jul 9, 2020 · 5 comments

Comments

@houdayec
Copy link

houdayec commented Jul 9, 2020

Hi. Thanks for your package, really nice job.

However, I would like to know if it is possible to close the drawer when its opened, by swiping or clicking the view on the right.

Thanks in advance

@houdayec
Copy link
Author

houdayec commented Jul 9, 2020

I updated your ZoomDrawer widget and modified the build method to get gestures callbacks on all the stack, not only the menu.

@override
  Widget build(BuildContext context) {
    final slidePercent =
        CHZoomDrawer.isRTL() ? MediaQuery.of(context).size.width * .1 : 15.0;

    return GestureDetector(
      onPanUpdate: (details) {
        print(details);
        if (details.delta.dx < -6 && !_rtl || details.delta.dx < 6 && _rtl) {
          toggle();
        }
      },
      child: Stack(
        children: [
          widget.menuScreen,
          if (widget.showShadow) ...[
            /// Displaying the first shadow
            AnimatedBuilder(
              animation: _animationController,
              builder: (_, w) => _zoomAndSlideContent(w,
                  angle: (widget.angle == 0.0) ? 0.0 : widget.angle - 8,
                  scale: .9,
                  slide: slidePercent * 2),
              child: Container(
                color: widget.backgroundColor.withAlpha(31),
              ),
            ),

@medyas
Copy link
Owner

medyas commented Jul 9, 2020

@houdayec hello, Thanks for your feedback.
Wrapping the hole Stack widget with GestureDetector will probably disable any events going to the bottom widget tree and its not a good thing to do in the plugin side. If you want to capture events to close the widget while it's open, you can add this in your code rather then in the plugin as its supposed to be for general use.
You can check for the DrawerState and update your widget. If the Drawer is not closed then return a GestureDetector with both onTap and onPanUpdate methods and call toggle else return the child(The home screen).

class _MainScreenState extends State<MainScreen> {
  @override
  Widget build(BuildContext context) {
    final rtl = ZoomDrawer.isRTL();
    return ValueListenableBuilder<DrawerState>(
      valueListenable: ZoomDrawer.of(context).stateNotifier,
      builder: (context, state, child) {
        return (state != DrawerState.closed)? GestureDetector(
                child: child,
                onTap: () => ZoomDrawer.of(context).toggle(),
                onPanUpdate: (details) {
                  if (details.delta.dx < 6 && !rtl || details.delta.dx < -6 && rtl) {
                    ZoomDrawer.of(context).toggle();
                  }
                },
              ): child;
      },
      child: PageStructure(),
    );
  }
}

@medyas medyas closed this as completed Jul 17, 2020
@houdayec
Copy link
Author

houdayec commented Jul 20, 2020

Hi!

Thanks for your answer and sorry for the late reply.

I have tried this solution, but I finally encountered a problem: using this value listener forces child rebuild which is very annoying. Do you have the same problem using this solution?

@medyas
Copy link
Owner

medyas commented Jul 21, 2020

The ValueListenableBuilder will call it's builder function each time it get notified of a new drawer state. To minimize you page rebuilds you can provide the child parameter and use it in the builder function, same as the example. This will reduce the page rebuilds. In the example project, the PageStructure will only be built once, and then used from the child parameter.
If your having multiple rebuilds you should check your code for calls of setState.

@houdayec
Copy link
Author

Yes that is what I did, I think I'm having child updates that lead to a widget rebuild. I'm going to investigate deeper. Thanks anyway for the workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants