Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 0fdeee5

Browse files
authored
[iOS] Fix Gesture issue with SwipeView (#11217) fixes #11209
* Added repro sample * Updated sample * Fixed issue * Added instructions to the sample * Fixed the issue with another approach * Fixed Build error * Added UITest
1 parent f880a05 commit 0fdeee5

File tree

4 files changed

+157
-0
lines changed

4 files changed

+157
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<controls:TestContentPage
3+
xmlns="http://xamarin.com/schemas/2014/forms"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
5+
xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
6+
x:Class="Xamarin.Forms.Controls.Issues.Issue11209"
7+
x:Name="Issue11209Page"
8+
Title="Issue 11209">
9+
<Grid
10+
RowSpacing="0">
11+
<Grid.RowDefinitions>
12+
<RowDefinition Height="Auto" />
13+
<RowDefinition Height="*" />
14+
</Grid.RowDefinitions>
15+
<Label
16+
Padding="12"
17+
BackgroundColor="Black"
18+
TextColor="White"
19+
Text="Tap any item on the list."/>
20+
<CollectionView
21+
Grid.Row="1"
22+
ItemsSource="{Binding Source={x:Reference Issue11209Page}, Path=Items}">
23+
<CollectionView.ItemTemplate>
24+
<DataTemplate>
25+
<SwipeView
26+
HeightRequest="60">
27+
<SwipeView.LeftItems>
28+
<SwipeItems
29+
Mode="Reveal">
30+
<SwipeItem
31+
Text="Item 1"
32+
BackgroundColor="Green"
33+
Invoked="SwipeItem_Invoked"/>
34+
</SwipeItems>
35+
</SwipeView.LeftItems>
36+
<Grid
37+
AutomationId="SwipeViewContent"
38+
BackgroundColor="Yellow">
39+
<Grid.GestureRecognizers>
40+
<TapGestureRecognizer
41+
Tapped="TapGestureRecognizer_Tapped"/>
42+
</Grid.GestureRecognizers>
43+
<Label
44+
HorizontalOptions="Start"
45+
VerticalOptions="Center"
46+
Margin="20"
47+
Text="{Binding .}"/>
48+
<BoxView
49+
HeightRequest="1"
50+
BackgroundColor="Black"
51+
VerticalOptions="End"/>
52+
</Grid>
53+
</SwipeView>
54+
</DataTemplate>
55+
</CollectionView.ItemTemplate>
56+
</CollectionView>
57+
</Grid>
58+
</controls:TestContentPage>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Xamarin.Forms.CustomAttributes;
4+
using Xamarin.Forms.Internals;
5+
using Xamarin.Forms.Xaml;
6+
7+
#if UITEST
8+
using Xamarin.UITest;
9+
using Xamarin.UITest.Queries;
10+
using NUnit.Framework;
11+
using Xamarin.Forms.Core.UITests;
12+
using System.Linq;
13+
#endif
14+
15+
namespace Xamarin.Forms.Controls.Issues
16+
{
17+
#if UITEST
18+
[Category(UITestCategories.SwipeView)]
19+
#endif
20+
#if APP
21+
[XamlCompilation(XamlCompilationOptions.Compile)]
22+
#endif
23+
[Preserve(AllMembers = true)]
24+
[Issue(IssueTracker.Github, 11209, "[Bug] [iOS][SwipeView] Swipe view not handling tap gesture events until swiped", PlatformAffected.Android)]
25+
public partial class Issue11209 : TestContentPage
26+
{
27+
const string SwipeViewContent = "SwipeViewContent";
28+
const string Success = "Success";
29+
30+
public Issue11209()
31+
{
32+
#if APP
33+
Device.SetFlags(new List<string> { ExperimentalFlags.SwipeViewExperimental });
34+
InitializeComponent();
35+
#endif
36+
}
37+
38+
public List<string> Items => new List<string> { "short", "long word", "Extra long word", "word up" };
39+
40+
protected override void Init()
41+
{
42+
43+
}
44+
45+
#if APP
46+
void SwipeItem_Invoked(object sender, EventArgs e)
47+
{
48+
Console.WriteLine("Hey i was invoked");
49+
}
50+
51+
async void TapGestureRecognizer_Tapped(object sender, EventArgs e)
52+
{
53+
await Navigation.PushAsync(new Issue11209SecondPage());
54+
}
55+
#endif
56+
57+
#if UITEST
58+
[Category(UITestCategories.SwipeView)]
59+
[Test]
60+
public void TapSwipeViewAndNavigateTest()
61+
{
62+
RunningApp.WaitForElement(SwipeViewContent);
63+
RunningApp.Tap(SwipeViewContent);
64+
RunningApp.WaitForElement(Success);
65+
}
66+
#endif
67+
68+
[Preserve(AllMembers = true)]
69+
public class Issue11209SecondPage : ContentPage
70+
{
71+
public Issue11209SecondPage()
72+
{
73+
Title = "Issue 11209";
74+
75+
var layout = new StackLayout();
76+
77+
var instructions = new Label
78+
{
79+
AutomationId = Success,
80+
Padding = 12,
81+
BackgroundColor = Color.Black,
82+
TextColor = Color.White,
83+
Text = "If navigated tapping an item from the CollectionView, the test has passed."
84+
};
85+
86+
layout.Children.Add(instructions);
87+
88+
Content = layout;
89+
}
90+
}
91+
}
92+
}

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,7 @@
14941494
<Compile Include="$(MSBuildThisFileDirectory)Issue11869.cs" />
14951495
<Compile Include="$(MSBuildThisFileDirectory)Issue11723.cs" />
14961496
<Compile Include="$(MSBuildThisFileDirectory)Issue11496.xaml.cs" />
1497+
<Compile Include="$(MSBuildThisFileDirectory)Issue11209.xaml.cs" />
14971498
</ItemGroup>
14981499
<ItemGroup>
14991500
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
@@ -1791,6 +1792,9 @@
17911792
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11496.xaml">
17921793
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
17931794
</EmbeddedResource>
1795+
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11209.xaml">
1796+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
1797+
</EmbeddedResource>
17941798
</ItemGroup>
17951799
<ItemGroup>
17961800
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla27417Xaml.xaml">

Xamarin.Forms.Platform.iOS/Renderers/SwipeViewRenderer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ void UpdateContent()
337337
if (Subviews.Length > 0)
338338
_contentView = Subviews[0];
339339
}
340+
341+
if (_contentView != null)
342+
BringSubviewToFront(_contentView);
340343
}
341344

342345
void HandleTap()

0 commit comments

Comments
 (0)