-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Calling Focus on all Pickers running an API 28 devices no longer opens Picker #5159
Comments
@PureWeen Are you looking at this one? |
@varyamereon I've attached a quick sample based on the one you linked that works for me. Can you try it? |
@PureWeen EDIT |
Anyone found a solution to this? Currently experiencing the exact same issue when compiling against Android 28 (Pie). On devices that are 8.1 and lower (using the same APK built against Android 28), the date time pickers work. Only happens when running on an Android 9.0 device. |
I just did a bit of testing. In the start, our xaml looks like this (notice, they start off invisible):
Our code was just calling ".Focus()" on one of these elements (depending on the button you click, of course).
If I change my code to the following, the date picker input box appears (we don't want this to happen - all we want to happen is to bring up the date/time picker dialog). BUT along with the input field appearing, the date/timer picker dialog DOES appear.
|
The picker not working too, not only DatePicker. |
https://developer.android.com/about/versions/pie/android-9.0-changes-28
Pickers probably should have a ShowDialog method instead of just having to go via focus |
Facing the same issue. Any quick workarounds for this at the moment? |
I put the button I am using to activate it, and the picker itself in a grid in the same column and did: HeightRequest="1" WidthRequest="1" Margin="0" HorizontalOptions="Center" on the picker. So basically hide the picker behind the button, and it seems to work. |
Hopefully this can help somebody else. Full disclosure -- it's a hack, but it works. I was able to work around this issue with a custom picker renderer bypassing the default implementation of the For reference, take a look at the IPickerRenderer.OnClick method for the Android PickerRenderer: Here is the relevant code:
|
check if the IsEnable property is set to false then the focus() event won't work on api 28, setting it to true or removing it will fix the issue and make the datepicker focus works. |
Tried all the workarounds, some work but only once and the custom renderer is overkill for my purposes.
|
@chrisfoulds sorry it did not work for me either. The only workaround I've found is using a custom renderer (quite easy to write in fact) following these instructions |
The solution I posted above works great for me, in a product app now with 20k DAU's and no complaints so surprised you had to go down the custom renderer route. |
@chrisfoulds I am using it in a "modal page", that's maybe the issue ? |
@jonathanantoine maybe , I just checked I am using it on a standard navigation page which may make all the difference. |
Hi folks, I see a lot of replies here looking for solutions and I realized I never posted my work around!! Just make the date picker / time picker visible but translate it on the Y axis by a huge number. Then when you call .Focus() on it, it will work! Here is an example of what we have: xaml: Code behind: If it means anything (I doubt it) these elements are direct children of a StackLayout, which is the root child of my content page. This content page itself is apart of the out-of-the-back navigation page. |
Just set IsVisible TRUE, and set Opacity to 0 :) now you can reuse the datepicker.Focus |
Another hack, set the Height and Width requests to 1 and make the text transparent. Set IsVisible to true. It ain't pretty but it works for now. Still think this is something that needs a proper implementation with regards to #5159 (comment). |
Regression between 3.4.0.1008975 and 3.4.0.1009999 Requires targeting Android 9.0 to reproduce. |
Same issue,
Put the control in the same grid. set datepicker textcolor to transparent |
So in 9.0 it seems Android started enforcing (or added?) a condition for being focusable is first being visible. If we make the view visible before requesting it gain focus then the the date picker appears. It seems people want the picker dialog without the A number of workaround/hacks have been proposed (a translation off the visible screen, reducing size to a pixel, hiding behind another view) and while any may work we not in a position to endorse one over the other. Here is where I added |
Here's the line of code that changed that broke it between 3.4 releases https://github.com/xamarin/Xamarin.Forms/pull/4344/files#diff-446294d29d78ca8d84e4c0ddc20bbc07R100 |
So, if I have reproduced this correctly in the Gallery app, it's not so much a problem of receiving focus. That seems to still work, but the I have tried both This seems to work in all cases I have tried so far, at the time of writing the UI tests are still running. In any case, if this works, I don't really see the need to keep the I'm curious to hear any of your thoughts about this. Edit: this fix does not seem to work for Picker for some reason... |
My picker was hidden behind another view so setting the IsVisible workaround didn't work for me. This line in constructor of the Page.xaml.cs worked for me:
|
I've used the workaround from @truXton222 but now when I press backbutton on the device the datepicker dialog shown again instead of view going back :| |
@jfversluis would be great! |
closed by #7289 |
This was the only work around which works for me sadly it only works the first time. After dismissing the picker I can't seem to bring it up anymore unless I switch to another views and later come back to the view with the picker. |
@gilles-leblanc did you try the latest 4.2 version (or 4.3-pre) the fix for this should be incorporated in there? If you still find that it's not working, please open a new issue. |
Uh oh!
There was an error while loading. Please reload this page.
Description
When using API Level 28, calling Focus on a DatePicker with Visible set to false does not show the date picker dialog.
Prior to this PR https://github.com/xamarin/Xamarin.Forms/pull/4344/files#diff-446294d29d78ca8d84e4c0ddc20bbc07L132 the Picker was opened as part of the FocusRequestedEvent. PR #4344 brought DatePicker inline with the other pickers by changing it to trigger a Click on the control which then would trigger the click listener to open the picker.
On API 28 FocusRequestedEvent is still called so there is still an opportunity to react to this. The difference on API 28 is that the Focus request fails so the Click Listener never actually fires.
Possible fix ideas
Steps to Reproduce
Expected Behavior
DatePicker dialog is shown.
Actual Behavior
Nothing happens.
Basic Information
Screenshots
n/a
Reproduction Link
Reproduction
The text was updated successfully, but these errors were encountered: