Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[iOS] fixes #3525 - add epsilon for float compare and make region imm…
…utable
- Loading branch information
Showing
4 changed files
with
102 additions
and
10 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3525.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
|
||
|
||
#if UITEST | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
using Xamarin.Forms.Core.UITests; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 3525, "[iOS] Finicky tap gesture recognition on Spans")] | ||
#if UITEST | ||
[NUnit.Framework.Category(UITestCategories.Gestures)] | ||
#endif | ||
public class Issue3525 : TestContentPage | ||
{ | ||
const string kClickCount = "Click Count: "; | ||
const string kClickCountAutomationId = "ClickCount"; | ||
const string kLabelTestAutomationId = "SpanningLabel"; | ||
|
||
protected override void Init() | ||
{ | ||
var label = new Label() { Text = kClickCount, AutomationId = kClickCountAutomationId }; | ||
Padding = new Thickness(20); | ||
var layout = new StackLayout { Padding = new Thickness(5, 10) }; | ||
|
||
var formattedString = new FormattedString(); | ||
formattedString.Spans.Add(new Span { Text = "Not Clickable, ", ForegroundColor = Color.Red, FontAttributes = FontAttributes.Bold, LineHeight = 1.8 }); | ||
formattedString.Spans.Add(new Span { Text = Environment.NewLine }); | ||
var span = new Span { Text = "Clickable, " }; | ||
int clickCount = 0; | ||
span.GestureRecognizers.Add(new TapGestureRecognizer | ||
{ | ||
Command = new Command(() => | ||
{ | ||
clickCount++; | ||
label.Text = $"{kClickCount}{clickCount}"; | ||
}) | ||
}); | ||
|
||
formattedString.Spans.Add(span); | ||
formattedString.Spans.Add(new Span { Text = Environment.NewLine }); | ||
|
||
formattedString.Spans.Add(new Span { Text = "You also cannot click on me sorry about that.", FontAttributes = FontAttributes.Italic, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)) }); | ||
|
||
layout.Children.Add(new Label { AutomationId = kLabelTestAutomationId, FormattedText = formattedString }); | ||
layout.Children.Add(label); | ||
|
||
this.Title = "Label Demo - Code"; | ||
this.Content = layout; | ||
} | ||
|
||
#if UITEST | ||
[Test] | ||
public void SpanRegionClicking() | ||
{ | ||
var label = RunningApp.WaitForElement(kLabelTestAutomationId); | ||
var location = label[0].Rect; | ||
|
||
var lineHeight = location.Height / 3; | ||
var y = location.Y; | ||
RunningApp.TapCoordinates(location.X, y + lineHeight / 2); | ||
RunningApp.TapCoordinates(location.X + 5, y + lineHeight + 5); | ||
RunningApp.TapCoordinates(location.X, y + (lineHeight * 2)); | ||
RunningApp.WaitForElement($"{kClickCount}{1}"); | ||
|
||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters