muak / AiForms.SettingsView

SettingsView for Xamarin.Forms
MIT License
316 stars 45 forks source link

iOS PickerCell IsEnabled not reflecting properly #185

Open AlvinKwong opened 3 years ago

AlvinKwong commented 3 years ago

Description

My app has a page that allows users to adjust the settings. But the settings will expire in 1 minute. After that, the cells will be greyed out and not allow to be configured. The problem happens that when the user navigates to this page, one of the picker cells is enabled, though the flag is false. But after scrolling down and up again, that picker cell becomes disabled. Therefore it is suspected that there is some caching issue when reflecting the isEnabled status of the cell. This only happens on iOS and does not happen on Android.

(For more Information, the picker cell "Recovery Detection Angle" and "Sensing Timer" are binding the same boolean in their IsEnabled properties. Therefore it should not be the program issue as if the flag is not updated properly, both cells would be enabled/disabled at the same time.)

Steps to Reproduce

  1. Create a page with a SettingsView
  2. Bind the isEnabled Flag of the cells to the ViewModels boolean properties.
  3. Set the boolean properties to false in OnNavigatedTo() method.
  4. Navigate to this page, some of the cells that are supposed to be disabled are enabled.
  5. Scroll down and up again, the cells now become disabled.

Platforms

Basic Information

Video

https://user-images.githubusercontent.com/31871670/133186005-2e3bcd5b-7564-425b-b107-428d1c0d5382.mp4

AlvinKwong commented 3 years ago

More information For that problematic picker cell, I changed to isEnabled="False" such that it should always be disabled. But the problem persists that when just navigates to the page, the picker cell is still enabled. Once scroll down and back again, the picker cell becomes disabled.

The only difference between this problematic picker cell and other picker cells is that the ItemSource of the problematic picker cell updates dynamically. When the "Fall Detection Angle" value changes, the "Recovery Detection Angle" item source will update accordingly to the "Fall Detection Angle" value. Other picker cells' item sources are initialized in the view model constructor and will not changed.

AlvinKwong commented 3 years ago

I have found a workaround for this issue. Currently the isEnabled is initialized in the method OnNavigatedTo because it is determined by the navigation parameter. Since I use Prism.Forms, I can implement the IInitialize interface which its method Initialize(INavigationParameters parameters) is executed before OnNavigatedTo. After moving the codes from OnNavigatedTo to Initialize, the picker cell state is now reflected properly when the page shows up.