-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Android-specific ImageRequestParams (#47930)
Summary: Pull Request resolved: #47930 This diff adds a list of props that will be used by the Android `ImagePrefetcher` to create an `ImageRequest`. This list is derived from all the props that `ReactImageView` uses to create its `ImageOptions` and `ImageRequest` objects. Changelog: [Internal] Reviewed By: javache Differential Revision: D66453306 fbshipit-source-id: ca4f59784c81f2b94ed4b052f6fbe5e8c6b97a2a
- Loading branch information
1 parent
071d223
commit 318db8e
Showing
6 changed files
with
214 additions
and
33 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
30 changes: 0 additions & 30 deletions
30
...eact-native/ReactCommon/react/renderer/imagemanager/platform/android/ImageRequestParams.h
This file was deleted.
Oops, something went wrong.
File renamed without changes.
94 changes: 94 additions & 0 deletions
94
...t/renderer/imagemanager/platform/android/react/renderer/imagemanager/ImageRequestParams.h
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,94 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <utility> | ||
|
||
#include <react/renderer/graphics/Color.h> | ||
#include <react/renderer/graphics/Float.h> | ||
#include <react/renderer/imagemanager/primitives.h> | ||
|
||
namespace facebook::react { | ||
|
||
class ImageRequestParams { | ||
public: | ||
ImageRequestParams() = default; | ||
ImageRequestParams( | ||
Float blurRadius, | ||
ImageSource defaultSource, | ||
ImageResizeMode resizeMode, | ||
std::string resizeMethod, | ||
Float resizeMultiplier, | ||
bool shouldNotify, | ||
SharedColor overlayColor, | ||
SharedColor tintColor, | ||
Float fadeDuration, | ||
bool progressiveRenderingEnabled, | ||
ImageSource loadingIndicatorSource, | ||
std::string analyticTag) | ||
: blurRadius(blurRadius), | ||
defaultSource(std::move(defaultSource)), | ||
resizeMode(resizeMode), | ||
resizeMethod(std::move(resizeMethod)), | ||
resizeMultiplier(resizeMultiplier), | ||
shouldNotify(shouldNotify), | ||
overlayColor(overlayColor), | ||
tintColor(tintColor), | ||
fadeDuration(fadeDuration), | ||
progressiveRenderingEnabled(progressiveRenderingEnabled), | ||
loadingIndicatorSource(std::move(loadingIndicatorSource)), | ||
analyticTag(std::move(analyticTag)) {} | ||
|
||
Float blurRadius{}; | ||
ImageSource defaultSource{}; | ||
ImageResizeMode resizeMode{ImageResizeMode::Stretch}; | ||
std::string resizeMethod{}; | ||
Float resizeMultiplier{}; | ||
bool shouldNotify{}; | ||
SharedColor overlayColor{}; | ||
SharedColor tintColor{}; | ||
Float fadeDuration{}; | ||
bool progressiveRenderingEnabled{}; | ||
ImageSource loadingIndicatorSource{}; | ||
std::string analyticTag{}; | ||
|
||
bool operator==(const ImageRequestParams& rhs) const { | ||
return std::tie( | ||
this->blurRadius, | ||
this->defaultSource, | ||
this->resizeMode, | ||
this->resizeMethod, | ||
this->resizeMultiplier, | ||
this->shouldNotify, | ||
this->overlayColor, | ||
this->tintColor, | ||
this->fadeDuration, | ||
this->progressiveRenderingEnabled, | ||
this->loadingIndicatorSource, | ||
this->analyticTag) == | ||
std::tie( | ||
rhs.blurRadius, | ||
rhs.defaultSource, | ||
rhs.resizeMode, | ||
rhs.resizeMethod, | ||
rhs.resizeMultiplier, | ||
rhs.shouldNotify, | ||
rhs.overlayColor, | ||
rhs.tintColor, | ||
rhs.fadeDuration, | ||
rhs.progressiveRenderingEnabled, | ||
rhs.loadingIndicatorSource, | ||
rhs.analyticTag); | ||
} | ||
|
||
bool operator!=(const ImageRequestParams& rhs) const { | ||
return !(*this == rhs); | ||
} | ||
}; | ||
|
||
} // namespace facebook::react |
100 changes: 100 additions & 0 deletions
100
...on/react/renderer/imagemanager/platform/android/react/renderer/imagemanager/conversions.h
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,100 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include <react/renderer/core/graphicsConversions.h> | ||
#include <react/renderer/imagemanager/ImageRequestParams.h> | ||
#include <react/renderer/imagemanager/primitives.h> | ||
#include <react/renderer/mapbuffer/MapBuffer.h> | ||
#include <react/renderer/mapbuffer/MapBufferBuilder.h> | ||
|
||
namespace facebook::react { | ||
|
||
inline std::string toString(const ImageResizeMode& value) { | ||
switch (value) { | ||
case ImageResizeMode::Cover: | ||
return "cover"; | ||
case ImageResizeMode::Contain: | ||
return "contain"; | ||
case ImageResizeMode::Stretch: | ||
return "stretch"; | ||
case ImageResizeMode::Center: | ||
return "center"; | ||
case ImageResizeMode::Repeat: | ||
return "repeat"; | ||
case ImageResizeMode::None: | ||
return "none"; | ||
} | ||
} | ||
|
||
constexpr static MapBuffer::Key IS_KEY_URI = 0; | ||
constexpr static MapBuffer::Key IS_KEY_DEFAULT_SRC = 1; | ||
constexpr static MapBuffer::Key IS_KEY_RESIZE_MODE = 2; | ||
constexpr static MapBuffer::Key IS_KEY_RESIZE_METHOD = 3; | ||
constexpr static MapBuffer::Key IS_KEY_BLUR_RADIUS = 4; | ||
constexpr static MapBuffer::Key IS_KEY_VIEW_WIDTH = 5; | ||
constexpr static MapBuffer::Key IS_KEY_VIEW_HEIGHT = 6; | ||
constexpr static MapBuffer::Key IS_KEY_RESIZE_MULTIPLIER = 7; | ||
constexpr static MapBuffer::Key IS_KEY_SHOULD_NOTIFY_LOAD_EVENTS = 8; | ||
constexpr static MapBuffer::Key IS_KEY_OVERLAY_COLOR = 9; | ||
constexpr static MapBuffer::Key IS_KEY_TINT_COLOR = 10; | ||
constexpr static MapBuffer::Key IS_KEY_FADE_DURATION = 11; | ||
constexpr static MapBuffer::Key IS_KEY_PROGRESSIVE_RENDERING_ENABLED = 12; | ||
constexpr static MapBuffer::Key IS_KEY_LOADING_INDICATOR_SRC = 13; | ||
constexpr static MapBuffer::Key IS_KEY_ANALYTIC_TAG = 14; | ||
|
||
inline void serializeImageSource( | ||
MapBufferBuilder& builder, | ||
const ImageSource& imageSource) { | ||
builder.putString(IS_KEY_URI, imageSource.uri); | ||
builder.putDouble(IS_KEY_VIEW_WIDTH, imageSource.size.width); | ||
builder.putDouble(IS_KEY_VIEW_HEIGHT, imageSource.size.height); | ||
} | ||
|
||
inline void serializeImageRequestParams( | ||
MapBufferBuilder& builder, | ||
const ImageRequestParams& imageRequestParams) { | ||
builder.putString(IS_KEY_DEFAULT_SRC, imageRequestParams.defaultSource.uri); | ||
builder.putString( | ||
IS_KEY_RESIZE_MODE, toString(imageRequestParams.resizeMode)); | ||
builder.putString(IS_KEY_RESIZE_METHOD, imageRequestParams.resizeMethod); | ||
builder.putDouble(IS_KEY_BLUR_RADIUS, imageRequestParams.blurRadius); | ||
builder.putDouble( | ||
IS_KEY_RESIZE_MULTIPLIER, imageRequestParams.resizeMultiplier); | ||
builder.putBool( | ||
IS_KEY_SHOULD_NOTIFY_LOAD_EVENTS, imageRequestParams.shouldNotify); | ||
if (isColorMeaningful(imageRequestParams.overlayColor)) { | ||
builder.putInt( | ||
IS_KEY_OVERLAY_COLOR, toAndroidRepr(imageRequestParams.overlayColor)); | ||
} | ||
if (isColorMeaningful(imageRequestParams.tintColor)) { | ||
builder.putInt( | ||
IS_KEY_TINT_COLOR, toAndroidRepr(imageRequestParams.tintColor)); | ||
} | ||
builder.putDouble(IS_KEY_FADE_DURATION, imageRequestParams.fadeDuration); | ||
builder.putBool( | ||
IS_KEY_PROGRESSIVE_RENDERING_ENABLED, | ||
imageRequestParams.progressiveRenderingEnabled); | ||
builder.putString( | ||
IS_KEY_LOADING_INDICATOR_SRC, | ||
imageRequestParams.loadingIndicatorSource.uri); | ||
builder.putString(IS_KEY_ANALYTIC_TAG, imageRequestParams.analyticTag); | ||
} | ||
|
||
inline MapBuffer serializeImageRequest( | ||
const ImageSource& imageSource, | ||
const ImageRequestParams& imageRequestParams) { | ||
auto builder = MapBufferBuilder(); | ||
serializeImageSource(builder, imageSource); | ||
serializeImageRequestParams(builder, imageRequestParams); | ||
return builder.build(); | ||
} | ||
|
||
} // namespace facebook::react |