maui icon indicating copy to clipboard operation
maui copied to clipboard

Gestures don't work on Label Spans

Open davidortinau opened this issue 3 years ago • 43 comments

Description

I added a gesture to a label span and tapped it. Nothing is happening on Windows. Cannot test Android bc it doesn't render the span.

Steps to Reproduce

Run this:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="ControlGallery.Pages.LabelPage"
             Shell.FlyoutBehavior="Disabled"
             >

    <ContentPage.Content>
        <ScrollView>
            <StackLayout Padding="{OnPlatform iOS='30,60,30,30', Default='30'}">

                <Label LineBreakMode="NoWrap" LineHeight="1.4">
                    <Label.FormattedText>
                        <FormattedString>
                            <Span Text="Font name: Default &#10;"/>
                            <Span Text="Version: 1.00  &#10;"/>
                            <Span Text="Digitally Signed, TrueType Outlines &#10;"/>
                            <Span Text="abcdefghijklmnopqrstuvwxyz "/>
                            <Span Text="abcdefghijklmnopqrstuvwxyz &#10;" TextTransform="Uppercase"/>
                            <Span Text="1234567890.:,;'+-*/=  &#10;"/>
                            <Span Text="12 The quick brown fox jumps over the lazy dog. 1234567890 &#10;" FontSize="12"/>
                            <Span Text="18 The quick brown fox jumps over the lazy dog. 1234567890 &#10;" FontSize="18"/>
                            <Span Text="24 The quick brown fox jumps over the lazy dog. 1234567890 &#10;" FontSize="24"/>
                            <Span Text="36 The quick brown fox jumps over the lazy dog. 1234567890 &#10;" FontSize="36"/>
                            <Span Text="48 The quick brown fox jumps over the lazy dog. 1234567890 &#10;" FontSize="48"/>
                            <Span Text="60 The quick brown fox jumps over the lazy dog. 1234567890 &#10;" FontSize="60"/>
                            <Span Text="72 The quick brown fox jumps over the lazy dog. 1234567890 " FontSize="72" >
                                <Span.GestureRecognizers>
                                    <TapGestureRecognizer Command="{Binding TapCommand}" CommandParameter="https://google.com" />
                                </Span.GestureRecognizers>
                            </Span>
                        </FormattedString>
                    </Label.FormattedText>                    
                </Label>
            </StackLayout>
        </ScrollView>

    </ContentPage.Content>
</ContentPage>
using System.Windows.Input;

namespace ControlGallery.Pages;

public partial class LabelPage : ContentPage
{
    public ICommand TapCommand => new Command<string>(async (url) => await Launcher.OpenAsync(url));

    public LabelPage()
    {
        InitializeComponent();
        BindingContext = this;
    }
}

image

Screenshot_1645061133

Version with bug

Preview 13 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows

Affected platform versions

All

Did you find any workaround?

No workaround

Relevant log output

No response

davidortinau avatar Feb 17 '22 01:02 davidortinau

Reproduced on Windows(OS: 19044.1526) and Android(OS: Android 12.0-API31). Repro Project: 4734-Gesture.zip

XamlTest avatar Feb 25 '22 11:02 XamlTest

Confirmed - #6257 is a duplicate of this issue. Added to the 6.0.300 milestone and self-assigned by PureWeen - thanks.

AndreduToit avatar May 01 '22 05:05 AndreduToit

This issue persists. ETA on the fix?

danielftz avatar Aug 19 '22 21:08 danielftz

@PureWeen, @samhouts Did this fall through the cracks? It's listed as being part of 6.0.300-servicing, but no fix made it into even the latest release.

philipag avatar Aug 21 '22 10:08 philipag

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost avatar Aug 23 '22 15:08 ghost

The RecalculateSpan call is never happening on iOS or WinUI

I tried to see if it was a quick easy thing to add https://github.com/dotnet/maui/tree/span_gesture_fixes

But I think the timing needs to be figured out on WinUI so that the Runs sizes are all set and useable.

Also, the call to android to grab the spans doesn't seem to be converting the click point to DP. Maybe the regions get set onto the span in PX?

PureWeen avatar Aug 23 '22 19:08 PureWeen

This same issue applies to the new PointerGestureRecognizer

rachelkang avatar Aug 25 '22 20:08 rachelkang

Is there any fix for this yet? We are migrating an app written in forms and this is a bit of a blocker for us.

ninaada avatar Aug 30 '22 06:08 ninaada

I needed a gesture on a label. I came across this and was tinkering a bit. It's not on a label span but this does appear to be working if you need a temporary workaround.

I'm very new to Maui, this might not be what y'all are looking for but I do hope this helps someone.

Edit: Fixed missing quote on command binding (Thank you @bdcoder2 )

<Label Text="Testing>
    <Label.GestureRecognizers>
        <TapGestureRecognizer Command="{Binding MyDummyCommand}" />
    </Label.GestureRecognizers>
</Label>

TimVanDyke avatar Sep 12 '22 20:09 TimVanDyke

Agreed - this needs to be fixed, posted this on StackOverflow (12-Sep-2022) as well:

https://stackoverflow.com/questions/73695949/net-maui-how-to-include-a-link-in-a-label

@TimVanDyke - Thanks, corrected code (was missing a closing quote on the Text attribute):

<Label Text="Testing">
    <Label.GestureRecognizers>
        <TapGestureRecognizer Command="{Binding MyDummyCommand}" />
    </Label.GestureRecognizers>
</Label>

bdcoder2 avatar Sep 13 '22 01:09 bdcoder2

I'm new to MAUI/Xamarin but having a tappable link in the flow of some text seems like a pretty essential capability. I'm starting an app similar to Twitter and would like to have clickable hashtags in the flow of text.

Is there a workaround, maybe using a label and TextType.Html? Is it possible to capture a tap on an HTML a[href] tag?

ghorsey avatar Oct 20 '22 16:10 ghorsey

I've noticed that if you put a TapGestureRecognizer on the label, the TapGestureRecognizers on the spans also work

<Label ....>
    <Label.FormattedText>
        ... put your spans here with TapGestureRecognizer 
    </Label.FormattedText>
    <Label.GestureRecognizers>
        <TapGestureRecognizer Tapped="LegalLabel_Tapped" />
    </Label.GestureRecognizers>
</Label>

The TapGestureRecognizer on the label doesn't have to do anything, it can be just empty

tom-b-iodigital avatar Oct 25 '22 17:10 tom-b-iodigital

@tom-b-iodigital yup, works like a charm... thanks for sharing!

mtanml avatar Oct 25 '22 17:10 mtanml

@tom-b-iodigital your workaround ONLY works on Android but it doesn't work on iOS or WinUI.

TamerIrdais avatar Nov 04 '22 14:11 TamerIrdais

I'm facing the same issue as @davidortinau posted initially. The workaround does not fix the issue fully on Android.

vhugogarcia avatar Nov 09 '22 20:11 vhugogarcia

I am facing the same issue on iOS and Android

cris-m avatar Nov 11 '22 06:11 cris-m

@PureWeen any update on this?

Looking out migrating an app to maui but it has a lot of embedded links throughout the app, so this is a bit of a stopper atm

IeuanWalker avatar Nov 16 '22 21:11 IeuanWalker

Also blocked, the workaround works in some cases but not in my case.

terraslate avatar Nov 19 '22 12:11 terraslate

Why was this not included in the update days ago?

angelru avatar Dec 18 '22 12:12 angelru

Almost a year now and this is still an open issue? Can we developers help you speed up the process to get this fixed?

bryancass avatar Jan 17 '23 01:01 bryancass

¿Casi un año y esto sigue siendo un tema abierto? ¿Podemos los desarrolladores ayudar a acelerar el proceso para solucionar esto?

supposedly it's fixed: https://github.com/dotnet/maui/pull/12027

angelru avatar Jan 17 '23 06:01 angelru

Yes thank you, I saw the pull request, but I believe it's still being worked on. I can help test the changes, but I am not sure how to do that in github.

bryancass avatar Jan 17 '23 14:01 bryancass

When will this be fixed? We have been waiting for ages for this fix

ninaada avatar Apr 18 '23 10:04 ninaada

The original fix for this was being done in #12027, but the PR was getting large and making it difficult to test/review/merge. So it's being broken up into individual fixes for each platform. We'll try to list those here so folks can track the progress.

The first one is for Android: #14410

hartez avatar Apr 19 '23 16:04 hartez

Keeping this open for the iOS PR to complete: https://github.com/dotnet/maui/pull/15544

jfversluis avatar Jun 27 '23 12:06 jfversluis

This is still broken in Windows, and I don't see a corresponding open PR @jfversluis

daltzctr avatar Jul 06 '23 19:07 daltzctr

Any update on this for Windows? I just want to know if this is going to make it into .NET GA 8 for Windows?

daltzctr avatar Sep 05 '23 20:09 daltzctr

I'm kind of disappointed that an issue that has

  • been open for over a year
  • has one of the most comments and upvotes of any issue
  • numerous complaints and duplicate issues

And somehow only made it to GA Servicing.

The triaging of issues has been better, this issue should have been better prioritized.

daltzctr avatar Oct 01 '23 15:10 daltzctr

Perhaps someone wrote this already, but I didn’t see it. You can solve this problem if you just use a label. Tested only for Android, there is no way to check for iOS, maybe someone can write down how it will work for iOS Example:

<Label Text="Forgot password"
    Style="{StaticResource MessageText}">
    <Label.GestureRecognizers>
        <TapGestureRecognizer Command="{Binding GoToForgotPasswordPageCommand}"/>
    </Label.GestureRecognizers>
</Label>

Or this way if you used several spans:

<HorizontalStackLayout HorizontalOptions="Center">
    <Label Text="Don't have an account? " HorizontalTextAlignment="End" Style="{StaticResource MessageText}"></Label>
    <Label Text="Sign Up" HorizontalTextAlignment="End" Style="{StaticResource MessageTextGreen}">
        <Label.GestureRecognizers>
            <TapGestureRecognizer Command="{Binding GoToSignUpPageCommand}"/>
        </Label.GestureRecognizers>
    </Label>
</HorizontalStackLayout>

Octopon avatar Oct 01 '23 20:10 Octopon

@Octopon sometimes there might be a need for the hyperlinks within the text. So doing the typography or calculating the hit-boxes manually seems like a lot of work. Especially given that the feature used to work perfectly for x.Forms. p.s. also suffering from this one

dodikk avatar Oct 19 '23 18:10 dodikk