erksch / react-native-wheely

An all JavaScript wheel picker for react-native without any native code.
413 stars 59 forks source link

Array Index Out Of Bounds Exception #50

Closed c-goettert closed 1 year ago

c-goettert commented 1 year ago

Also after upgrading to 0.6.0 we are still seeing some occasional occurrences of index out of bounds exceptions in our crash reporting. I was unable to reproduce it myself during testing, but perhaps the corresponding error can be deliberately captured or stabilized even further?

Here is a part of the Stacktrace of a native crash (Android 10, HUAWEI HUAWEI P30 lite):

at android.widget.OverScroller$SplineOverScroller.update(OverScroller.java:1145)
at android.widget.OverScroller.computeScrollOffset(OverScroller.java:402)
at android.widget.ScrollView.onInterceptTouchEvent(ScrollView.java:782)
at com.facebook.react.views.scroll.ReactScrollView.onInterceptTouchEvent(ReactScrollView.java:366)
at android.view.ViewGroup.checkInterception(ViewGroup.java:2736)

And here is the crash message of a JS crash (Android 13, Samsung Galaxy S20): Selected index -1 is out of bounds [0, 23]

We are currently using RN 0.70.7.

Might be related to #36 .

c-goettert commented 1 year ago

Perhaps I should add that we do not manually set a "-1" value as a prop. Basically, our component looks like this: We store the selected index in the component state and pass this state back as value prop to the wheel picker, like this:

...
onItemSelected = (selectedIndex) => {
  this.setState({ selectedIndex })
}
...
render () {
  const { items, label, unit, containerStyle, compactLayout } = this.props
  return (
        <WheelPicker
          selectedIndex={this.state.selectedIndex}
          options={items}
          onChange={this.onItemSelected}
          visibleRest={compactLayout ? 1 : undefined}
          itemHeight={ITEM_HEIGHT}
          itemTextStyle={styles.itemText}
        />
  )
}
...
c-goettert commented 1 year ago

Never mind - I suspect the error was in our implementation, in which the default or initial value was -1 in some cases. Therefore, I close the issue.