From 62536db8c7da18bd2b8339ac5755d4db425d67ca Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Wed, 26 Mar 2025 14:13:19 -0700 Subject: [PATCH] Fabric: Fixes color hash type to prevent bits truncation (#50285) Summary: I made a mistake before, it seems we should use std::size_t to prevent bits truncation. ## Changelog: [IOS] [FIXED] - Fabric: Fixes color hash type to prevent bits truncation Pull Request resolved: https://github.com/facebook/react-native/pull/50285 Test Plan: N/A Reviewed By: javache Differential Revision: D71895413 Pulled By: cipolleschi fbshipit-source-id: 26cc036bee851902e11abfa8ed5c5c8222421b09 --- .../platform/ios/react/renderer/graphics/HostPlatformColor.h | 4 ++-- .../platform/ios/react/renderer/graphics/HostPlatformColor.mm | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.h b/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.h index 8d47debe992..5dd1ac810e5 100644 --- a/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.h +++ b/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.h @@ -26,7 +26,7 @@ struct Color { Color(const ColorComponents& components); Color() : uiColor_(nullptr){}; int32_t getColor() const; - int32_t getUIColorHash() const; + std::size_t getUIColorHash() const; static Color createSemanticColor(std::vector& semanticItems); @@ -54,7 +54,7 @@ struct Color { private: Color(std::shared_ptr uiColor); std::shared_ptr uiColor_; - int32_t uiColorHashValue_; + std::size_t uiColorHashValue_; }; namespace HostPlatformColor { diff --git a/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm b/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm index 8ea0639aa52..90885828451 100644 --- a/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm +++ b/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm @@ -132,7 +132,7 @@ UIColor *_Nullable UIColorFromComponentsColor(const facebook::react::ColorCompon return uiColor; } -int32_t hashFromUIColor(const std::shared_ptr &uiColor) +std::size_t hashFromUIColor(const std::shared_ptr &uiColor) { if (uiColor == nullptr) { return 0; @@ -229,7 +229,7 @@ float Color::getChannel(int channelId) const return static_cast(rgba[channelId]); } -int32_t Color::getUIColorHash() const +std::size_t Color::getUIColorHash() const { return uiColorHashValue_; }