dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.99k stars 1.72k forks source link

After selecting an item in the picker, the 'Unfocused' event does not trigger. #21704

Open bhuwancb99 opened 5 months ago

bhuwancb99 commented 5 months ago

Description

When selecting any item inside the picker, the 'Unfocused' event fails to trigger. Previously, in Xamarin Forms, it worked correctly. However, currently, it functions properly only on iOS. On Android, the event does not occur as expected; upon selecting an item, no action is taken. image

image

image

Steps to Reproduce

Create .NET MAUI New Project -> Select .NET 8.0 -> Add Picker Inside Page - > add Event Unfocused -> When select any item inside picker -> Unfocused event not trigger.

Link to public reproduction project repository

https://1drv.ms/f/s!Alibu8GDjP9aggKpS2vWOW7lZMxh?e=zt5toB

Version with bug

8.0.14 SR3.1

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 14

Did you find any workaround?

No response

Relevant log output

sometime getting this error when select picker- Android.Views.InflateException: 'Binary XML file line #23 in com.abc.xyz:layout/mtrl_alert_select_dialog_item: Binary XML file line #23 in com.abc.xyz:layout/mtrl_alert_select_dialog_item: Error inflating class TextView'

jaosnz-rep commented 5 months ago

Can repro this issue at Android platform on the latest 17.10 preview 5(8.0.21 & 8.0.14 & 8.0.7).

bhuwancb99 commented 5 months ago

facing same issue on the latest 17.10 preview 2(8.0.14). not able to trigger 'Unfocused' event after selected items inside picker.

bhuwancb99 commented 5 months ago

Could you please provide an update on this? My application release is pending due to this change. If you have any suggestions for patching this issue, I urgently need a solution. Thank you.

bhuwancb99 commented 5 months ago

any update?

bhuwancb99 commented 5 months ago

any update?

bhuwancb99 commented 4 months ago

Hi @jaosnz-rep any update on this ? I'm waiting for this fix before releasing the application to the Play Store.

bhuwancb99 commented 4 months ago

Hi @jaosnz-rep -any update on this bug?

jsuarezruiz commented 4 months ago

As a workaround, could use the SelectedIndexChanged event and use the Unfocus method.

bhuwancb99 commented 4 months ago

Hi @jsuarezruiz I can't use the 'SelectedIndexChanged' event because I am changing the SelectedIndex based on the entry value, so both the picker and entry's Unfocused events are not working. It's difficult for me to manage this across the entire application. After upgrading from Xamarin to MAUI, it's not possible to change the logic in many places. If possible, could you suggest any patch or code that would make the Unfocused event work?

bhuwancb99 commented 4 months ago

Hi @jaosnz-rep and @Eilon -any update on this bug?

bhuwancb99 commented 3 months ago

Hi @jaosnz-rep and @Eilon any update on this. i am waiting to release application inside playstore.

bhuwancb99 commented 3 months ago

Hi @jaosnz-rep and @Eilon,

Do you have any updates on this issue? I am waiting to release the application on the Play Store. It is a small issue related to the picker event not triggering the focused or unfocused events. I created this ticket 2-3 months ago, but it has not been fixed yet. I coordinate with the client daily regarding this issue, and it is becoming increasingly urgent. If you are unable to fix this issue, could you please provide some steps or any other workaround to resolve it temporarily so we can release the application live?

bhuwancb99 commented 2 months ago

any update on this when picker unfocused issue fixed?

bhuwancb99 commented 2 months ago

@samhouts / @jaosnz-rep / @Eilon - It's been almost 3-4 month since this issue was reported. This is my priority issue because I am not releasing my upgraded app from Xamarin Forms to MAUI due to this pending issue. Please provide a solution for this, or suggest any patch or alternate way to fix this issue and release the app on the Play Store.

Eilon commented 2 months ago

@Redth / @PureWeen - any thoughts on how this issue can make progress? Would we accept a PR to this? Or know of a better workaround?

bhuwancb99 commented 1 month ago

Hi @Eilon / @Redth / @PureWeen - any update on this ?

bzd3y commented 1 month ago

@bhuwancb99 Wait, why would selecting something trigger Unfocused? The control still has focus when something was selected, right? Why would it lose focus or report that it lost focus?

Xamarin might have done this, but that seems to be the wrong behavior (unless I'm misunderstanding something). Personally I would not want or expect a control to do this, unless it was configurable.

If you want to reproduce this for legacy reasons, I think you should be able to do it pretty easily with a MAUI handler.

bhuwancb99 commented 1 month ago

@bzd3y inside a collection view, I am using a Picker to change values like item quantity or other values. When users add multiple items (like 10 to 15) to the cart, the SelectedIndexChanged event is triggered every time the page loads or when the collection view refreshes, causing 10-15 API calls to be made. However, the Unfocused event for the Picker is only called when a specific Picker value is changed, and it is not triggered when the collection view refreshes or loads for the first time.

I want to use the Picker's Unfocused event (or an alternative method) to achieve this behavior without triggering multiple API calls during page load or collection view refresh. Additionally, the Unfocused event for the Entry textbox is also not being called.

Please suggest an alternative way to handle this scenario or a method to achieve this using handlers.

uhbtl commented 1 month ago

I am facing the exact same problem as @bhuwancb99 since I upgraded my app from Xamarin to MAUI. I used the Unfocused event to check if the user changed the selected value too. I cannot release my MAUI app this way.

bhuwancb99 commented 1 month ago

Hi @Eilon / @Redth / @PureWeen / @bzd3y, In Xamarin. Forms, the Unfocused event is working, and based on this, we delivered the application to the client. However, in .NET MAUI, the Unfocused event does not trigger. This is why I cannot deliver this app to the Play Store. If you are providing this functionality in Xamarin. Forms, why is it not available in MAUI? I opened this issue in April, and it has been almost 4-5 months without a solution. Three of my projects are pending release to production due to this issue, and my clients need the Unfocused functionality.

Please provide a solution for this or suggest a patch or any alternative way.

bhuwancb99 commented 1 month ago

Yes, @uhbtl I am facing the exact same issue. If the issue is fixed, I will release all three of my applications on the Play Store or Apple Store.

Eilon commented 1 month ago

Hi, I think that logically the Unfocused event is not the right one to use. That event is meant for when the user unfocuses a control and focuses another control. I think you're actually looking for SelectedIndexChanged, but your issue is that this event happens even when the user didn't actually pick something? Is that correct?

If this is true, could you create a control derived from Picker that has an additional event that is only raised when the actual item changes? Or you could handle this within your app's ViewModel where even though there is an event that is raised too often, the ViewModel can compare its internal data to the UI, and detect if something actually changed?

bhuwancb99 commented 1 month ago

Hi @Eilon I don't know why you're not providing the same Xamarin. Forms functionality in .NET MAUI. It's very difficult to manage because, in the Unfocused event, when an item is selected, an API call is made. So, please provide the same Xamarin. Forms functionality in MAUI. Also, the Unfocused event was working in .NET MAUI 7.0, but it's not working in .NET 8.0. Why is this happening? and why you are not fixing this issue on .NET 8.0

uhbtl commented 1 month ago

Hi @Eilon

Hi, I think that logically the Unfocused event is not the right one to use. That event is meant for when the user unfocuses a control and focuses another control. I think you're actually looking for SelectedIndexChanged, but your issue is that this event happens even when the user didn't actually pick something? Is that correct?

That´s correct.

If this is true, could you create a control derived from Picker that has an additional event that is only raised when the actual item changes?

This is exactly what I did in Xamarin.Forms. After the user changed the selected value manually, the Unfocused Event was raised. By raising this event, the IsFocused property changed to false. So you could handle that in the OnPropertyChanged event of the picker itself (and fire your custom event). But in MAUI, after the user changed the selected value manually, no property is changed. I found no way to handle that.

LeoJHarris commented 3 weeks ago

Facing the same issue.

SleepyDevelops commented 3 weeks ago

When looking into this issue I noticed that the IsFocused is always false, even if the Picker is open. That's probably why the unfocused is not triggered. Which makes this even worse i think.

bhuwancb99 commented 1 week ago

Hi @Eilon / @Redth / @PureWeen / @bzd3y, any update on this ?