React-Native scroll to index doesn't work - react-native

In my application, ScrollToIndex doesn't work as expected. Here is my code.
getItemLayout = (data, index) => (
{ length: 50, offset: 50 * index, index }
)
scrollToIndex = () => {
if(this.flatListRef != null){
setTimeout(() => this.flatListRef.scrollToIndex({animated: false, index: 5}), 200)
}
// this.flatListRef.scrollToIndex({animated: true, index: 5});
}
// render post
renderPost({ item, index }) {
return (
<Post
post={item}
likeIsLoading={
item.shareId === this.props.likeLoadingPostId &&
this.props.likeIsLoading
}
likeCount={item.likeCount > 0 ? item.likeCount : ""}
likeIcon={item.hasLiked === 1 ? LikeActive : LikeInactive}
name={item.hasLiked === 1 ? "like-active" : "like-inactive"}
onIconClick={payload => this.onIconClick(payload)}
/>
);
}
// render
render() {
let { posts, featuredWorkouts, mainFeedIsLoading } = this.props;
let mainFeedData = (
<View>
<View style={{ marginBottom: 5 }}>
<SwiperContainer featuredWorkouts={featuredWorkouts} />
</View>
<FlatList
ref={(ref) => { this.flatListRef = ref; }}
data={posts}
extraData={[posts, mainFeedIsLoading, featuredWorkoutsAreLoading]}
renderItem={(item, index) => this.renderPost(item, item.shareId)}
getItemLayout={this.getItemLayout}
// initialScrollIndex={4}
keyExtractor={item => item.shareId}
/>
</View>
);
if (mainFeedIsLoading) {
mainFeedData = (
<View style={styles.screenLoader}>
<ScreenLoader color="lightblue" size="large" />
</View>
);
}
return (
<View>
<Button
onPress={() => this.scrollToIndex()}
title="Tap to scrollToIndex"
color="darkblue"
/>
<ScrollView>{mainFeedData}</ScrollView>
</View>
);
}
I tried the suggestions which have been give on the internet, but none of them worked. What am I doing wrong here? How can I achieve what I want? As an example, I want to move to 5th index when the button is clicked.

Related

React Native FlatList Delete Item

I want to delete item from the FlatList. However, the solution from here is not working for my code. When I run my code, I am getting error such as 'index is not defined'.
I have yet to find other post regarding this issue so any help would be greatly appreciated.
Code snippet provided below:
export default class FrCreateScreen extends Component {
constructor(props) {
super(props);
this.state = {
//new timeSlots
timeSlots: [],
}
}
setEndTime = (event, appointmentEndTime, textEndTime) => {
appointmentEndTime = appointmentEndTime || this.state.appointmentEndTime;
textEndTime = textEndTime || moment(appointmentEndTime).format('h:mm a').toString();
this.setState({
showEndTime: Platform.OS === 'ios' ? true : false,
appointmentEndTime,
textEndTime,
timeSlots: [
...this.state.timeSlots,
{
apptdate: this.state.textAppointmentDate,
appttime: this.state.textAppointmentTime,
endTime: textEndTime,
}
],
});
}
deleteDateTime = (id) => {
const filteredData = this.state.timeSlots.filter(item => item.id !== id);
this.setState({ timeSlots: filteredData });
}
render() {
return (
<ScrollView>
...
<View>
<FlatList
data={this.state.timeSlots}
keyExtractor={({ id }, index) => index.toString()}
renderItem={({ item }) => {
return (
<View style={styles.containerList}>
...
<TouchableOpacity onPress={() => this.deleteDateTime(index)}>
<Feather name="trash" style={styles.icon} />
</TouchableOpacity>
</View>
</View>
);
}}
/>
</View>
</ScrollView>
)
};
};
Screenshot below:
I think you need to add index inside renderItem { item, index }
renderItem = {({ item, index }) => {
return (
<View style={styles.containerList}>
<TouchableOpacity onPress={() => this.deleteDateTime(index)}>
<Feather name="trash" style={styles.icon} />
</TouchableOpacity>
</View>
);
}}
While rendering in map function , it provides the index too, so try adding that.
renderItem={({ item,index }) => {
return (
<View style={styles.containerList}>
...
<TouchableOpacity onPress={() => this.deleteDateTime(index)}>
<Feather name="trash" style={styles.icon} />
</TouchableOpacity>
</View>
</View>
);
}}
Hope it helps
ok fixed. on touchable onPress, the argument should be 'item.index' instead of 'index'.
here's the correct code:
renderItem={({ item,index }) => {
return (
<View style={styles.containerList}>
...
<TouchableOpacity onPress={() => this.deleteDateTime(item.index)}>
<Feather name="trash" style={styles.icon} />
</TouchableOpacity>
</View>
</View>
);
}}

Expo : Select Multiple item of flatlist ( change style)

I'm trying to add a badge on a View ,by a TouchableOpacity on press.
The trouble is the animation work appears only on one element at a time and not on two or more simultaneously
Here the code :
Flatlist :
<FlatList
data={this.state.ReturnedArray}
width='100%'
ItemSeparatorComponent={this.FlatListItemSeparator}
keyExtractor={(item, index) => 'key' + index}
renderItem={this.renderizza}
extraData={this.state.activeItem}
/>
Render funtion :
<View style={style.containerFlat}>
<View style={style.containerFlat1}>
<Text style={style.txt}>{item.name} {item.cognome}</Text>
</View>
<TouchableOpacity style={style.containerFlat2} onPress={() => this.badge(item.expoToken,index)}>
{(this.state.activeItem === index) ? <Animated.View style={[style.animatedView, { opacity: this.state.fadeValue }]}><Text>ADDED</Text></Animated.View> : null}
<Text style={style.AvatarTxt} >{acronym}</Text>
</TouchableOpacity>
</View>
Badge function add Token into an array and lunch animation :
badge(chiavi, index) {
if ((this.state.SelectedUser).includes(chiavi)) {
this.Nonanimate(index)
this.state.SelectedUser.splice(this.state.SelectedUser.indexOf(chiavi), 1)
} else {
this.state.SelectedUser.push(chiavi)
this.animate(index)
}
}
and the animation / NotAnimation :
animate = (index) => {
this.setState({
activeItem: index,
});
Animated.timing(this.state.fadeValue, {
toValue: 1,
duration: 0
}).start()
};
Nonanimate = index => {
this.setState({
activeItem: index,
});
Animated.timing(this.state.fadeValue, {
toValue: 0,
duration: 0
}).start()
};
i'm wasting days on this trouble. Suggest ?
Here the function to solve this :
badge = chiavi => {
//console.log(chiavi.item.expoToken)
if ((this.state.SelectedUser).includes(chiavi.item.expoToken)) {
// this.Nonanimate(index)
this.state.SelectedUser.splice(this.state.SelectedUser.indexOf(chiavi.item.expoToken), 1)
} else {
this.state.SelectedUser.push(chiavi.item.expoToken)
// this.animate(index)
}
chiavi.item.isSelect = !chiavi.item.isSelect;
chiavi.item.selectedClass = chiavi.item.isSelect ?
style.selected : style.containerFlat1;
const index = this.state.ReturnedArray.findIndex(
item => chiavi.item.user_id === item.user_id
);
this.state.ReturnedArray[index] = chiavi.item;
this.setState({
ReturnedArray: this.state.ReturnedArray,
});
and Flatlist :
<FlatList
data={this.state.ReturnedArray}
width='100%'
ItemSeparatorComponent={this.FlatListItemSeparator}
keyExtractor={item => item.user_id.toString()}
renderItem={item => this.renderizza(item)}
extraData={this.state}
/>
Source : Link here

My flatlist not rendering without remote debugger

I am working on an app by react native.i have a problem. when my app has a debug mode work very well. but in without debug mode, my Flatlist is not rendering all items.
I'm using redux and redux-saga
class ComponentGroups extends React.Component {
constructor (props){
super(props)
this.state = {
listBanner: this.props.item.listBanner
}
}
eventOnscroll = () => {
console.log('load list banner pls what wrong with u')
}
checkRenderView = () => {
if(this.state.listBanner.length && this.state.listBanner.length === 1) {
return (
<ComponentBanner item={this.state.listBanner[0]} typeTab={1}/>
)
}
const dimensions = Dimensions.get('window');
const screenWidth = dimensions.width;
return (
<ScrollView onScroll={this.eventOnscroll}>
<FlatList
style={{
flex: 1,
width: screenWidth
}}
showsHorizontalScrollIndicator={false}
horizontal={true}
data={this.state.listBanner}
removeClippedSubviews={false}
keyExtractor={(item, index) => index.toString()}
renderItem={({item, index}) => <ComponentBanner item={item} index={index} typeTab={1}/>}
/>
</ScrollView>
)
}
render () {
return (
<View style={styles.bannerItem}>
{this.state.listBanner.length && this.checkRenderView()}
</View>
)
}
}
and my component item:
class ComponentBanner extends React.Component {
constructor (props) {
super(props)
}
handlePressDetailBanner = () => {
detailImageScreen({item: this.props.item, typeTab: 1})
}
showViewNewsViewed = () => {
if(this.props.item.hot && this.props.item.watched) {
return (
<View style={styles.viewsLiked}>
<View style={styles.iconLike}>
<Text style={styles.news}>Mới</Text>
</View>
<View style={styles.iconView}>
<Text style={styles.viewed}>Đã xem</Text>
</View>
</View>
)
}
if(this.props.item.hot && !this.props.item.watched) {
return (
<View style={styles.viewsLiked}>
<View style={styles.iconLike}>
<Text style={styles.news}>Mới</Text>
</View>
</View>
)
}
if(!this.props.item.hot && this.props.item.watched) {
return (
<View style={styles.viewsLiked}>
<View style={styles.iconView}>
<Text style={styles.viewed}>Đã xem</Text>
</View>
</View>
)
}
}
render () {
return (
<View style={styles.bannerItem}>
<TouchableOpacity onPress ={this.handlePressDetailBanner}>
<Image source={{uri: this.props.item.url}} style={styles.imageItem} borderRadius={5} resizeMode='stretch'/>
</TouchableOpacity>
<View style={styles.titleLikes}>
{this.showViewNewsViewed()}
<Text numberOfLines={2} ellipsizeMode='tail' style={styles.textTitle}>{this.props.item.name}</Text>
<View style={styles.viewsLiked}>
<View style={styles.iconLike}>
<Icon
name='thumb-up'
color={this.props.item.userLike? Colors.mpAdvertise : Colors.cloud}
size={Fonts.size.regular}
/>
<Text style={styles.accountLike}>{this.props.item.totalLike}</Text>
</View>
<View style={styles.iconView}>
<Icon
name='eye'
color={Colors.cloud}
size={Fonts.size.regular}
/>
<Text style={styles.accountLike}>{this.props.item.totalView}</Text>
</View>
</View>
</View>
</View>
)
}
}
export default ComponentBanner
and Render Item by :
render () {
return (
<TouchableOpacity onPress ={this.handlePressDetailBanner} style={styles.detailImage}>
<View style={styles.bannerItem}>
<View>
<Image source={{uri: this.props.item.url ? this.props.item.url : ''}} style={styles.imageItem} borderRadius={5} resizeMode='stretch'/>
</View>
<View style={styles.titleLikes}>
<Text numberOfLines={2} ellipsizeMode='tail' style={styles.textTitle}>{this.props.item.name ? this.props.item.name : ''}</Text>
<View style={styles.viewsLiked}>
<View style={styles.iconLike}>
<Icon
name='thumb-up'
color={this.props.item.userLike? Colors.mpAdvertise : Colors.cloud}
size={Fonts.size.regular}
/>
<Text style={styles.accountLike}>{this.props.item.totalLike ? this.props.item.totalLike : ''}</Text>
</View>
<View style={styles.iconView}>
<Icon
name='eye'
color={Colors.cloud}
size={Fonts.size.regular}
/>
<Text style={styles.accountLike}>{this.props.item.totalView ? this.props.item.totalView : ''}</Text>
</View>
</View>
</View>
</View>
</TouchableOpacity>
)
}
}
UPDATE: sorry for forgot main screen rendering ComponentGroups:
constructor (props) {
super(props)
this.state = {
params: {
SourceType: '',
GroupCode: '',
NumOfRec: 10,
PageNum: 1,
TypeId: '',
},
data:[],
groupBanner: '',
groupVideo: '',
mainBanner: '',
listBanners: [],
listVideos: [],
isSelected: 1,
fetching: false,
onEndReachedCalledDuringMomentum: true
}
Navigation.events().bindComponent(this)
this.props.getData()
}
static getDerivedStateFromProps(nextProps, prevState){
if (nextProps.fetching !== prevState.fetching){
return {
fetching: nextProps.fetching,
data: nextProps.data,
listBanners: nextProps.listBanners,
listVideos: nextProps.listVideos
}
}
else return null;
}
componentDidUpdate(prevProps, prevState) {
if (prevState.fetching !== this.state.fetching) {
}
}
componentDidAppear () {
Navigation.mergeOptions(this.props.componentId, {
sideMenu: {
left: {
enabled: true
}
}
})
}
showSideMenu () {
Navigation.mergeOptions(this.props.componentId, {
sideMenu: {
left: {
visible: true
}
}
})
}
navigationButtonPressed ({ buttonId }) {
this.showSideMenu()
}
handlePressScroll = () => {
const {params} = this.state
if(!this.state.fetching) {
this.setState({
params: {
...params,
PageNum: params.PageNum + 1,
}
}, () => {
const data = Object.keys(this.state.params).map(key => key + '=' + this.state.params[key]).join('&')
console.log(data)
if(this.state.isSelected === 2) {
this.props.getDataBanner(data)
}
if(this.state.isSelected === 3) {
this.props.getDataVideo(data)
}
})
} else {
return null
}
}
handlePressSwitchTab = (value) => {
this.setState({
isSelected: value,
params: {
SourceType: 1,
GroupCode: '',
NumOfRec: 10,
PageNum: 1,
TypeId: 0
},
listBanners: [],
listVideos: [],
},()=>{
if(value === 1) {
this.props.resetStateHome()
this.props.getData()
}
if(value === 2) {
this.props.resetStateHome()
const data = Object.keys(this.state.params).map(key => key + '=' + this.state.params[key]).join('&')
this.props.getDataBanner(data)
}
if(value === 3) {
this.props.resetStateHome()
const data = Object.keys(this.state.params).map(key => key + '=' + this.state.params[key]).join('&')
this.props.getDataVideo(data)
}
})
}
formatData = (data, numColumns) => {
const numberOfFullRows = Math.floor(data.length / numColumns)
let numberOfElementsLastRow = data.length - (numberOfFullRows * numColumns)
while (numberOfElementsLastRow !== numColumns && numberOfElementsLastRow !== 0) {
data.push({ key: `blank-${numberOfElementsLastRow}`, empty: true })
numberOfElementsLastRow++
}
return data
}
handlePressBanner = () => {
detailImageScreen({item: this.state.data.mainBanner})
}
eventScroll = () => {
console.log(45544)
}
renderViewByState = () => {
const numColumns = 2;
if(this.state.data && this.state.data.mainBanner && this.state.data.mainBanner.url) {
var url = this.state.data.mainBanner.url
}
if (this.state.isSelected === 1) {
if(this.state.fetching) {
return (
<View style={styles.styleLoadMore}>
<BallIndicator color={Colors.mpAdvertise} animationDuration={800} />
</View>
)
} else {
return (
<ScrollView onScroll={this.eventScroll} >
<View style={styles.centered}>
<TouchableOpacity onPress={this.handlePressBanner} style={styles.mainBannerImage}>
<Image source={{uri: url}} style={styles.logo} borderRadius={5} resizeMode='stretch'/>
</TouchableOpacity>
</View>
<View style={styles.containerContent}>
<View style={styles.sectionBanner} >
<View>
<Text style={styles.textBanner}>BANNERS</Text>
</View>
<View style={styles.listBanner}>
<FlatList
data={this.state.data.groupBanner}
keyExtractor={(item, index) => index.toString()}
renderItem={({item, index}) => <ComponentGroups item={item} index={index} />}
/>
</View>
</View>
<View style={styles.sectionBanner} >
<View>
<Text style={styles.textBanner}>VIDEOS</Text>
</View>
<View style={styles.listBanner}>
<ScrollView>
<FlatList
data={this.state.data.groupVideo}
keyExtractor={(item, index) => index.toString()}
renderItem={({item, index}) => <ComponentGroupsVideo item={item} index={index} />}
/>
</ScrollView>
</View>
</View>
</View>
</ScrollView>
)
}
}
if (this.state.isSelected === 2) {
if(this.state.fetching && this.state.params.PageNum < 2) {
return (
<View style={styles.styleLoadMore}>
<BallIndicator color={Colors.mpAdvertise} animationDuration={800} />
</View>
)
}
return (
<ScrollView onScroll={this.eventScroll}>
<View style={styles.listBanner}>
<FlatList
extraData={this.state}
ListFooterComponent = {this.renderFooter}
data={this.state.listBanners}
keyExtractor={(item, index) => index.toString()}
renderItem={({item, index}) => <BannerItem item={item} index={index}/>}
numColumns={countNumber}
onEndReached={this.handlePressScroll}
onEndReachedThreshold={0.05}
/>
</View>
</ScrollView>
)
}
if (this.state.isSelected === 3) {
if(this.state.fetching && this.state.params.PageNum < 2) {
return (
<View style={styles.styleLoadMore}>
<BallIndicator color={Colors.mpAdvertise} animationDuration={800} />
</View>
)
}
return (
<View style={styles.listBanner}>
<FlatList
extraData={this.state}
data={this.state.listVideos}
ListFooterComponent = {this.renderFooter}
keyExtractor={(item, index) => index.toString()}
renderItem={({item, index}) => <VideosItem item={item} index={index} typeTab={3}/>}
numColumns={countNumber}
onEndReached={this.handlePressScroll}
onEndReachedThreshold={0.01}
/>
</View>
)
}
}
renderFooter = () => {
if(this.state.fetching && this.props.isStopScroll && this.state.params.PageNum > 1) {
return (
<View style={styles.styleLoadMoreFooter}>
<BallIndicator color={Colors.mpAdvertise} animationDuration={800} />
</View>
)
}
return null
}
render () {
return (
<View style={styles.mainContainer} testID='launchScreen'>
<View style={styles.tabBarHome}>
<View style={[styles.itemTab, this.state.isSelected === 1 ? styles.itemTabActive : null]}>
<TouchableOpacity testID='loginScreenLoginButton' style={styles.loginButtonWrapper} onPress={() => this.handlePressSwitchTab(1)}>
<View style={styles.loginButton}>
<Text style={[styles.itemText, this.state.isSelected === 1 ? styles.itemTextActive : null]}>Nổi bật</Text>
</View>
</TouchableOpacity>
</View>
<View style={[styles.itemTab, this.state.isSelected === 2 ? styles.itemTabActive : null]}>
<TouchableOpacity testID='loginScreenLoginButton' style={styles.loginButtonWrapper} onPress={() => this.handlePressSwitchTab(2)}>
<View style={styles.loginButton}>
<Text style={[styles.itemText, this.state.isSelected === 2 ? styles.itemTextActive : null]}>Banner</Text>
</View>
</TouchableOpacity>
</View>
<View style={[styles.itemTab, this.state.isSelected === 3 ? styles.itemTabActive : null]}>
<TouchableOpacity testID='loginScreenLoginButton' style={styles.loginButtonWrapper} onPress={() => this.handlePressSwitchTab(3)}>
<View style={styles.loginButton}>
<Text style={[styles.itemText, this.state.isSelected === 3 ? styles.itemTextActive : null]}>Videos</Text>
</View>
</TouchableOpacity>
</View>
</View>
{this.renderViewByState()}
</View>
)
}
}
const mapStateToProps = (state) => {
return {
data: state.home.data,
listBanners: state.home.listBanners,
listVideos: state.home.listVideos,
fetching: state.home.fetching,
cart: state.login.dataCart,
isStopScroll: state.home.isStopScroll
}
}
const mapDispatchToProps = (dispatch) => {
return {
getData: () => dispatch(HomeActions.homeRequest()),
getDataBanner: (data) => dispatch(HomeActions.bannerRequest(data)),
getDataVideo: (data) => dispatch(HomeActions.videoRequest(data)),
resetStateHome: () => dispatch(HomeActions.resetStateHome())
}
}
export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen)
The above code, render my item in flatlist .in debug mode working very good, but in release mode, it's not rendering at all
please try this
<FlatList
style={{
flex: 1,
width: screenWidth
}}
extraData={this.state} //<--- add this line
showsHorizontalScrollIndicator={false}
horizontal={true}
data={this.state.listBanner}
removeClippedSubviews={false}
keyExtractor={(item, index) => index.toString()}
renderItem={({item, index}) => <ComponentBanner item={item} index={index} typeTab={1}/>}
/>

Passing values after clicking on the Button - React Native

How can I pass all values inside Render() method after I click on the button Send? Inside this Render() method I return some Flatlists, Views, Signature, etc. So, is it possible to pass all of these values to another page only by a click of a button.
Please let me know if you dont have the question clear so I can add some more explanation.
See below for the code (Edited).
I appreciate any suggestion or help!
EDIT:
renderTextandInputs = (obje) => {
var keyvalue_to_json = JSON.parse(obje.keyValues);
var foundTextFields = [];
for (let i = 0; i < keyvalue_to_json.length; i++) {
if (keyvalue_to_json[i].type === 'textfield') {
foundTextFields.push(<TextInput style={{ borderWidth: 1, flex: 1, alignItems: 'flex-start' }}>{keyvalue_to_json[i].placeholderText}</TextInput>)
}
}
return (
<View>
<ScrollView>
<ListItem
title={obje.name}
subtitle={obje.description}
/>
</ScrollView>
<View >
{foundTextFields}
</View>
</View>
)
}
render() {
const obj = this.props.navigation.state.params.item;
var propsArray = [];
const itemArray = Object.assign(obj)
propsArray.push(itemArray)
keyExtractor = (item, index) => {
return index.toString();
}
return (
<View>
<View>
<FlatList
key={this.keyExtractor}
data={propsArray}
renderItem={({ item }) => this.renderTextandInputs(item)}
/>
</View>
<View >
{this.state.signature ? (
<Image
resizeMode={"contain"}
source={{ uri: this.state.signature }}
/>
) : null}
</View>
<Modal isVisible={this.state.isModalVisible}
onBackdropPress={() => this.setState({ isModalVisible: false })}
>
<Signature
width="100"
onOK={this.handleSignature}
descriptionText="Sign"
clearText="Clear"
confirmText="Save"
webStyle={style}
/>
</Modal>
<View>
<Button title="SIGN" onPress={this._toggleModal} />
</View>
<View>
<Button title="Send" onPress={this._onSendDoc} />
</View>
</View>
);
}
_onSendDoc = (item) => {
this.props.navigation.navigate('Detail', { item: item })
}
}
if you check here: https://facebook.github.io/react-native/docs/flatlist you can render a button per flatlist item like this:
EDIT
_onSendAll = () => {
const obj = this.props.navigation.state.params.item;
var propsArray = [];
const itemArray = Object.assign(obj)
propsArray.push(itemArray)
this.props.navigation.navigate("Detail", { allData: propsArray });
};
_onSendDoc = item => {
this.props.navigation.navigate("Detail", { item: item });
};
render() {
return (
<FlatList
data={[{title: 'Title Text', key: 'item1'}]}
renderItem={({item}) => (
<TouchableHighlight
onPress={() => this._onSendDoc(item)}
<View style={{backgroundColor: 'white'}}>
<Text>{item.title}</Text>
</View>
</TouchableHighlight>
)}
/>
)
On each button clicked, the item data passed will be logged.

ScrollToIndex in React-Native

In my application, I want to use scrollToIndex() which is a method of the FlatList component.
render() {
let { posts, featuredWorkouts, mainFeedIsLoading } = this.props;
let mainFeed = <SwiperContainer featuredWorkouts={featuredWorkouts} />;
let mainFeedData = (
<View>
<View style={{ marginBottom: 5 }}>
<SwiperContainer featuredWorkouts={featuredWorkouts} />
</View>
<FlatList
data={posts}
scrollToIndex={5}
extraData={[posts, mainFeedIsLoading]}
renderItem={item => this.renderPost(item)}
keyExtractor={item => item.shareId}
/>
</View>
);
if (mainFeedIsLoading) {
mainFeedData = (
<View style={styles.screenLoader}>
<ScreenLoader color="lightblue" size="large" />
</View>
);
}
return (
<View>
<ScrollView>{mainFeedData}</ScrollView>
</View>
);
}
As an example, when the page loads, I want to go to the 10th index. How can I achieve this? I tried the scrollToIndex() and it did not work.
you have to add ref to your flat list.
ref={(ref) => { this.list = ref; }}
Also you have to add to scroll index to your componentdidmount.
componentDidMount() {
this.list.scrollToIndex({animated: true, index: tempIndex, viewOffset:0,viewPosition:0});
}
Also you can use:
initialScrollIndex
Well in my case I have to do this to make scrolltoindex work properly,
1.add reference to flatlist:
`
ref={ref => {
this.flatListRef = ref;
}}
`
2. Call scrollToIndex() with timeout:
`
setTimeout(() => {
this.flatListRef.scrollToIndex({
animated: true,
index: this.state.pressedIndex
});
}, 500);
`
3. then call function again inside flatlist
onScrollToIndexFailed={() =>
{
this.scrollToIndex();
}
}