Fixed profile page refreshing issue

This commit is contained in:
Mustafa Buyukcelebi 2019-06-20 12:18:55 +03:00
parent c7783aa24b
commit b8b019c33e
3 changed files with 31 additions and 17 deletions

View File

@ -47,11 +47,12 @@ class PostsView extends Component {
}
componentWillReceiveProps(nextProps) {
const { currentAccountUsername } = this.props;
const { currentAccountUsername, changeForceLoadPostState } = this.props;
if (
currentAccountUsername !== nextProps.currentAccountUsername &&
nextProps.currentAccountUsername
(currentAccountUsername !== nextProps.currentAccountUsername &&
nextProps.currentAccountUsername) ||
nextProps.forceLoadPost
) {
// Set all initial data (New user new rules)
this.setState(
@ -68,6 +69,9 @@ class PostsView extends Component {
},
() => {
this._loadPosts();
if (changeForceLoadPostState) {
changeForceLoadPostState(false);
}
},
);
}
@ -281,7 +285,7 @@ class PostsView extends Component {
tintColor={!isDarkTheme ? '#357ce6' : '#96c0ff'}
titleColor="#fff"
colors={['#fff']}
/>
/>
}
ref={ref => {
this.flatList = ref;

View File

@ -44,6 +44,7 @@ class ProfileContainer extends Component {
isReverseHeader,
user: null,
selectedQuickProfile: null,
forceLoadPost: false,
};
}
@ -75,7 +76,7 @@ class ProfileContainer extends Component {
};
componentWillReceiveProps(nextProps) {
const { navigation, currentAccount, activeBottomTab, isLoggedIn } = this.props;
const { activeBottomTab, currentAccount, isLoggedIn, navigation } = this.props;
const currentUsername =
currentAccount.name !== nextProps.currentAccount.name && nextProps.currentAccount.name;
@ -84,15 +85,13 @@ class ProfileContainer extends Component {
return;
}
if (currentUsername) {
this._loadProfile(currentUsername);
}
if (
activeBottomTab !== nextProps.activeBottomTab &&
nextProps.activeBottomTab === 'ProfileTabbar'
(activeBottomTab !== nextProps.activeBottomTab &&
nextProps.activeBottomTab === ROUTES.TABBAR.PROFILE) ||
currentUsername
) {
this._loadProfile(currentAccount.name);
this.setState({ forceLoadPost: true });
}
}
@ -334,6 +333,10 @@ class ProfileContainer extends Component {
}
};
_changeForceLoadPostState = value => {
this.setState({ forceLoadPost: value });
};
render() {
const {
avatar,
@ -349,6 +352,7 @@ class ProfileContainer extends Component {
selectedQuickProfile,
user,
username,
forceLoadPost,
} = this.state;
const { isDarkTheme, isLoggedIn, currency, navigation } = this.props;
const activePage = (navigation.state.params && navigation.state.params.activePage) || 0;
@ -379,6 +383,8 @@ class ProfileContainer extends Component {
selectedQuickProfile={selectedQuickProfile}
selectedUser={user}
username={username}
forceLoadPost={forceLoadPost}
changeForceLoadPostState={this._changeForceLoadPostState}
/>
);
}

View File

@ -84,6 +84,8 @@ class ProfileScreen extends PureComponent {
selectedUser,
username,
activePage,
forceLoadPost,
changeForceLoadPostState,
} = this.props;
const {
@ -206,6 +208,8 @@ class ProfileScreen extends PureComponent {
tag={username}
key={username}
handleOnScroll={this._handleOnScroll}
forceLoadPost={forceLoadPost}
changeForceLoadPostState={changeForceLoadPostState}
/>
</View>
<View