This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android,iOS,UWP] Allow Entry CursorPosition/SelectionLength to be se…
…t in ctor (#3402) fixes #3343 fixes #3633 * Add repro for #3343 + unit tests * [Core] Disallow negative values for CursorPosition/SelectionLength * [All] CursorPosition/SelectionLength can bindin ctor & clear value fixes #3343 * typo * cleanup * [iOS] Cursor snaps to end * try/catch
- Loading branch information
Showing
7 changed files
with
544 additions
and
102 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3343.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,88 @@ | ||
using System.Threading.Tasks; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 3343, "[Android] Cursor position in entry and selection length not working on 3.2.0-pre1", PlatformAffected.Android | PlatformAffected.iOS)] | ||
public class Issue3343 : TestContentPage | ||
{ | ||
protected override void Init() | ||
{ | ||
Entry entry = new Entry() | ||
{ | ||
Text = "Initialized", | ||
VerticalOptions = LayoutOptions.Center, | ||
HorizontalOptions = LayoutOptions.StartAndExpand, | ||
WidthRequest = 150 | ||
}; | ||
|
||
entry.CursorPosition = 4; | ||
entry.SelectionLength = entry.Text.Length; | ||
|
||
Label entryLabel = new Label { VerticalOptions = LayoutOptions.Center, FontSize = 8 }; | ||
entryLabel.SetBinding(Label.TextProperty, new Binding(nameof(Entry.CursorPosition), stringFormat: "CursorPosition: {0}", source: entry)); | ||
|
||
Label entryLabel2 = new Label { VerticalOptions = LayoutOptions.Center, FontSize = 8 }; | ||
entryLabel2.SetBinding(Label.TextProperty, new Binding(nameof(Entry.SelectionLength), stringFormat: "SelectionLength: {0}", source: entry)); | ||
|
||
Entry entry2 = new Entry() | ||
{ | ||
Text = "Click Button", | ||
VerticalOptions = LayoutOptions.Center, | ||
HorizontalOptions = LayoutOptions.StartAndExpand, | ||
WidthRequest = 150 | ||
}; | ||
|
||
Label entry2Label = new Label { VerticalOptions = LayoutOptions.Center, FontSize = 8 }; | ||
entry2Label.SetBinding(Label.TextProperty, new Binding(nameof(Entry.CursorPosition), stringFormat: "CursorPosition: {0}", source: entry2)); | ||
|
||
Label entry2Label2 = new Label { VerticalOptions = LayoutOptions.Center, FontSize = 8 }; | ||
entry2Label2.SetBinding(Label.TextProperty, new Binding(nameof(Entry.SelectionLength), stringFormat: "SelectionLength: {0}", source: entry2)); | ||
|
||
// When the Entry is in a NavPage, the Entry doesn't get first focus on UWP | ||
string uwp_instructions = Device.RuntimePlatform == Device.UWP ? "Press Tab to focus the first entry. " : ""; | ||
|
||
Content = new StackLayout() | ||
{ | ||
Padding = 20, | ||
Children = | ||
{ | ||
new StackLayout{ Children = { entry, entryLabel, entryLabel2 }, Orientation = StackOrientation.Horizontal }, | ||
new StackLayout{ Children = { entry2, entry2Label, entry2Label2 }, Orientation = StackOrientation.Horizontal }, | ||
new Button() | ||
{ | ||
Text = "Click Me", | ||
Command = new Command(() => | ||
{ | ||
entry2.CursorPosition = 4; | ||
entry2.SelectionLength = entry2.Text.Length; | ||
}) | ||
}, | ||
new Button() | ||
{ | ||
Text = "Click Me After", | ||
Command = new Command(() => | ||
{ | ||
entry2.CursorPosition = 2; | ||
}) | ||
}, | ||
new Button() | ||
{ | ||
Text = "Click Me Last", | ||
Command = new Command(async () => | ||
{ | ||
entry2.ClearValue(Entry.SelectionLengthProperty); | ||
|
||
await Task.Delay(500); | ||
|
||
entry2.ClearValue(Entry.CursorPositionProperty); | ||
}) | ||
}, | ||
new Label{ Text = $"{uwp_instructions}The first Entry should have all text selected starting at character 4. Click the first button to trigger the same selection in the second Entry. Click the second button to move the cursor position but keep the selection length to the end. Click the third button to clear the selection length and then the cursor position." } | ||
} | ||
}; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.