mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-07 13:05:18 +08:00
Enable developers to force Fresco to resize an image
Summary: Here's a little background. Resizing is inferior to scaling. See http://frescolib.org/docs/resizing-rotating.html#_ Currently, React Native has a heuristic to use resize when the image is likely to be from the device's camera. However, there may be other cases where a developer wants to use resize. For example, when the developer knows they'll be downloading a large image from a service but the image will be rendered at a small size on the device. This change adds a `resizeMethod` prop to the `Image` component so developers can choose how Fresco resizes the image. The options are 'auto', 'resize', or 'scale'. When 'auto' is specified, a heuristic is used to choose between 'resize' and 'scale'. The default value is 'auto'. **Test plan (required)** In a small test app, verified that the `resizeMethod` prop properly influences the mechanism that is used to resize the image (e.g. resize or scale). Adam Comella Microsoft Corp. Closes https://github.com/facebook/react-native/pull/9652 Differential Revision: D3841322 Pulled By: foghina fbshipit-source-id: 6c78b5c75ea73053aa10386afd4cbff45f5b8ffe
This commit is contained in:
committed by
Facebook Github Bot
parent
ea5b335351
commit
b6735f3391
@@ -65,6 +65,7 @@ function generateRequestId() {
|
||||
var ImageViewAttributes = merge(ReactNativeViewAttributes.UIView, {
|
||||
src: true,
|
||||
loadingIndicatorSrc: true,
|
||||
resizeMethod: true,
|
||||
resizeMode: true,
|
||||
progressiveRenderingEnabled: true,
|
||||
fadeDuration: true,
|
||||
@@ -130,6 +131,26 @@ var Image = React.createClass({
|
||||
* Used to locate this view in end-to-end tests.
|
||||
*/
|
||||
testID: PropTypes.string,
|
||||
/**
|
||||
* The mechanism that should be used to resize the image when the image's dimensions
|
||||
* differ from the image view's dimensions. Defaults to `auto`.
|
||||
*
|
||||
* - `auto`: Use heuristics to pick between `resize` and `scale`.
|
||||
*
|
||||
* - `resize`: A software operation which changes the encoded image in memory before it
|
||||
* gets decoded. This should be used instead of `scale` when the image is much larger
|
||||
* than the view.
|
||||
*
|
||||
* - `scale`: The image gets drawn downscaled or upscaled. Compared to `resize`, `scale` is
|
||||
* faster (usually hardware accelerated) and produces higher quality images. This
|
||||
* should be used if the image is smaller than the view. It should also be used if the
|
||||
* image is slightly bigger than the view.
|
||||
*
|
||||
* More details about `resize` and `scale` can be found at http://frescolib.org/docs/resizing-rotating.html.
|
||||
*
|
||||
* @platform android
|
||||
*/
|
||||
resizeMethod: PropTypes.oneOf(['auto', 'resize', 'scale']),
|
||||
/**
|
||||
* Determines how to resize the image when the frame doesn't match the raw
|
||||
* image dimensions.
|
||||
|
||||
Reference in New Issue
Block a user