Fix post with layout to not create new post components (#1611)

This commit is contained in:
Elias Nahum 2018-04-24 15:01:24 -03:00 committed by GitHub
parent 86840f761c
commit 223bd40703
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 16 deletions

View file

@ -17,25 +17,22 @@ function withLayout(WrappedComponent) {
static defaultProps = {
onLayoutCalled: emptyFunction,
}
};
onLayout = (event) => {
const {height} = event.nativeEvent.layout;
this.props.onLayoutCalled(this.props.index, height);
const {shouldCallOnLayout} = this.props;
if (shouldCallOnLayout) {
this.props.onLayoutCalled(this.props.index, height);
}
};
render() {
const {index, onLayoutCalled, shouldCallOnLayout, ...otherProps} = this.props; //eslint-disable-line no-unused-vars
if (shouldCallOnLayout) {
return (
<View onLayout={this.onLayout}>
<WrappedComponent {...otherProps}/>
</View>
);
}
return <WrappedComponent {...otherProps}/>;
return (
<View onLayout={this.onLayout}>
<WrappedComponent {...this.props}/>
</View>
);
}
};
}

View file

@ -49,6 +49,7 @@ export default class ProfilePicture extends PureComponent {
componentWillMount() {
const {edit, imageUri, user} = this.props;
this.mounted = true;
if (edit && imageUri) {
this.setImageURL(imageUri);
@ -65,18 +66,26 @@ export default class ProfilePicture extends PureComponent {
componentWillUpdate(nextProps) {
if (Boolean(nextProps.user) !== Boolean(this.props.user) || nextProps.user.id !== this.props.user.id) {
this.setState({pictureUrl: null});
const nextUser = nextProps.user;
if (this.mounted) {
this.setState({pictureUrl: null});
}
if (nextUser) {
ImageCacheManager.cache('', Client4.getProfilePictureUrl(nextUser.id, nextUser.last_picture_update), this.setImageURL);
}
}
}
componentWillUnmount() {
this.mounted = false;
}
setImageURL = (pictureUrl) => {
this.setState({pictureUrl});
if (this.mounted) {
this.setState({pictureUrl});
}
};
render() {