[v1] Component remounts on Pop!
I am facing issues when I go from Product Details to Product Screen. I have implemented a back button which calls this.props.navigator.pop();. If I tap the back button, it does go to the Product Screen, but the Product List Component unmounts and remounts and reloads the entire data. which should not be the case!. I am facing this issue on Android only, iOS works perfectly and there is no reload as well as the scroll position of the list retains. The problem is only appearing in Android.
Here is the code:
Product Screen:
import React, { Component } from 'react';
import { View } from 'react-native';
import ProductComponent from '../../components/product/product.component';
import { Container } from 'native-base';
import HeaderComponent from '../../components/header/header.component';
class ProductScreen extends Component {
constructor(props){
super(props);
}
render(){
return(
<Container>
<HeaderComponent title={"Products"} back={this.props.back} userMenu={true} navigator={this.props.navigator} />
<View style={{flex: 1}}>
<ProductComponent navigator={this.props.navigator} />
</View>
</Container>
);
}
}
export default ProductScreen;
Product List Component:
import React, { Component } from 'react';
import {connect} from 'react-redux';
import { Image, StyleSheet, View, RefreshControl, FlatList } from 'react-native';
import { Text, Button } from 'native-base';
import {getProducts} from '../../store/actions/index';
import ProductDetailsComponent from './ProductDetailsComponent.component';
class ProductComponent extends Component{
constructor(props){
super(props);
this.loadProducts=this.loadProducts.bind(this);
}
componentDidMount(){
this.loadProducts();
}
loadProducts(){
this.props.onLoadProducts();
}
_onRefresh() {
this.props.onLoadProducts();
}
render(){
return(
<View>
<FlatList
numColumns={1}
refreshControl={
<RefreshControl
onRefresh={this._onRefresh.bind(this)}
/>
}
data={this.props.products}
renderItem={({ item }) => (
item.product ?
<ProductDetailsComponent item={item} navigator={this.props.navigator} />
: null
)}
keyExtractor={(item) => item.id}
/>
</View>
);
}
}
const mapStateToProps = (state) => {
return {
user: state.auth.user,
products: state.products.products
}
}
const mapDispatchToProps = (dispatch) => {
return {
onLoadProducts: () => dispatch(getProducts())
};
}
export default connect(mapStateToProps, mapDispatchToProps)(ProductComponent);
React Native version: 0.53.0 Using React Native Navigation version: 1.1.375 Along with Redux and Axios
Kindly help :-).
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest version and report back. Thank you for your contributions.
The issue has been closed for inactivity.