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

[Feedback] Xamarin Forms 3.2 Android entry cursor jumps back and forth #3923

Closed
samhouts opened this issue Sep 27, 2018 · 14 comments · Fixed by #4730
Closed

[Feedback] Xamarin Forms 3.2 Android entry cursor jumps back and forth #3923

samhouts opened this issue Sep 27, 2018 · 14 comments · Fixed by #4730
Labels
a/entry e/5 🕔 5 excellent-report feedback-ticket Issue originates from https://developercommunity.visualstudio.com help wanted We welcome community contributions to any issue, but these might be a good place to start! inactive Issue is older than 6 months and needs to be retested p/Android t/bug 🐛 up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!
Milestone

Comments

@samhouts
Copy link
Member

Description

Xamarin.Forms 3.2 appears to introduce and error, in some cases, where when typing into an entry field, the cursor continually jumps from the beginning to the end of input and back continuously. Thus when attempting to enter "123456789", it comes out as "975312468". It occurs when typing directly and using on-screen keyboard. I've repeated the problem using an emulator and debugging on a device. It seems to only occur on Android.

In my case, the issue only happens when I am brought to my initial login screen on startup. If I reset the cursor after each character and login successfully, I no longer have a problem, even if I log off and back on during the session. If I start a new session and currently have valid login information cached and bypass the sign in page, I also do not have a problem. I've only seen this problem on my sign on page.

Reverting back to Xamarin.Forms 3.1 fixes the problem.

Visual Studio 15.8.5
Xamarin 4.11.0.776 (d15-8@1ae9b59d7)
Xamarin Designer 4.15.9 (d000f568b)
Xamarin Templates 1.1.116 (9619170)
Xamarin.Android SDK 9.0.0.19 (HEAD/a8a3b0ec7)
Xamarin.iOS and Xamarin.Mac SDK 12.0.0.15 (84552a4)
Xamarin.Forms 3.2.0.839982


View on Developer Community

To find diagnostic information, see the original linked feedback ticket.

Source

692432

@samhouts samhouts added the feedback-ticket Issue originates from https://developercommunity.visualstudio.com label Sep 27, 2018
@pauldipietro pauldipietro added this to New in Triage Sep 27, 2018
@kingces95 kingces95 added p/Android s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. e/5 🕔 5 labels Oct 1, 2018
@ndcs
Copy link

ndcs commented Oct 4, 2018

AndroidCursorFail.zip
I could not access the Source link above, so I added the project that reproduces the error.

@kingces95 kingces95 moved this from New to Ready For Work in Triage Oct 4, 2018
@samhouts samhouts removed the s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. label Oct 16, 2018
@samhouts samhouts removed this from Ready For Work in Triage Oct 16, 2018
@samhouts samhouts added the inactive Issue is older than 6 months and needs to be retested label Apr 4, 2019
@samhouts samhouts added help-wanted up-for-grabs We welcome community contributions to any issue, but these might be a good place to start! labels Jun 28, 2019
@lukazh
Copy link

lukazh commented Jul 1, 2019

OnCreateView method in Xamarin.Forms.Platform.Android.AppCompat.FragmentContainer class is called twice for the same "initial login screen" page on startup, result in double renderers created for the single page. That could be the root cause of this issue.

@kvpt
Copy link
Contributor

kvpt commented Jul 1, 2019

Made a fix on the 3.6 branch.

@kvpt
Copy link
Contributor

kvpt commented Jul 1, 2019

@ndcs Thanks for the reproduction.
@lukazh Thanks to have raise the issue to the top

@lukazh
Copy link

lukazh commented Jul 2, 2019

@kvpt The fix only fixes cursor jump behavior, while the problem of duplicate call on OnCreateView for single page still exists, which could be the cause of "certain circumstances". Would you please take some time to invest this?

@kvpt
Copy link
Contributor

kvpt commented Jul 2, 2019

@lukazh The issue here is for the cursor jump and what cause this is a focus problem.
The duplicate call of OnCreateView is not related to this issue. I'm sure of this, because all the events here come from Android and there can only be one "MainView" at a time.

So if you have this issue and have reproduction example, I invite you to open a dedicated issue.

From previous debug session, if I remember, I have encountered this case of double call.
From the stacktrace it was caused by the registrar (used by depency injection) class which initialized all the renderers which trigger the OnCreateView but those views was never attached.
You can check it yourself, use a breakpoint and compare the stacktraces of the two calls.

@lukazh
Copy link

lukazh commented Jul 2, 2019

repro.zip
@kvpt I made a much simpler reproduction with only two pages and nothing else. The duplicate method call occurs as well, which means it has nothing to do with dependency injection.

If you make a breakpoint in OnTextChanged method in Xamarin.Forms.Platform.Android.EntryRenderer class and then input in the Entry, you will find that the method is called twice, from two different instances (use GetHashCode() or somehow). These two renderer instances interfere with each other causing problems including focus and cursor.

When one of the two calls on OnCreateView is discarded, everything works well and we don't need to care about the focus stuff.

@kvpt
Copy link
Contributor

kvpt commented Jul 2, 2019

@lukazh Thanks for the reproduction, I will test that.

@kvpt
Copy link
Contributor

kvpt commented Jul 2, 2019

@lukazh Your problem is caused by the navigation during the MainPage appearing.
This edge case is broken in Xamarin.Forms, I fixed it in #4730 but it has not been merged yet.

You have two solutions :

  • Had a delay/wait before your push async inside the OnAppearing (1 second is normaly enough)
  • Use my custom package which contain the fix (the nupkg is inside the zip), However it's based on the 3.6 branch (I don't use 3.2 branch anymore).
    xamarin.forms.3.6.8.zip

I will check the other reproduction to see if the same patch fix also the issue here.

@kvpt
Copy link
Contributor

kvpt commented Jul 2, 2019

It's also the same case in the other reproduction.
The init method of the MainViewModel make a navigation to another page in the init, I did not see that.
So the right fix is #4730 and not #6736, so I will close #6736.

@samhouts samhouts added this to In Progress in v4.2.0 Jul 8, 2019
@samhouts samhouts added this to In Progress in v4.3.0 Aug 22, 2019
@samhouts samhouts removed this from In Progress in v4.2.0 Aug 22, 2019
@samhouts samhouts added the in-progress This issue has an associated pull request that may resolve it! label Oct 2, 2019
@samhouts samhouts removed this from In Progress in v4.3.0 Oct 7, 2019
@snice1981
Copy link

Hi

I have the same problem in Xamarin Forms 4.3. I need to type two times the same character. For instance, if I want 1234, I need to do 11223344. Same for backspace, need to do 2x backspace.

How did you solve the problem?

@kvpt
Copy link
Contributor

kvpt commented Dec 10, 2019

Hi @snice1981,
From the previous reproduction cases in this post, the issue is related to a navigation during the init.
So if you make a navigation at this place too, it's the same root cause.
As the fix for this is not merged yet, you will have to do the workaround, which is to add a Task.Delay (1 second should do it) before the navigation to give more time for the main page to load before navigating.
If it's not your case, can you provide a reproduction ?

@snice1981
Copy link

Hi @kvpt

Here is my reproduction:
From the Main page, I have a LongPressedEffect command that navigate to a Settings page (App.NavigationService.NavigateAsync(NavigationPages.SettingsPage))

Here is the OnAppearing in SettingsPage.xaml.cs:

image

The Settings page is pretty easy and just contains 3-4 Labels + 3-4 Entry
I have the problem on all Entry in that page.

Here is an example of Entry that cause the issue:

image

image

This code was working since months until I upgraded from Xamarin Forms v3.0 to latest (v4.3)

@snice1981
Copy link

I think I have found the reason!
If I put SetValue after Settings.ServerURL it works!

image

And that's how it should be of course, as in the SetValue we are firing OnPropertyChange event which will rebind the Entry to not yet changed value...

However it doesn't explain why it was working since months...

@samhouts samhouts removed the inactive Issue is older than 6 months and needs to be retested label Feb 6, 2020
@samhouts samhouts added a/entry and removed in-progress This issue has an associated pull request that may resolve it! labels Apr 15, 2020
@samhouts samhouts added inactive Issue is older than 6 months and needs to be retested help wanted We welcome community contributions to any issue, but these might be a good place to start! and removed inactive Issue is older than 6 months and needs to be retested labels Jul 17, 2020
@samhouts samhouts added this to the 5.0.0 milestone Aug 13, 2020
@samhouts samhouts added the inactive Issue is older than 6 months and needs to be retested label Sep 18, 2020
@samhouts samhouts removed this from the 5.0.0 milestone Nov 2, 2020
@rmarinho rmarinho added this to To do in v5.0.1 via automation Nov 16, 2020
@rmarinho rmarinho added this to the 5.0.1 milestone Nov 16, 2020
Android Ready For Work automation moved this from To do to Done Nov 15, 2021
v5.0.1 automation moved this from To do to Done Nov 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/entry e/5 🕔 5 excellent-report feedback-ticket Issue originates from https://developercommunity.visualstudio.com help wanted We welcome community contributions to any issue, but these might be a good place to start! inactive Issue is older than 6 months and needs to be retested p/Android t/bug 🐛 up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!
Projects
Development

Successfully merging a pull request may close this issue.

7 participants