-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32700 from Expensify/revert-13036-kidroca/feature…
…/react-native-web-image-headers [CP Staging + Prod] Revert "Image Web/Desktop: Add support for http headers" (cherry picked from commit c1877ed)
- Loading branch information
1 parent
5af7f1a
commit decca28
Showing
8 changed files
with
101 additions
and
250 deletions.
There are no files selected for viewing
200 changes: 0 additions & 200 deletions
200
patches/react-native-web+0.19.9+005+image-header-support.patch
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import lodashGet from 'lodash/get'; | ||
import React from 'react'; | ||
import RNFastImage from 'react-native-fast-image'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import {defaultProps, imagePropTypes} from './imagePropTypes'; | ||
import RESIZE_MODES from './resizeModes'; | ||
|
||
const dimensionsCache = new Map(); | ||
|
||
function resolveDimensions(key) { | ||
return dimensionsCache.get(key); | ||
} | ||
|
||
function Image(props) { | ||
// eslint-disable-next-line react/destructuring-assignment | ||
const {source, isAuthTokenRequired, session, ...rest} = props; | ||
|
||
let imageSource = source; | ||
if (source && source.uri && typeof source.uri === 'number') { | ||
imageSource = source.uri; | ||
} | ||
if (typeof imageSource !== 'number' && isAuthTokenRequired) { | ||
const authToken = lodashGet(props, 'session.encryptedAuthToken', null); | ||
imageSource = { | ||
...source, | ||
headers: authToken | ||
? { | ||
[CONST.CHAT_ATTACHMENT_TOKEN_KEY]: authToken, | ||
} | ||
: null, | ||
}; | ||
} | ||
|
||
return ( | ||
<RNFastImage | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...rest} | ||
source={imageSource} | ||
onLoad={(evt) => { | ||
const {width, height} = evt.nativeEvent; | ||
dimensionsCache.set(source.uri, {width, height}); | ||
if (props.onLoad) { | ||
props.onLoad(evt); | ||
} | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
Image.propTypes = imagePropTypes; | ||
Image.defaultProps = defaultProps; | ||
Image.displayName = 'Image'; | ||
const ImageWithOnyx = withOnyx({ | ||
session: { | ||
key: ONYXKEYS.SESSION, | ||
}, | ||
})(Image); | ||
ImageWithOnyx.resizeMode = RESIZE_MODES; | ||
ImageWithOnyx.resolveDimensions = resolveDimensions; | ||
|
||
export default ImageWithOnyx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.