Skip to content

[iOS]Span TapGestureRecognizer does not work on the second line of the span, if the span is wrapped to the next line #34504

@sumchat

Description

@sumchat

Description

I created a fresh .Net 10 maui app . In the main page, I created a label with multiple span tags. I added a TapGestureRecognizer to each of the span. When the app loads ,the main Page is the page that gets shown. All the gestures work fine at this point. But if I navigate to a different page which has the similar code as the previous page, the span gestures stop working when the span is wrapped to the second line. The tapgesture on the first line still works. This behavior is only reproducible in iOS.
Fig 1. (MainPage)
Gestures work fine for all the 3 lines.
Image
Fig2. (TestPage)
Gestures work only on the first line of each label.

Image

Steps to Reproduce

  1. Create a .Net maui app with a MAIN page. Add a BUTTON in the MAIN Page. Add a buttonclick event which should navigate to another Page e.g. TestPage.xaml
  2. Create a ContentPage named TestPage.Xaml . Add a LABEL with multiple SPANs inside FORMATTEDSTRING . Create a long string so that it wraps to a second or third line like below. Now observe that the tapgestures on the second line of the span do not get triggered in iOS

TestPage.xaml

<ScrollView>
    <VerticalStackLayout Padding="30,0" Spacing="25">
        <Border>
            <Label SemanticProperties.HeadingLevel="Level1" Text="Hello, World!">
                <Label.FormattedText>
                    <FormattedString>
                        <FormattedString.Spans>
                            <Span
                                Text="Hello,This is a test. Hello,This is a test. Hello,This is a test."
                                TextColor="Blue"
                                TextDecorations="Underline">
                                <Span.GestureRecognizers>
                                    <TapGestureRecognizer Tapped="OnLabelTapped" />
                                </Span.GestureRecognizers>
                            </Span>
                            <Span
                                Text="Hello,This is a test1. Hello,This is a test1. Hello,This is a test1."
                                TextColor="Red"
                                TextDecorations="Underline">
                                <Span.GestureRecognizers>
                                    <TapGestureRecognizer Tapped="OnLabelTapped" />
                                </Span.GestureRecognizers>
                            </Span>
                            <Span
                                Text="Hello,This is a test2. Hello,This is a test2. Hello,This is a test2."
                                TextColor="Green"
                                TextDecorations="Underline">
                                <Span.GestureRecognizers>
                                    <TapGestureRecognizer Tapped="OnLabelTapped" />
                                </Span.GestureRecognizers>
                            </Span>
                            <Span
                                Text="Hello,This is a test4. Hello,This is a test4. Hello,This is a test4."
                                TextColor="Green"
                                TextDecorations="Underline">
                                <Span.GestureRecognizers>
                                    <TapGestureRecognizer Tapped="OnLabelTapped" />
                                </Span.GestureRecognizers>
                            </Span>
                            <Span
                                Text="Hello,This is a test3. Hello,This is a test3. Hello,This is a test3."
                                TextColor="Green"
                                TextDecorations="Underline">
                                <Span.GestureRecognizers>
                                    <TapGestureRecognizer Tapped="OnLabelTapped" />
                                </Span.GestureRecognizers>
                            </Span>
                            <Span FontAttributes="Bold" Text="World!" />
                        </FormattedString.Spans>
                    </FormattedString>
                </Label.FormattedText>
            </Label>
        </Border>                   
    </VerticalStackLayout>
</ScrollView>

TestPage.Xaml.cs

namespace MauiApp1;

public partial class TestPage : ContentPage
{
public TestPage()
{
InitializeComponent();
}
void OnLabelTapped(object sender, EventArgs e)
{
SemanticScreenReader.Announce("Label was tapped");
}
}

Link to public reproduction project repository

No response

Version with bug

10.0.30

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

9.0.80 SR8

Affected platforms

iOS

Affected platform versions

iOS 26.1 onwards

Did you find any workaround?

No

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    t/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions