From d4e405485bb63d96bdc8a1ab920291612e6b755f Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Wed, 20 May 2020 22:17:49 +0200 Subject: [PATCH] Do not preload images with FastImage (#4315) Co-authored-by: Elias Nahum --- .../file_attachment_image.js | 27 +++---------------- .../markdown/markdown_image/markdown_image.js | 1 - .../message_attachments/attachment_author.js | 8 ------ .../message_attachments/attachment_footer.js | 8 ------ .../post_attachment_opengraph.js | 2 -- .../profile_picture/profile_picture.js | 2 -- .../progressive_image.test.js | 4 --- app/components/team_icon/team_icon.js | 1 - test/setup.js | 7 ----- 9 files changed, 3 insertions(+), 57 deletions(-) diff --git a/app/components/file_attachment_list/file_attachment_image.js b/app/components/file_attachment_list/file_attachment_image.js index 511a6588e1..7f43903973 100644 --- a/app/components/file_attachment_list/file_attachment_image.js +++ b/app/components/file_attachment_list/file_attachment_image.js @@ -7,7 +7,6 @@ import { View, StyleSheet, } from 'react-native'; -import FastImage from 'react-native-fast-image'; import brokenImageIcon from '@assets/images/icons/brokenimage.png'; import ProgressiveImage from '@components/progressive_image'; @@ -49,29 +48,9 @@ export default class FileAttachmentImage extends PureComponent { resizeMethod: 'resize', }; - constructor(props) { - super(props); - - const {file} = props; - if (file && file.id && !file.localPath) { - const headers = Client4.getOptions({}).headers; - - const preloadImages = [ - {uri: Client4.getFileThumbnailUrl(file.id), headers}, - {uri: Client4.getFileUrl(file.id), headers}, - ]; - - if (isGif(file)) { - preloadImages.push({uri: Client4.getFilePreviewUrl(file.id), headers}); - } - - FastImage.preload(preloadImages); - } - - this.state = { - failed: false, - }; - } + state = { + failed: false, + }; boxPlaceholder = () => { if (this.props.isSingleImage) { diff --git a/app/components/markdown/markdown_image/markdown_image.js b/app/components/markdown/markdown_image/markdown_image.js index d646a30c0c..becde228c8 100644 --- a/app/components/markdown/markdown_image/markdown_image.js +++ b/app/components/markdown/markdown_image/markdown_image.js @@ -77,7 +77,6 @@ export default class MarkdownImage extends ImageViewPort { uri = EphemeralStore.currentServerUrl + uri; } - FastImage.preload([{uri}]); return uri; }; diff --git a/app/components/message_attachments/attachment_author.js b/app/components/message_attachments/attachment_author.js index 923feecaef..c9b408a604 100644 --- a/app/components/message_attachments/attachment_author.js +++ b/app/components/message_attachments/attachment_author.js @@ -16,14 +16,6 @@ export default class AttachmentAuthor extends PureComponent { theme: PropTypes.object.isRequired, }; - constructor(props) { - super(props); - - if (props.icon) { - FastImage.preload([{uri: props.icon}]); - } - } - openLink = () => { const {link} = this.props; if (link && Linking.canOpenURL(link)) { diff --git a/app/components/message_attachments/attachment_footer.js b/app/components/message_attachments/attachment_footer.js index 5542f89f47..9e0a140b12 100644 --- a/app/components/message_attachments/attachment_footer.js +++ b/app/components/message_attachments/attachment_footer.js @@ -17,14 +17,6 @@ export default class AttachmentFooter extends PureComponent { theme: PropTypes.object.isRequired, }; - constructor(props) { - super(props); - - if (props.icon) { - FastImage.preload([{uri: props.icon}]); - } - } - render() { const { text, diff --git a/app/components/post_attachment_opengraph/post_attachment_opengraph.js b/app/components/post_attachment_opengraph/post_attachment_opengraph.js index 93c1517b6f..0140b1dc01 100644 --- a/app/components/post_attachment_opengraph/post_attachment_opengraph.js +++ b/app/components/post_attachment_opengraph/post_attachment_opengraph.js @@ -110,8 +110,6 @@ export default class PostAttachmentOpenGraph extends PureComponent { dimensions = calculateDimensions(ogImage.height, ogImage.width, this.getViewPostWidth()); } - FastImage.preload([{uri: imageUrl}]); - return { hasImage: true, ...dimensions, diff --git a/app/components/profile_picture/profile_picture.js b/app/components/profile_picture/profile_picture.js index 7399e725fe..b4ad006ec7 100644 --- a/app/components/profile_picture/profile_picture.js +++ b/app/components/profile_picture/profile_picture.js @@ -61,7 +61,6 @@ export default class ProfilePicture extends PureComponent { this.setImageURL(imageUri); } else if (user) { const uri = Client4.getProfilePictureUrl(user.id, user.last_picture_update); - FastImage.preload([{uri, headers: Client4.getOptions({}).headers}]); this.setImageURL(uri); this.clearProfileImageUri(); @@ -102,7 +101,6 @@ export default class ProfilePicture extends PureComponent { if (nextUrl && url !== nextUrl) { // empty function is so that promise unhandled is not triggered in dev mode - FastImage.preload([{uri: nextUrl, headers: Client4.getOptions({}).headers}]); this.setImageURL(nextUrl); this.clearProfileImageUri(); } diff --git a/app/components/progressive_image/progressive_image.test.js b/app/components/progressive_image/progressive_image.test.js index ead3f23ec8..abf9c2104e 100644 --- a/app/components/progressive_image/progressive_image.test.js +++ b/app/components/progressive_image/progressive_image.test.js @@ -8,10 +8,6 @@ import Preferences from '@mm-redux/constants/preferences'; import ProgressiveImage from './progressive_image'; -jest.mock('react-native-fast-image', () => ({ - preload: jest.fn(), -})); - jest.useFakeTimers(); describe('ProgressiveImage', () => { diff --git a/app/components/team_icon/team_icon.js b/app/components/team_icon/team_icon.js index 3365294e66..27391c74e2 100644 --- a/app/components/team_icon/team_icon.js +++ b/app/components/team_icon/team_icon.js @@ -54,7 +54,6 @@ export default class TeamIcon extends React.PureComponent { preloadTeamIcon = (teamId, lastIconUpdate) => { const uri = Client4.getTeamIconUrl(teamId, lastIconUpdate); - FastImage.preload([{uri, headers: Client4.getOptions({}).headers}]); this.setImageURL(uri); }; diff --git a/test/setup.js b/test/setup.js index 5e1fa6655e..ab4b8b5c6b 100644 --- a/test/setup.js +++ b/test/setup.js @@ -119,13 +119,6 @@ jest.mock('react-native-device-info', () => { }; }); -jest.mock('react-native-fast-image', () => { - const FastImage = jest.requireActual('react-native-fast-image').default; - FastImage.preload = jest.fn(); - - return FastImage; -}); - jest.mock('rn-fetch-blob', () => ({ fs: { dirs: {