Correctly load file attachment images (#4160)

* Correctly load file attachment images

* Remove cache control from gallery
This commit is contained in:
Elias Nahum 2020-04-16 16:24:28 -04:00 committed by GitHub
parent fda4948c8c
commit 0c7a2c6fa1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 11 deletions

View file

@ -57,11 +57,16 @@ export default class FileAttachmentImage extends PureComponent {
const {file} = props;
if (file && file.id) {
const preloadImages = [{uri: Client4.getFileThumbnailUrl(file.id)}];
const headers = {
Authorization: `Bearer ${Client4.getToken()}`,
'X-CSRF-Token': Client4.csrf,
'X-Requested-With': 'XMLHttpRequest',
};
if (isGif(file)) {
preloadImages.push({uri: Client4.getFileUrl(file.id)});
}
const preloadImages = [
{uri: Client4.getFileThumbnailUrl(file.id), headers},
{uri: Client4.getFileUrl(file.id), headers},
];
FastImage.preload(preloadImages);
}
@ -94,7 +99,7 @@ export default class FileAttachmentImage extends PureComponent {
imageProps.defaultSource = {uri: file.localPath};
} else if (file.id) {
imageProps.thumbnailUri = Client4.getFileThumbnailUrl(file.id);
imageProps.imageUri = Client4.getFilePreviewUrl(file.id);
imageProps.imageUri = Client4.getFileUrl(file.id);
}
return imageProps;
};
@ -149,6 +154,8 @@ export default class FileAttachmentImage extends PureComponent {
return this.renderSmallImage();
}
const imageProps = this.imageProps(file);
return (
<View
ref={this.handleCaptureRef}
@ -162,7 +169,7 @@ export default class FileAttachmentImage extends PureComponent {
filename={file.name}
resizeMode={resizeMode}
resizeMethod={resizeMethod}
{...this.imageProps(file)}
{...imageProps}
/>
</View>
);

View file

@ -120,10 +120,8 @@ export default class FileAttachmentList extends PureComponent {
let uri;
if (file.localPath) {
uri = file.localPath;
} else if (isGif(file)) {
uri = Client4.getFileUrl(file.id);
} else {
uri = Client4.getFilePreviewUrl(file.id);
uri = Client4.getFileUrl(file.id);
}
results.push({

View file

@ -76,8 +76,7 @@ export default class ProgressiveImage extends PureComponent {
load = () => {
const {imageUri, thumbnailUri} = this.props;
if (thumbnailUri && imageUri) {
FastImage.preload([{uri: imageUri}]);
if (thumbnailUri) {
this.setThumbnail(thumbnailUri);
} else if (imageUri) {
this.setImage(imageUri);