question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Picker: Selected item index is not maintained when the list is changed

See original GitHub issue

Minimal 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.

image

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.

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
TimLarivierecommented, Jun 27, 2019

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 of SelectedIndex. If the ItemsSource needs to change, we will need to automatically reapply the SelectedIndex if possible as well.

0reactions
TimLarivierecommented, Jul 6, 2019

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)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found