initialScrollToIndex does not work when input data size is reduced
See original GitHub issueFollowing 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
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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:7 (1 by maintainers)
Top 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 >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
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 ?