-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iOS: Support HTTP headers for source prop on <Image> components
Summary: Allows developers to specify headers to include in the HTTP request when fetching a remote image. For example, one might leverage this when fetching an image from an endpoint that requires authentication: ``` <Image style={styles.logo} source={{ uri: 'http://facebook.github.io/react/img/logo_og.png', headers: { Authorization: 'someAuthToken' } }} /> ``` Note that the header values must be strings. Works on iOS and Android. **Test plan (required)** - Ran a small example like the one above on iOS and Android and ensured the headers were sent to the server. - Ran a small example to ensure that \<Image\> components without headers still work. - Currently using this code in our app. Adam Comella Microsoft Corp. Closes #7338 Reviewed By: javache Differential Revision: D3371458 Pulled By: nicklockwood fbshipit-source-id: cdb24fe2572c3ae3ba82c86ad383af6d85157e20
- Loading branch information
Adam Comella
authored and
Facebook Github Bot 1
committed
Jun 1, 2016
1 parent
cec913e
commit ee8496f
Showing
12 changed files
with
331 additions
and
142 deletions.
There are no files selected for viewing
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
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,56 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ImageSourcePropType | ||
* @no-flow | ||
*/ | ||
'use strict'; | ||
|
||
const PropTypes = require('ReactPropTypes'); | ||
|
||
const ImageSourcePropType = PropTypes.oneOfType([ | ||
PropTypes.shape({ | ||
/** | ||
* `uri` is a string representing the resource identifier for the image, which | ||
* could be an http address, a local file path, or the name of a static image | ||
* resource (which should be wrapped in the `require('./path/to/image.png')` | ||
* function). | ||
*/ | ||
uri: PropTypes.string, | ||
/** | ||
* `method` is the HTTP Method to use. Defaults to GET if not specified. | ||
*/ | ||
method: PropTypes.string, | ||
/** | ||
* `headers` is an object representing the HTTP headers to send along with the | ||
* request for a remote image. | ||
*/ | ||
headers: PropTypes.objectOf(PropTypes.string), | ||
/** | ||
* `body` is the HTTP body to send with the request. This must be a valid | ||
* UTF-8 string, and will be sent exactly as specified, with no | ||
* additional encoding (e.g. URL-escaping or base64) applied. | ||
*/ | ||
body: PropTypes.string, | ||
/** | ||
* `width` and `height` can be specified if known at build time, in which case | ||
* these will be used to set the default `<Image/>` component dimensions. | ||
*/ | ||
width: PropTypes.number, | ||
height: PropTypes.number, | ||
/** | ||
* `scale` is used to indicate the scale factor of the image. Defaults to 1.0 if | ||
* unspecified, meaning that one image pixel equates to one display point / DIP. | ||
*/ | ||
scale: PropTypes.number, | ||
}), | ||
// Opaque type returned by require('./image.jpg') | ||
PropTypes.number, | ||
]); | ||
|
||
module.exports = ImageSourcePropType; |
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.