Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

TapGestureRecognizer not following view when using LayoutTo()

$
0
0

I'm using LayoutTo(); to create my own pseudo hamburger menu. Unfortunately, once the view moves, I can no longer tap it again to close it. It's as though the GestureRecognizer is no longer available (or maybe it's hidden behind the drawer that opens).

            <AbsoluteLayout
                RelativeLayout.XConstraint="{ConstraintExpression Type=Constant, Constant=0}"
                RelativeLayout.YConstraint="{ConstraintExpression Type=Constant, Constant=25}"
                WidthRequest="40"
                HeightRequest="40">
                <AbsoluteLayout.GestureRecognizers>
                    <TapGestureRecognizer Tapped="HamburgerMenu_OnTapped" />
                </AbsoluteLayout.GestureRecognizers>
                <BoxView Color="Black"
                         Opacity=".5"
                         AbsoluteLayout.LayoutBounds="0,0,1,1"
                         AbsoluteLayout.LayoutFlags="All" />

                <BoxView Color="White"
                         WidthRequest="3"
                         HeightRequest="25"
                         AbsoluteLayout.LayoutBounds="0.25, 0.5, -1, -1"
                         AbsoluteLayout.LayoutFlags="PositionProportional" />

                <BoxView Color="White"
                         WidthRequest="3" 
                         HeightRequest="25"
                         AbsoluteLayout.LayoutBounds="0.5, 0.5, -1, -1"
                         AbsoluteLayout.LayoutFlags="PositionProportional" />

                <BoxView Color="White"
                         WidthRequest="3"
                         HeightRequest="25"
                         AbsoluteLayout.LayoutBounds="0.75, 0.5, -1, -1"
                         AbsoluteLayout.LayoutFlags="PositionProportional" />
            </AbsoluteLayout>
        private async void HamburgerMenu_OnTapped(object sender, EventArgs e)
        {
            var menu = (AbsoluteLayout)sender;
            var legendBounds = Legend.Bounds;
            var menuBounds = menu.Bounds;

            if (!_menuIsOpen)
            {
                menuBounds.X = menuBounds.X - legendBounds.X;
                legendBounds.X = 0;
                _menuIsOpen = true;
            }
            else
            {
                menuBounds.X = 0;
                legendBounds.X = -220;
                _menuIsOpen = false;
            }

            Legend.LayoutTo(legendBounds, 100, Easing.SinOut);
            await menu.LayoutTo(menuBounds, 100, Easing.SinOut);
        }

I even tried clearing and re-adding the gesture recognizer after the move, but no dice.

            // re-add the tap gesture recognzier cuz, shit.
            menu.GestureRecognizers.Clear();
            var tg = new TapGestureRecognizer();
            tg.Tapped += HamburgerMenu_OnTapped;
            menu.GestureRecognizers.Add(tg);


Viewing all articles
Browse latest Browse all 77050

Trending Articles