Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Keep showing loading before image really loaded #459

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/image-viewer.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ export default class ImageViewer extends React.Component<Props, State> {
</Wrapper>
);
case 'success':
case 'loadSuccess':
if (!image.props) {
image.props = {};
}
Expand All @@ -520,6 +521,11 @@ export default class ImageViewer extends React.Component<Props, State> {
width,
height
};
image.props.onLoad = () => {
const imageSizes = [...this.state.imageSizes!];
imageSizes[index].status = 'loadSuccess';
this.setState({ imageSizes });
};

if (typeof image.props.source === 'number') {
// source = require(..), doing nothing
Expand Down Expand Up @@ -561,6 +567,17 @@ export default class ImageViewer extends React.Component<Props, State> {
maxScale={this.props.maxScale}
>
{this!.props!.renderImage!(image.props)}
{imageInfo.status === 'success' ? (
<View
style={[
this.styles.loadingContainer,
this.styles.modalContainer,
{ position: 'absolute', width: '100%', height: '100%' }
]}
>
{this!.props!.loadingRender!()}
</View>
) : null}
</ImageZoom>
);
case 'fail':
Expand Down
4 changes: 2 additions & 2 deletions src/image-viewer.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class Props {
*/
public pageAnimateTime?: number = 100;

/**
/**
* 是否启用原生动画驱动
* Whether to use the native code to perform animations.
*/
Expand Down Expand Up @@ -304,5 +304,5 @@ export interface IImageSize {
width: number;
height: number;
// 图片加载状态
status: 'loading' | 'success' | 'fail';
status: 'loading' | 'success' | 'loadSuccess' | 'fail';
}