Skip to content
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

fix image props for web #26452

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
10 changes: 2 additions & 8 deletions src/components/Image/imagePropTypes.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import PropTypes from 'prop-types';
import stylePropTypes from '../../styles/stylePropTypes';
import sourcePropTypes from './sourcePropTypes';
import RESIZE_MODES from './resizeModes';

const imagePropTypes = {
/** Styles for the Image */
style: stylePropTypes,

/** The static asset or URI source of the image */
source: PropTypes.oneOfType([
PropTypes.number,
PropTypes.shape({
uri: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
// eslint-disable-next-line react/forbid-prop-types
headers: PropTypes.object,
}),
]).isRequired,
source: sourcePropTypes.isRequired,

/** Should an auth token be included in the image request */
isAuthTokenRequired: PropTypes.bool,
Expand Down
3 changes: 0 additions & 3 deletions src/components/Image/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ function Image(props) {
const {source, isAuthTokenRequired, session, ...rest} = props;

let imageSource = source;
if (source && source.uri && typeof source.uri === 'number') {
imageSource = source.uri;
}
shubham1206agra marked this conversation as resolved.
Show resolved Hide resolved
if (typeof imageSource !== 'number' && isAuthTokenRequired) {
const authToken = lodashGet(props, 'session.encryptedAuthToken', null);
imageSource = {
Expand Down
11 changes: 11 additions & 0 deletions src/components/Image/sourcePropTypes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import PropTypes from 'prop-types';

export default PropTypes.oneOfType([
PropTypes.number,
PropTypes.shape({
uri: PropTypes.string.isRequired,
// eslint-disable-next-line react/forbid-prop-types
headers: PropTypes.object,
}),
PropTypes.string,
shubham1206agra marked this conversation as resolved.
Show resolved Hide resolved
]);
10 changes: 10 additions & 0 deletions src/components/Image/sourcePropTypes/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import PropTypes from 'prop-types';

export default PropTypes.oneOfType([
PropTypes.number,
PropTypes.shape({
uri: PropTypes.string.isRequired,
// eslint-disable-next-line react/forbid-prop-types
headers: PropTypes.object,
}),
]);
8 changes: 5 additions & 3 deletions src/components/ReportActionItem/ReportActionItemImage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import lodashGet from 'lodash/get';
import styles from '../../styles/styles';
import Image from '../Image';
import ThumbnailImage from '../ThumbnailImage';
Expand All @@ -10,13 +11,14 @@ import {ShowContextMenuContext} from '../ShowContextMenuContext';
import Navigation from '../../libs/Navigation/Navigation';
import PressableWithoutFocus from '../Pressable/PressableWithoutFocus';
import useLocalize from '../../hooks/useLocalize';
import sourcePropTypes from '../Image/sourcePropTypes';

const propTypes = {
/** thumbnail URI for the image */
thumbnail: PropTypes.string,

/** URI for the image or local numeric reference for the image */
image: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
image: sourcePropTypes.isRequired,

/** whether or not to enable the image preview modal */
enablePreviewModal: PropTypes.bool,
Expand All @@ -37,7 +39,7 @@ function ReportActionItemImage({thumbnail, image, enablePreviewModal}) {
const {translate} = useLocalize();

if (thumbnail) {
const imageSource = tryResolveUrlFromApiRoot(image);
const imageSource = tryResolveUrlFromApiRoot(lodashGet(image, 'uri', image));
const thumbnailSource = tryResolveUrlFromApiRoot(thumbnail);
const thumbnailComponent = (
<ThumbnailImage
Expand Down Expand Up @@ -72,7 +74,7 @@ function ReportActionItemImage({thumbnail, image, enablePreviewModal}) {

return (
<Image
source={{uri: image}}
source={image}
style={[styles.w100, styles.h100]}
/>
);
Expand Down
3 changes: 2 additions & 1 deletion src/components/ReportActionItem/ReportActionItemImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import _ from 'underscore';
import styles from '../../styles/styles';
import Text from '../Text';
import ReportActionItemImage from './ReportActionItemImage';
import sourcePropTypes from '../Image/sourcePropTypes';

const propTypes = {
/** array of image and thumbnail URIs */
images: PropTypes.arrayOf(
PropTypes.shape({
thumbnail: PropTypes.string,
image: PropTypes.string,
image: sourcePropTypes,
}),
).isRequired,

Expand Down
4 changes: 2 additions & 2 deletions src/libs/ReceiptUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ function getThumbnailAndImageURIs(path, filename) {

// For local files, we won't have a thumbnail yet
if (isReceiptImage && (path.startsWith('blob:') || path.startsWith('file:'))) {
return {thumbnail: null, image: path};
return {thumbnail: null, image: {uri: path}};
}

if (isReceiptImage) {
return {thumbnail: `${path}.1024.jpg`, image: path};
return {thumbnail: `${path}.1024.jpg`, image: {uri: path}};
shubham1206agra marked this conversation as resolved.
Show resolved Hide resolved
}

const {fileExtension} = FileUtils.splitExtensionFromFileName(filename);
Expand Down
Loading