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

[Android] Picker list shows up, when focus is set on other controls. #4187

Closed
thudugala opened this issue Oct 23, 2018 · 16 comments
Closed

[Android] Picker list shows up, when focus is set on other controls. #4187

thudugala opened this issue Oct 23, 2018 · 16 comments

Comments

@thudugala
Copy link

thudugala commented Oct 23, 2018

Description

Android issue.
Xamarin.Form 3.3.0.912540 issue. Works ok in 3.2.0.871581

When setting the focus on some other control, picker list shows up. when picker and other controls are inside ListVew.DataTemplate.ViewCell.
App2.zip

Steps to Reproduce

  1. Run the attached sample solution
  2. Select a value from Picker
  3. It works correctly
  4. Set focus on Entry
  5. The picker list shows up
  6. That is incorrect

Expected Behavior

when setting the focus on the entry, picker list should not show up.

Actual Behavior

when setting the focus on the entry, picker list shows up.

Basic Information

  • Versions with issue: Xamarin.Form 3.3.0.912540, 3.3.0.967583, 3.4.0.1008975
  • Last known good version: Xamarin.Form 3.2.0.871581
  • IDE: 15.8.7
  • Platform Target Frameworks:
    • Android: 9

Sample

App2.zip

@thudugala thudugala changed the title Picker list shows up, when focus is set on other controls. [Android] Picker list shows up, when focus is set on other controls. Oct 25, 2018
@samhouts samhouts added this to the 3.3.0 milestone Oct 26, 2018
@nbevans
Copy link

nbevans commented Oct 30, 2018

Same issue as this #4260

We are getting this too. Both real and emulated devices.

We were on the latest 3.4 pre but I am now going back through the versions to find a release where this doesn't happen.

@nbevans
Copy link

nbevans commented Oct 30, 2018

cceee9d#diff-a8dc9a010c576f0d2924c24ea2e54596R103

This most recent commit to PickerRenderer.cs looks highly suspect to me.

@nbevans
Copy link

nbevans commented Oct 30, 2018

I have developed a workaround for those in desperate need. Rather simple, turn off the Control.Focusable on the PickerRenderer which prevents that internal OnNativeFocusChanged from being superfluously invoked.

I've tested this rudimentarily and cannot find any impacts, though I'm sure it reverses the TabStop improvements that the aforementioned commit was meant to bring.

public class HackFix20181030PickerRenderer : PickerRenderer {
    public HackFix20181030PickerRenderer(DroidContext context) : base (context) { }

    protected override void OnElementChanged(ElementChangedEventArgs<Picker> e) {
        base.OnElementChanged(e);
        
        if (Control != null) {
            Control.Focusable = false;
        }
    }
}

@MikaTas
Copy link

MikaTas commented Nov 1, 2018

I was about to post here and issue about this aswell as I was facing a similar issue after updating from 3.2.. to 3.3.0.912540.

But, I can confirm that using the workaround Control.Focusable = false; in the customrendered as mentioned solved the acute problem.

@nbevans
Copy link

nbevans commented Nov 1, 2018

Glad it was of help to you 👍

@thudugala
Copy link
Author

Issue still exist in 3.3.0.967583

@AtosNicoS
Copy link

I just noticed another bug, I am not sure if this is related. Android only:

If Option A is selected and I select B and then scrol down, so that the entry is out of focus, the option gets resetted to A. Do you also see this problem?

@zezelazo
Copy link

I just noticed another bug, I am not sure if this is related. Android only:

If Option A is selected and I select B and then scrol down, so that the entry is out of focus, the option gets resetted to A. Do you also see this problem?

Try changing the CachingStrategy of the ListView to "RetainElement"

@AtosNicoS
Copy link

Yes that worked. I also opened the issue here and got a different suggestion as well: #4390

@thudugala
Copy link
Author

Issue still exist in 3.4.0.1008975

@samhouts samhouts removed this from the 3.3.0 milestone Nov 20, 2018
@samhouts samhouts added this to the 3.4.0 milestone Nov 20, 2018
@kellyelton
Copy link

A more complete workaround.

Place this class in the Android project, just replace the namespace MyCompany.App.Android with the appropriate namespace.

using Android.Content;
using MyCompany.App.Android;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(Picker), typeof(HackFix20181030PickerRenderer))]
namespace MyCompany.App.Android
{
    public class HackFix20181030PickerRenderer : Xamarin.Forms.Platform.Android.AppCompat.PickerRenderer
    {
        public HackFix20181030PickerRenderer(Context context) : base(context) { }

        protected override void OnElementChanged(ElementChangedEventArgs<Picker> e) {
            base.OnElementChanged(e);

            if (Control != null) {
                Control.Focusable = false;
            }
        }
    }
}

@valdetero
Copy link

@rmarinho Will this be in the next 3.4.x release? I just put in some nasty hacks to get around this in 3.4.0.1008975.

@rmarinho
Copy link
Member

@valdetero yes

@DennisWelu
Copy link

Thanks all. FWIW this "fixed" the reported issue which was also happening in my app. But with 3.4.1009999 I found that the on screen keyboard input was now messed up. I'm not sure if its related to this fix or if its something new in the release. Just a heads up. For me, I'm using a SearchBar instead of an Entry, it might accept a few characters but then it freezes up, and in fact the keyboard hangs around even after the app was killed.

@baneageorge
Copy link

@kellyelton Hi Kelly, your fix worked like a charm thank you so much! Now a new one came out... with the entry fields, the keyboard pops out in weird situations. Is there a way to do something similar?

@kellyelton
Copy link

@baneageorge I would ask @nbevans , I just copied thier solution and made it easier to copy/paste.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests