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.

initialScrollToIndex does not work when input data size is reduced

See original GitHub issue

Following code works fine

const petTypes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

export default class Example extends Component {
  constructor(props) {
    super(props);
    this.state = {
      selected: 5
    };
  }

  onPetChange = index => {
    this.setState({
        selected: index
    });
  };

  render() {
    return (
      <SmoothPicker
        style={{ marginTop: 300 }}
        horizontal
        initialScrollToIndex={this.state.selected}
        keyExtractor={(_, index) => index.toString()}
        ref={ref => (this.refPetList = ref)}
        showsHorizontalScrollIndicator={false}
        bounces={true}
        magnet={true}
        scrollAnimation
        data={petTypes}
        onSelected={({ item, index }) => this.onPetChange(index)}
        renderItem={({ item, index }) => {
          return this.petPickerItem(index, item);
        }}
      />
    );
  }

  petPickerItem = (index, item) => {
    return <Text style={this.state.selected === index?{color:"red"}:{color: "#000000"}}>{index}</Text>;
  };
}

Result for the above code Screen Shot 2019-08-30 at 2 35 04 AM

When the input array is reduced by one value to the following const petTypes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

Following is the result Screen Shot 2019-08-30 at 2 37 15 AM

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Rahulzzcommented, Nov 26, 2019

Nope, I haven’t. I actually quit working on that project. I am sorry.

On Tue, Nov 26, 2019, 10:55 PM Brian Rubio notifications@github.com wrote:

Did you find a workaround for this ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rdhox/react-native-smooth-picker/issues/14?email_source=notifications&email_token=AE2JVTLRXIWI7HXENFEOYVTQVVLXXA5CNFSM4ISG4IT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFGZ2DY#issuecomment-558734607, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE2JVTOXEXQRPXDBKNZKJQLQVVLXXANCNFSM4ISG4ITQ .

1reaction
Brianopcommented, Nov 26, 2019

Did you find a workaround for this ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

scrollToIndex out of range: item length 0 but minimum is 1
Data is passed correctly in vertical FlatList but when i try with the horizontal one, it gives this error. What do you think...
Read more >
Scroll to a Specific Item in ScrollView List View - About React
In this example, we will create a List using Scroll View to hold the data, a TextInput and a button to take the...
Read more >
ScrollView - React Native
This can be used for pagination when the page is less than the width of the horizontal ScrollView or the height of the...
Read more >
FlatList scrollToIndex practical example. - Expo Snack
function getData(number) {. let data = []; ... { length: 50, offset: 50 * index, ... random(Date.now()) * this.props.data. length);. this.flatListRef.
Read more >
Property does not exist on type 'never' in React | bobbyhadz
import {useState} from 'react'; function App() { // 👇️ use generic to type the state array const [arr, setArr] = useState<any[]>([]); return (...
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