xamarin / XamarinCommunityToolkit

The Xamarin Community Toolkit is a collection of Animations, Behaviors, Converters, and Effects for mobile development with Xamarin.Forms. It simplifies and demonstrates common developer tasks building iOS, Android, and UWP apps with Xamarin.Forms.
MIT License
1.58k stars 471 forks source link

[Bug] Cannot use Touch effect on a NavigationPage.TitleView #1829

Open eduardoagr opened 2 years ago

eduardoagr commented 2 years ago

Description

I have a

<NavigationPage.TitleView>
        <StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal">

            <ffimageloadingsvg:SvgCachedImage
                community:TouchEffect.Command="{Binding ProfileCommnd}"
                HeightRequest="40"
                Source="{Binding FireUser.PhotoUrl}"
                WidthRequest="40" />

            <Label
                FontAttributes="Bold"
                FontSize="Medium"
                Text="{Binding FireUser.DisplayName}"
                TextColor="{StaticResource BackgroundLigthColor}"
                VerticalOptions="Center">
                <Label.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding ProfileCommnd}" />
                </Label.GestureRecognizers>
            </Label>

            <SearchBar
                x:Name="SearchBar"
                IsVisible="{Binding IsVisible}"
                MaxLength="50"
                WidthRequest="200">
                <SearchBar.Behaviors>
                    <community:EventToCommandBehavior
                        Command="{Binding TextToSearchCommand}"
                        CommandParameter="{Binding Text, Source={x:Reference SearchBar}}"
                        EventName="TextChanged" />
                </SearchBar.Behaviors>
            </SearchBar>

            <Button
                community:TouchEffect.PressedBackgroundColor="{StaticResource PressedItems}"
                BackgroundColor="{StaticResource Trnsparent}"
                Command="{Binding SwitchVisibilityCommand}"
                HorizontalOptions="EndAndExpand"
                VerticalOptions="CenterAndExpand">
                <Button.ImageSource>
                    <FontImageSource FontFamily="ma" Glyph="{Static icon:MaterialIcons.TextBoxSearch}" />
                </Button.ImageSource>
            </Button>
        </StackLayout>
    </NavigationPage.TitleView>

Stack Trace

Link to Reproduction Sample

Steps to Reproduce

  1. Create a xaml page
  2. Put an <NavigationPage.TitleView>
  3. Create <Label> inside of the <NavigationPage.TitleView> `

    Expected Behavior

Be able to touch and execute the command

Actual Behavior

System.NotSupportedException: 'Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer from native handle 0x7ffee5901f14 (key_handle 0x92850c6).'

Basic Information

Workaround

Use a Gesture recognizer -

Reproduction imagery

rokenbuzz commented 2 years ago

I just encountered this issue. My Command will ultimately call INavigation.PushAsync to change pages.

A workaround for me, and perhaps a clue to the issue, was to wrap my Command's functionality in Device.BeginInvokeOnMainThread:

private void MyCommandMethod() { Device.BeginInvokeOnMainThread(() => { // my code }); }

eduardoagr commented 2 years ago

Well if you use a gesture recognizer, it will work