maui
maui copied to clipboard
Gestures don't work on Label Spans
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 "/>
<Span Text="Version: 1.00 "/>
<Span Text="Digitally Signed, TrueType Outlines "/>
<Span Text="abcdefghijklmnopqrstuvwxyz "/>
<Span Text="abcdefghijklmnopqrstuvwxyz " TextTransform="Uppercase"/>
<Span Text="1234567890.:,;'+-*/= "/>
<Span Text="12 The quick brown fox jumps over the lazy dog. 1234567890 " FontSize="12"/>
<Span Text="18 The quick brown fox jumps over the lazy dog. 1234567890 " FontSize="18"/>
<Span Text="24 The quick brown fox jumps over the lazy dog. 1234567890 " FontSize="24"/>
<Span Text="36 The quick brown fox jumps over the lazy dog. 1234567890 " FontSize="36"/>
<Span Text="48 The quick brown fox jumps over the lazy dog. 1234567890 " FontSize="48"/>
<Span Text="60 The quick brown fox jumps over the lazy dog. 1234567890 " 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;
}
}

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
Reproduced on Windows(OS: 19044.1526) and Android(OS: Android 12.0-API31). Repro Project: 4734-Gesture.zip
Confirmed - #6257 is a duplicate of this issue. Added to the 6.0.300 milestone and self-assigned by PureWeen - thanks.
This issue persists. ETA on the fix?
@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.
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.
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?
This same issue applies to the new PointerGestureRecognizer
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.
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>
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>
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?
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 yup, works like a charm... thanks for sharing!
@tom-b-iodigital your workaround ONLY works on Android but it doesn't work on iOS or WinUI.
I'm facing the same issue as @davidortinau posted initially. The workaround does not fix the issue fully on Android.
I am facing the same issue on iOS and Android
@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
Also blocked, the workaround works in some cases but not in my case.
Why was this not included in the update days ago?
Almost a year now and this is still an open issue? Can we developers help you speed up the process to get this fixed?
¿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
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.
When will this be fixed? We have been waiting for ages for this fix
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
Keeping this open for the iOS PR to complete: https://github.com/dotnet/maui/pull/15544
This is still broken in Windows, and I don't see a corresponding open PR @jfversluis
Any update on this for Windows? I just want to know if this is going to make it into .NET GA 8 for Windows?
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.
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 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