Picker: Selected item index is not maintained when the list is changed
See original GitHub issueMinimal repro:
Program.mkProgram
(fun () -> false, Cmd.ofMsg ())
(fun () model -> not model, async { do! Async.Sleep 1000 } |> Cmd.ofAsyncMsg)
(fun model _ -> View.ContentPage(View.Picker((if model then [1; 2] else [1; 2; 3]), selectedIndex = 0)))
The above code changes the list every second. The selected index is kept constant. However, the selected item unselected.
Compare:
Program.mkSimple id (fun () -> id) (fun _ _ -> View.ContentPage(View.Picker([1; 2], selectedIndex = 0)))
When the list is unchanged, the selected index is set successfully.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Picker: Selected item index is not maintained when the list ...
The above code changes the list every second. The selected index is kept constant. However, the selected item unselected. image. Compare:.
Read more >xamarin.forms - Picker inside collectionview looses value ...
I have picker inside Xamarin Forms collectionview, which populated from viewModel. In case of changing index, i.e SelectedIndexChanged event, ...
Read more >How to maintain the SelectedIndex of the picker when ...
The SelectedIndex property of the picker control will not be maintained when loaded inside the ItemTemplate of SfListView. This is because while scrolling ......
Read more >Setting a Picker's ItemsSource Property - Xamarin
A Picker supports selection of one item at a time. When a user selects an item, the SelectedIndexChanged event fires, the SelectedIndex property ......
Read more >Class “ItemPicker” - Tabris.js Documentation
When items changes - either by modifying List or setting a new Array - the selection state will be preserved if the index...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A property that depends on another one is not something Fabulous really likes. The source of truth needs to be the ViewElement, not some side effect from the underlying framework.
The way I can imagine to fix it is a custom update code for
ItemsSource
instead ofSelectedIndex
. If the ItemsSource needs to change, we will need to automatically reapply theSelectedIndex
if possible as well.You’re right. It’s not possible for the moment, the Generator doesn’t support it. Before we’re able to move forward on this issue, we will need to decide how we proceed with the Generator. (might heavily change if we do the framework agnostic view diffing)