-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Prop Placeholder to make a progressive image #76
Comments
I can make a pull request if you want! |
I believe you can handle this already with the export default class ProgresiveLoading extends PureComponent {
static propTypes = {
thumb: string.isRequired
}
state = { ready: false };
handleOnGenerate(src) {
const buffer = new Image(); // Here is the secret! :)
buffer.onload = () => this.setState({ ready: true });
buffer.src = src;
}
render() {
const { thumb } = this.props;
const { ready } = this.state;
return (
<div className="progressive-loading">
<div className="progressive-loading-wrapper">
<img src={thumb} className={classNames("thumb", { hide: ready })} />
<StaticGoogleMap onGenerate={this.handleOnGenerate} style={{ display: ready ? '' : 'none' }}>
<Marker location="6.4488387,3.5496361" />
</StaticGoogleMap>
</div>
</div>
)
}
} |
I am going to close this and then open a new issue for "Add progressive image loading" to the docs. |
I have recently implemented this in my own apps and I wanted to revisit this issue. The trick is to actually use the To accomplish this, you want to hide (display: 'none') the Below is a bit more complex example. This example uses Bootstrap 4 classes, but could use any CSS/style. There is some crafty CSS going on here with the "intrinsic placeholder" (the div with paddingBottom set to the aspectRatio), rather than a placeholder image. That div acts like an export class MapImage extends React.Component {
state = { status: 'loading' };
render() {
const { status } = this.state;
const [width, height] = this.props.size.split('x').map(Number);
const aspectRatio = (height / width) * 100;
const { className, ...rest } = this.props;
return (
<div
className="bg-light"
style={{
paddingBottom: `${aspectRatio}%`,
position: 'relative'
}}
>
<div
style={{
position: 'absolute',
left: 0,
top: 0,
right: 0,
bottom: 0
}}
>
{status === 'error' && (
<div className="d-flex h-100 w-100 align-items-center justify-content-center animated fadeIn fast">
<p className="text-muted mb-0">Image not available</p>
</div>
)}
<StaticGoogleMap
apiKey={process.env.REACT_APP_GOOGLE_MAPS_KEY}
className={`${className} ${
status !== 'loaded' ? 'd-none' : 'animated fadeIn faster'
}`}
onLoad={() => this.setState({ status: 'loaded' })}
onError={() => this.setState({ status: 'error' })}
{...rest}
/>
</div>
</div>
);
}
} |
https://medium.com/front-end-weekly/progressive-image-loading-and-intersectionobserver-d0359b5d90cd#:~:text=What%20is%20Progressive%20Image%20Loading,placeholder%20to%20the%20original%20picture.
The text was updated successfully, but these errors were encountered: