AndreiMisiukevich / TouchEffect

UI-responsive touch effects for Xamarin.Forms
MIT License
195 stars 33 forks source link

Navigation from Completed event breaks from NavigationPage.TitleView on Android #53

Closed marufbd closed 4 years ago

marufbd commented 4 years ago

This seems something weird and probably a combination of how event in android is handled by Touchview and Xamarin forms Navigation works.

The Completed event breaks when I try to use it for navigation from Navigation page title view. Whereas a button event just works. It gives an Android FrameLayout Object disposed exception.

Attached is a sample project with Navigation. The ItemsPage.xaml has the code:

<NavigationPage.TitleView>
        <BoxView BackgroundColor="DarkGray" WidthRequest="50" touchEffect:TouchEff.NativeAnimation="True">
            <BoxView.Effects>
                <touchEffect:TouchEff Completed="Button_OnClicked"/>
            </BoxView.Effects>
        </BoxView>
        <!--The button below works just fine-->
        <!--<Button Text="Click" Clicked="Button_OnClicked"></Button>-->
    </NavigationPage.TitleView>

And the event handler

private async void Button_OnClicked(object sender, EventArgs e)
{
       await Navigation.PushAsync(new NewItemPage());
}

Everything remaining same the button works but the boxview with touch event does not. Sample project here

AndreiMisiukevich commented 4 years ago

Your event handler is wrong You should use TEffectCompletedHandler

void Button_OnClicked(VisualElement sender, TouchCompletedEventArgs args) 
{
}
marufbd commented 4 years ago

@AndreiMisiukevich that does not resolve the issue. Have you tested. Please note this behavior is only for if the ui element is inside NavigationPage.TitleView. And only if in the event handler I want to navigate away to another page. Both touchEff event handler and touchEff command breaks in that case. Attached updated project App3.zip

AndreiMisiukevich commented 4 years ago

latest version