PLT-7048 Changed MarkdownImage to scroll post list as soon as it knows its height (#6916)
Этот коммит содержится в:
коммит произвёл
Saturnino Abril
родитель
62f925b059
Коммит
96d7783d36
@@ -1,19 +1,67 @@
|
|||||||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
import React, {PureComponent} from 'react';
|
import PropTypes from 'prop-types';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
import {postListScrollChange} from 'actions/global_actions.jsx';
|
import {postListScrollChange} from 'actions/global_actions.jsx';
|
||||||
|
|
||||||
export default class MarkdownImage extends PureComponent {
|
const WAIT_FOR_HEIGHT_TIMEOUT = 100;
|
||||||
handleLoad = () => {
|
|
||||||
postListScrollChange();
|
export default class MarkdownImage extends React.PureComponent {
|
||||||
|
static propTypes = {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The href of the image to be loaded
|
||||||
|
*/
|
||||||
|
href: PropTypes.string
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.heightTimeout = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.waitForHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps) {
|
||||||
|
if (this.props.href !== prevProps.href) {
|
||||||
|
this.waitForHeight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this.stopWaitingForHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
waitForHeight = () => {
|
||||||
|
if (this.refs.image.height) {
|
||||||
|
postListScrollChange();
|
||||||
|
|
||||||
|
this.heightTimeout = 0;
|
||||||
|
} else {
|
||||||
|
this.heightTimeout = setTimeout(this.waitForHeight, WAIT_FOR_HEIGHT_TIMEOUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stopWaitingForHeight = () => {
|
||||||
|
if (this.heightTimeout !== 0) {
|
||||||
|
clearTimeout(this.heightTimeout);
|
||||||
|
this.heightTimeout = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const props = {...this.props};
|
return (
|
||||||
props.onLoad = this.handleLoad;
|
<img
|
||||||
|
{...this.props}
|
||||||
return <img {...props}/>;
|
ref='image'
|
||||||
|
onLoad={this.stopWaitingForHeight}
|
||||||
|
onError={this.stopWaitingForHeight}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user