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 default value

See original GitHub issue

For anyone interested

In order to start the picker with the default value you should find the key of that value something like const defaultKey = _.findIndex(values, v => v.value === defaultValue);

and then pass it down to the withDecay function and use it like

const state = {
        finished: new Value(0), 
        position: new Value(-ITEM_HEIGHT * defaultKey),
        time: new Value(0),
        frameTime: new Value(0)
    };

here

https://github.com/wcandillon/can-it-be-done-in-react-native/blob/8cee8ef306b0d7c3e26fee30c87ae7fe277c68d9/the-10-min/src/Picker/AnimationHelpers.tsx#L44

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
spyr0scommented, Aug 22, 2020

@wcandillon I would love to see the example using a flatlist for displaying the values because mapping over them is too slow and we probably (if we’re using it for displaying years) we will have over 80-90 values

0reactions
minhthien309commented, Dec 20, 2020

The example was updated to have the default value. @spyr0s your solution seems good too 😃

I’ve set defaultValue but it’s not working. It always return 1986

const start = 1900;
const values = new Array(new Date().getFullYear() - start + 1)
.fill(0)
.map((_, i) => {
      const value = start + i;
      return value;
})
.reverse();

const defaultValue = 1990 - start; //or any different value

return(
     <Picker {...{ values, defaultValue }} />
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Default value for Picker - MSDN - Microsoft
I would like to show a default value in the text field of the Picker. So far I know the "Title" is automatically...
Read more >
Xamarin Forms Default value for Picker
What do you mean by getting first data? Let picker select the first row? Or get the value of first row in Picker?...
Read more >
Set default picker value | Apple Developer Forums
Hi,. I have this picker. Picker("From status", selection: $fromStatusSelectorIndex) { ForEach(0 ..< orderStatusFromArray.count) { index in Text(self.
Read more >
sn-record-picker default value
i want to set default value to sn-record-picker on widget load.
Read more >
Setting a picker view default value to object – SwiftUI
I have a PickerView inside a form that I want to default to a certain value. I pass an object called MatchEvent into...
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