Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
#import <React/RCTConversions.h>
#import <React/RCTImageBlurUtils.h>
#import <React/RCTImageResponseObserverProxy.h>
#import <react/featureflags/ReactNativeFeatureFlags.h>
#import <react/renderer/components/image/ImageComponentDescriptor.h>
#import <react/renderer/components/image/ImageEventEmitter.h>
#import <react/renderer/components/image/ImageProps.h>
#import <react/renderer/graphics/Color.h>
#import <react/renderer/imagemanager/ImageRequest.h>
#import <react/renderer/imagemanager/RCTImagePrimitivesConversions.h>

Expand Down Expand Up @@ -63,7 +65,15 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &

// `tintColor`
if (oldImageProps.tintColor != newImageProps.tintColor) {
_imageView.tintColor = RCTUIColorFromSharedColor(newImageProps.tintColor);
if (ReactNativeFeatureFlags::enableImageTransparentTintColor()) {
if (newImageProps.tintColor.has_value()) {
_imageView.tintColor = RCTUIColorFromSharedColor(newImageProps.tintColor.value());
} else {
_imageView.tintColor = nil;
}
} else {
_imageView.tintColor = RCTUIColorFromSharedColor(newImageProps.tintColor.value_or(SharedColor{}));
}
}

[super updateProps:props oldProps:oldProps];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/renderer/components/image/ImageProps.h>
#include <react/renderer/components/image/conversions.h>
#include <react/renderer/core/propsConversions.h>
#include <react/renderer/debug/debugStringConvertibleUtils.h>
#include <react/renderer/graphics/Color.h>

namespace facebook::react {

Expand Down Expand Up @@ -199,8 +201,24 @@ folly::dynamic ImageProps::getDiffProps(const Props* prevProps) const {
result["capInsets"] = convertEdgeInsets(capInsets);
}

if (tintColor != oldProps->tintColor) {
result["tintColor"] = *tintColor;
if (ReactNativeFeatureFlags::enableImageTransparentTintColor()) {
// New: emit any defined tint (including transparent); emit null to clear on
// unset.
if (tintColor != oldProps->tintColor) {
if (tintColor.has_value()) {
result["tintColor"] = *tintColor.value();
} else {
result["tintColor"] = folly::dynamic(nullptr);
}
}
} else {
// pre-`std::optional` behavior
SharedColor tintColorValue = tintColor.value_or(SharedColor{});
SharedColor prevTintColorValue =
oldProps->tintColor.value_or(SharedColor{});
if (tintColorValue != prevTintColorValue) {
result["tintColor"] = *tintColorValue;
}
}

if (internal_analyticTag != oldProps->internal_analyticTag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ImageProps final : public ViewProps {
ImageResizeMode resizeMode{ImageResizeMode::Stretch};
Float blurRadius{};
EdgeInsets capInsets{};
SharedColor tintColor{};
std::optional<SharedColor> tintColor{};
std::string internal_analyticTag{};
std::string resizeMethod{"auto"};
Float resizeMultiplier{1.f};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ImageRequestParams {
Float resizeMultiplier,
bool shouldNotifyLoadEvents,
SharedColor overlayColor,
SharedColor tintColor,
std::optional<SharedColor> tintColor,
Float fadeDuration,
bool progressiveRenderingEnabled,
ImageSource loadingIndicatorSource,
Expand Down Expand Up @@ -55,7 +55,7 @@ class ImageRequestParams {
Float resizeMultiplier{};
bool shouldNotifyLoadEvents{};
SharedColor overlayColor{};
SharedColor tintColor{};
std::optional<SharedColor> tintColor{};
Float fadeDuration{};
bool progressiveRenderingEnabled{};
ImageSource loadingIndicatorSource{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once

#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/renderer/core/graphicsConversions.h>
#include <react/renderer/imagemanager/ImageRequestParams.h>
#include <react/renderer/imagemanager/primitives.h>
Expand Down Expand Up @@ -75,8 +76,16 @@ inline void serializeImageRequestParams(MapBufferBuilder &builder, const ImageRe
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));
if (ReactNativeFeatureFlags::enableImageTransparentTintColor()) {
if (imageRequestParams.tintColor.has_value()) {
builder.putInt(IS_KEY_TINT_COLOR, toAndroidRepr(imageRequestParams.tintColor.value()));
}
} else {
// pre-`std::optional` behavior
SharedColor tintColor = imageRequestParams.tintColor.value_or(SharedColor{});
if (isColorMeaningful(tintColor)) {
builder.putInt(IS_KEY_TINT_COLOR, toAndroidRepr(tintColor));
}
}
builder.putInt(IS_KEY_FADE_DURATION, static_cast<int32_t>(imageRequestParams.fadeDuration));
builder.putBool(IS_KEY_PROGRESSIVE_RENDERING_ENABLED, imageRequestParams.progressiveRenderingEnabled);
Expand Down
6 changes: 3 additions & 3 deletions scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -2594,7 +2594,7 @@ class facebook::react::ImageProps : public facebook::react::HostPlatformViewProp
public facebook::react::ImageSource loadingIndicatorSource;
public facebook::react::ImageSources sources;
public facebook::react::SharedColor overlayColor;
public facebook::react::SharedColor tintColor;
public std::optional<facebook::react::SharedColor> tintColor;
public std::string resizeMethod;
public virtual facebook::react::ComponentName getDiffPropsImplementationTarget() const override;
public virtual folly::dynamic getDiffProps(const facebook::react::Props* prevProps) const override;
Expand All @@ -2616,7 +2616,7 @@ class facebook::react::ImageRequest {

class facebook::react::ImageRequestParams {
public ImageRequestParams() = default;
public ImageRequestParams(facebook::react::Float blurRadius, facebook::react::ImageSource defaultSource, facebook::react::ImageResizeMode resizeMode, std::string resizeMethod, facebook::react::Float resizeMultiplier, bool shouldNotifyLoadEvents, facebook::react::SharedColor overlayColor, facebook::react::SharedColor tintColor, facebook::react::Float fadeDuration, bool progressiveRenderingEnabled, facebook::react::ImageSource loadingIndicatorSource, std::string analyticTag, facebook::react::Size size);
public ImageRequestParams(facebook::react::Float blurRadius, facebook::react::ImageSource defaultSource, facebook::react::ImageResizeMode resizeMode, std::string resizeMethod, facebook::react::Float resizeMultiplier, bool shouldNotifyLoadEvents, facebook::react::SharedColor overlayColor, std::optional<facebook::react::SharedColor> tintColor, facebook::react::Float fadeDuration, bool progressiveRenderingEnabled, facebook::react::ImageSource loadingIndicatorSource, std::string analyticTag, facebook::react::Size size);
public bool operator==(const facebook::react::ImageRequestParams& rhs) const = default;
public bool progressiveRenderingEnabled;
public bool shouldNotifyLoadEvents;
Expand All @@ -2627,8 +2627,8 @@ class facebook::react::ImageRequestParams {
public facebook::react::ImageSource defaultSource;
public facebook::react::ImageSource loadingIndicatorSource;
public facebook::react::SharedColor overlayColor;
public facebook::react::SharedColor tintColor;
public facebook::react::Size size;
public std::optional<facebook::react::SharedColor> tintColor;
public std::string analyticTag;
public std::string resizeMethod;
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -2576,7 +2576,7 @@ class facebook::react::ImageProps : public facebook::react::HostPlatformViewProp
public facebook::react::ImageSource loadingIndicatorSource;
public facebook::react::ImageSources sources;
public facebook::react::SharedColor overlayColor;
public facebook::react::SharedColor tintColor;
public std::optional<facebook::react::SharedColor> tintColor;
public std::string resizeMethod;
public virtual facebook::react::ComponentName getDiffPropsImplementationTarget() const override;
public virtual folly::dynamic getDiffProps(const facebook::react::Props* prevProps) const override;
Expand All @@ -2598,7 +2598,7 @@ class facebook::react::ImageRequest {

class facebook::react::ImageRequestParams {
public ImageRequestParams() = default;
public ImageRequestParams(facebook::react::Float blurRadius, facebook::react::ImageSource defaultSource, facebook::react::ImageResizeMode resizeMode, std::string resizeMethod, facebook::react::Float resizeMultiplier, bool shouldNotifyLoadEvents, facebook::react::SharedColor overlayColor, facebook::react::SharedColor tintColor, facebook::react::Float fadeDuration, bool progressiveRenderingEnabled, facebook::react::ImageSource loadingIndicatorSource, std::string analyticTag, facebook::react::Size size);
public ImageRequestParams(facebook::react::Float blurRadius, facebook::react::ImageSource defaultSource, facebook::react::ImageResizeMode resizeMode, std::string resizeMethod, facebook::react::Float resizeMultiplier, bool shouldNotifyLoadEvents, facebook::react::SharedColor overlayColor, std::optional<facebook::react::SharedColor> tintColor, facebook::react::Float fadeDuration, bool progressiveRenderingEnabled, facebook::react::ImageSource loadingIndicatorSource, std::string analyticTag, facebook::react::Size size);
public bool operator==(const facebook::react::ImageRequestParams& rhs) const = default;
public bool progressiveRenderingEnabled;
public bool shouldNotifyLoadEvents;
Expand All @@ -2609,8 +2609,8 @@ class facebook::react::ImageRequestParams {
public facebook::react::ImageSource defaultSource;
public facebook::react::ImageSource loadingIndicatorSource;
public facebook::react::SharedColor overlayColor;
public facebook::react::SharedColor tintColor;
public facebook::react::Size size;
public std::optional<facebook::react::SharedColor> tintColor;
public std::string analyticTag;
public std::string resizeMethod;
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -2591,7 +2591,7 @@ class facebook::react::ImageProps : public facebook::react::HostPlatformViewProp
public facebook::react::ImageSource loadingIndicatorSource;
public facebook::react::ImageSources sources;
public facebook::react::SharedColor overlayColor;
public facebook::react::SharedColor tintColor;
public std::optional<facebook::react::SharedColor> tintColor;
public std::string resizeMethod;
public virtual facebook::react::ComponentName getDiffPropsImplementationTarget() const override;
public virtual folly::dynamic getDiffProps(const facebook::react::Props* prevProps) const override;
Expand All @@ -2613,7 +2613,7 @@ class facebook::react::ImageRequest {

class facebook::react::ImageRequestParams {
public ImageRequestParams() = default;
public ImageRequestParams(facebook::react::Float blurRadius, facebook::react::ImageSource defaultSource, facebook::react::ImageResizeMode resizeMode, std::string resizeMethod, facebook::react::Float resizeMultiplier, bool shouldNotifyLoadEvents, facebook::react::SharedColor overlayColor, facebook::react::SharedColor tintColor, facebook::react::Float fadeDuration, bool progressiveRenderingEnabled, facebook::react::ImageSource loadingIndicatorSource, std::string analyticTag, facebook::react::Size size);
public ImageRequestParams(facebook::react::Float blurRadius, facebook::react::ImageSource defaultSource, facebook::react::ImageResizeMode resizeMode, std::string resizeMethod, facebook::react::Float resizeMultiplier, bool shouldNotifyLoadEvents, facebook::react::SharedColor overlayColor, std::optional<facebook::react::SharedColor> tintColor, facebook::react::Float fadeDuration, bool progressiveRenderingEnabled, facebook::react::ImageSource loadingIndicatorSource, std::string analyticTag, facebook::react::Size size);
public bool operator==(const facebook::react::ImageRequestParams& rhs) const = default;
public bool progressiveRenderingEnabled;
public bool shouldNotifyLoadEvents;
Expand All @@ -2624,8 +2624,8 @@ class facebook::react::ImageRequestParams {
public facebook::react::ImageSource defaultSource;
public facebook::react::ImageSource loadingIndicatorSource;
public facebook::react::SharedColor overlayColor;
public facebook::react::SharedColor tintColor;
public facebook::react::Size size;
public std::optional<facebook::react::SharedColor> tintColor;
public std::string analyticTag;
public std::string resizeMethod;
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -5008,7 +5008,7 @@ class facebook::react::ImageProps : public facebook::react::HostPlatformViewProp
public facebook::react::ImageSource loadingIndicatorSource;
public facebook::react::ImageSources sources;
public facebook::react::SharedColor overlayColor;
public facebook::react::SharedColor tintColor;
public std::optional<facebook::react::SharedColor> tintColor;
public std::string resizeMethod;
public void setProp(const facebook::react::PropsParserContext& context, facebook::react::RawPropsPropNameHash hash, const char* propName, const facebook::react::RawValue& value);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -4979,7 +4979,7 @@ class facebook::react::ImageProps : public facebook::react::HostPlatformViewProp
public facebook::react::ImageSource loadingIndicatorSource;
public facebook::react::ImageSources sources;
public facebook::react::SharedColor overlayColor;
public facebook::react::SharedColor tintColor;
public std::optional<facebook::react::SharedColor> tintColor;
public std::string resizeMethod;
public void setProp(const facebook::react::PropsParserContext& context, facebook::react::RawPropsPropNameHash hash, const char* propName, const facebook::react::RawValue& value);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -5005,7 +5005,7 @@ class facebook::react::ImageProps : public facebook::react::HostPlatformViewProp
public facebook::react::ImageSource loadingIndicatorSource;
public facebook::react::ImageSources sources;
public facebook::react::SharedColor overlayColor;
public facebook::react::SharedColor tintColor;
public std::optional<facebook::react::SharedColor> tintColor;
public std::string resizeMethod;
public void setProp(const facebook::react::PropsParserContext& context, facebook::react::RawPropsPropNameHash hash, const char* propName, const facebook::react::RawValue& value);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ class facebook::react::ImageProps : public facebook::react::HostPlatformViewProp
public facebook::react::ImageSource loadingIndicatorSource;
public facebook::react::ImageSources sources;
public facebook::react::SharedColor overlayColor;
public facebook::react::SharedColor tintColor;
public std::optional<facebook::react::SharedColor> tintColor;
public std::string resizeMethod;
public void setProp(const facebook::react::PropsParserContext& context, facebook::react::RawPropsPropNameHash hash, const char* propName, const facebook::react::RawValue& value);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ class facebook::react::ImageProps : public facebook::react::HostPlatformViewProp
public facebook::react::ImageSource loadingIndicatorSource;
public facebook::react::ImageSources sources;
public facebook::react::SharedColor overlayColor;
public facebook::react::SharedColor tintColor;
public std::optional<facebook::react::SharedColor> tintColor;
public std::string resizeMethod;
public void setProp(const facebook::react::PropsParserContext& context, facebook::react::RawPropsPropNameHash hash, const char* propName, const facebook::react::RawValue& value);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ class facebook::react::ImageProps : public facebook::react::HostPlatformViewProp
public facebook::react::ImageSource loadingIndicatorSource;
public facebook::react::ImageSources sources;
public facebook::react::SharedColor overlayColor;
public facebook::react::SharedColor tintColor;
public std::optional<facebook::react::SharedColor> tintColor;
public std::string resizeMethod;
public void setProp(const facebook::react::PropsParserContext& context, facebook::react::RawPropsPropNameHash hash, const char* propName, const facebook::react::RawValue& value);
}
Expand Down
Loading