Skip to content
Draft
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 @@ -24,7 +24,10 @@ boost_config = get_boost_config()
boost_compiler_flags = boost_config[:compiler_flags]

Pod::Spec.new do |s|
source_files = "*.{m,mm,cpp,h}", "platform/ios/**/*.{m,mm,cpp,h}"
# [macOS Use platform specific sources
ios_source_files = "*.{m,mm,cpp,h}", "platform/ios/**/*.{m,mm,cpp,h}"
macos_source_files = "*.{m,mm,cpp,h}", "platform/ios/**/*.{m,mm,cpp,h}", "platform/macos/**/*.{m,mm,cpp,h}"
# macOS]
header_search_paths = [
"\"$(PODS_ROOT)/boost\"",
"\"$(PODS_TARGET_SRCROOT)/../../../\"",
Expand All @@ -43,7 +46,11 @@ Pod::Spec.new do |s|
s.platforms = min_supported_versions
s.source = source
s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags
s.source_files = source_files
# [macOS Use platform specific sources
s.ios.source_files = ios_source_files
s.visionos.source_files = ios_source_files
s.osx.source_files = macos_source_files
# macOS]
s.header_dir = "react/renderer/graphics"
# [macOS Restrict UIKit to iOS and visionOS
s.ios.framework = "UIKit"
Expand All @@ -54,7 +61,7 @@ Pod::Spec.new do |s|
if ENV['USE_FRAMEWORKS']
s.module_name = "React_graphics"
s.header_mappings_dir = "../../.."
header_search_paths = header_search_paths + ["\"$(PODS_TARGET_SRCROOT)/platform/ios\""]
header_search_paths = header_search_paths + ["\"$(PODS_TARGET_SRCROOT)/platform/ios\"", "\"$(PODS_TARGET_SRCROOT)/platform/macos\""] # [macOS]
end

s.pod_target_xcconfig = { "USE_HEADERMAP" => "NO",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// [macOS]

#import "HostPlatformColor.h"

#import <Foundation/Foundation.h>
#import <React/RCTUIKit.h>
#import <objc/runtime.h>
#import <react/renderer/graphics/RCTPlatformColorUtils.h>
#import <react/utils/ManagedObjectWrapper.h>
#import <string>

using namespace facebook::react;

NS_ASSUME_NONNULL_BEGIN

namespace facebook::react {

RCTUIColor *_Nullable UIColorFromColorWithSystemEffect(
RCTUIColor *baseColor,
const std::string &systemEffectString)
{
if (baseColor == nil) {
return nil;
}

NSColor *colorWithEffect = baseColor;
if (!systemEffectString.empty()) {
if (systemEffectString == "none") {
colorWithEffect = [baseColor colorWithSystemEffect:NSColorSystemEffectNone];
} else if (systemEffectString == "pressed") {
colorWithEffect = [baseColor colorWithSystemEffect:NSColorSystemEffectPressed];
} else if (systemEffectString == "deepPressed") {
colorWithEffect = [baseColor colorWithSystemEffect:NSColorSystemEffectDeepPressed];
} else if (systemEffectString == "disabled") {
colorWithEffect = [baseColor colorWithSystemEffect:NSColorSystemEffectDisabled];
} else if (systemEffectString == "rollover") {
colorWithEffect = [baseColor colorWithSystemEffect:NSColorSystemEffectRollover];
}
}
return colorWithEffect;
}

} // namespace facebook::react

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// [macOS]

#import "PlatformColorParser.h"

#import <react/renderer/core/RawValue.h>
#import <react/renderer/graphics/HostPlatformColor.h>
#import <react/renderer/graphics/RCTPlatformColorUtils.h>
#import <react/utils/ManagedObjectWrapper.h>
#import <string>
#import <unordered_map>

using namespace facebook::react;

NS_ASSUME_NONNULL_BEGIN

// Forward declaration for ColorWithSystemEffect helper
RCTUIColor *_Nullable UIColorFromColorWithSystemEffect(
RCTUIColor *baseColor,
const std::string &systemEffectString);

namespace facebook::react {

inline facebook::react::SharedColor RCTPlatformColorComponentsFromDynamicItems(
const facebook::react::ContextContainer &contextContainer,
int32_t surfaceId,
std::unordered_map<std::string, facebook::react::RawValue> &dynamicItems)
{
SharedColor lightSharedColor{};
SharedColor darkSharedColor{};
SharedColor highContrastLightSharedColor{};
SharedColor highContrastDarkSharedColor{};
if (dynamicItems.count("light")) {
fromRawValue(contextContainer, surfaceId, dynamicItems.at("light"), lightSharedColor);
}
if (dynamicItems.count("dark")) {
fromRawValue(contextContainer, surfaceId, dynamicItems.at("dark"), darkSharedColor);
}
if (dynamicItems.count("highContrastLight")) {
fromRawValue(contextContainer, surfaceId, dynamicItems.at("highContrastLight"), highContrastLightSharedColor);
}
if (dynamicItems.count("highContrastDark")) {
fromRawValue(contextContainer, surfaceId, dynamicItems.at("highContrastDark"), highContrastDarkSharedColor);
}

Color color = Color(DynamicColor{
(*lightSharedColor).getColor(),
(*darkSharedColor).getColor(),
(*highContrastLightSharedColor).getColor(),
(*highContrastDarkSharedColor).getColor()});
return SharedColor(color);
}

SharedColor parsePlatformColor(const ContextContainer &contextContainer, int32_t surfaceId, const RawValue &value)
{
if (value.hasType<std::unordered_map<std::string, RawValue>>()) {
auto items = (std::unordered_map<std::string, RawValue>)value;
if (items.find("semantic") != items.end() && items.at("semantic").hasType<std::vector<std::string>>()) {
auto semanticItems = (std::vector<std::string>)items.at("semantic");
return SharedColor(Color::createSemanticColor(semanticItems));
} else if (
items.find("dynamic") != items.end() &&
items.at("dynamic").hasType<std::unordered_map<std::string, RawValue>>()) {
auto dynamicItems = (std::unordered_map<std::string, RawValue>)items.at("dynamic");
return RCTPlatformColorComponentsFromDynamicItems(contextContainer, surfaceId, dynamicItems);
} else if (
items.find("colorWithSystemEffect") != items.end() &&
items.at("colorWithSystemEffect").hasType<std::unordered_map<std::string, RawValue>>()) {
auto colorWithSystemEffectItems = (std::unordered_map<std::string, RawValue>)items.at("colorWithSystemEffect");
if (colorWithSystemEffectItems.find("baseColor") != colorWithSystemEffectItems.end() &&
colorWithSystemEffectItems.find("systemEffect") != colorWithSystemEffectItems.end() &&
colorWithSystemEffectItems.at("systemEffect").hasType<std::string>()) {
SharedColor baseColorShared{};
fromRawValue(contextContainer, surfaceId, colorWithSystemEffectItems.at("baseColor"), baseColorShared);
if (baseColorShared) {
RCTUIColor *baseColor = RCTPlatformColorFromColor(*baseColorShared);
std::string systemEffect = (std::string)colorWithSystemEffectItems.at("systemEffect");
RCTUIColor *colorWithEffect = UIColorFromColorWithSystemEffect(baseColor, systemEffect);
if (colorWithEffect != nil) {
return SharedColor(Color(wrapManagedObject(colorWithEffect)));
}
}
}
}
}

return clearColor();
}

} // namespace facebook::react

NS_ASSUME_NONNULL_END
Loading