forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
159 additions
and
100 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
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
53 changes: 53 additions & 0 deletions
53
...tCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm
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,53 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#import "HostPlatformColor.h" | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <UIKit/UIKit.h> | ||
#include <react/renderer/graphics/HostPlatformColor.h> | ||
|
||
#include <string> | ||
|
||
using namespace facebook::react; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
namespace facebook::react { | ||
|
||
int32_t RCTPlatformColorGetCurrentColorFromDynamicColor(facebook::react::DynamicColor dynamicColor) | ||
{ | ||
int32_t lightColor = dynamicColor.lightColor; | ||
int32_t darkColor = dynamicColor.darkColor; | ||
int32_t highContrastLightColor = dynamicColor.highContrastLightColor; | ||
int32_t highContrastDarkColor = dynamicColor.highContrastDarkColor; | ||
UITraitCollection *currentTraitCollection = [UITraitCollection currentTraitCollection]; | ||
if (currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { | ||
if (currentTraitCollection.accessibilityContrast == UIAccessibilityContrastHigh && highContrastDarkColor) { | ||
return highContrastDarkColor; | ||
} else { | ||
return darkColor; | ||
} | ||
} else { | ||
if (currentTraitCollection.accessibilityContrast == UIAccessibilityContrastHigh && highContrastLightColor) { | ||
return highContrastLightColor; | ||
} else { | ||
return lightColor; | ||
} | ||
} | ||
} | ||
|
||
int32_t Color::getColor() const | ||
{ | ||
if (kind_ == DynamicKind) { | ||
return RCTPlatformColorGetCurrentColorFromDynamicColor(getDynamicColor()); | ||
} | ||
return std::get<int32_t>(color_); | ||
} | ||
} // namespace facebook::react | ||
|
||
NS_ASSUME_NONNULL_END |
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
73 changes: 73 additions & 0 deletions
73
...ommon/react/renderer/graphics/platform/ios/react/renderer/graphics/PlatformColorParser.mm
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,73 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#import "PlatformColorParser.h" | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <UIKit/UIKit.h> | ||
#include <react/renderer/core/graphicsConversions.h> | ||
#include <react/renderer/graphics/HostPlatformColor.h> | ||
#include <react/renderer/graphics/RCTPlatformColorUtils.h> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
using namespace facebook::react; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
namespace facebook::react { | ||
|
||
inline facebook::react::SharedColor RCTPlatformColorComponentsFromDynamicItems( | ||
const facebook::react::PropsParserContext &context, | ||
std::unordered_map<std::string, facebook::react::RawValue> &dynamicItems) | ||
{ | ||
SharedColor lightSharedColor{}; | ||
SharedColor darkSharedColor{}; | ||
SharedColor highContrastLightSharedColor{}; | ||
SharedColor highContrastDarkSharedColor{}; | ||
if (dynamicItems.count("light")) { | ||
fromRawValue(context, dynamicItems.at("light"), lightSharedColor); | ||
} | ||
if (dynamicItems.count("dark")) { | ||
fromRawValue(context, dynamicItems.at("dark"), darkSharedColor); | ||
} | ||
if (dynamicItems.count("highContrastLight")) { | ||
fromRawValue(context, dynamicItems.at("highContrastLight"), highContrastLightSharedColor); | ||
} | ||
if (dynamicItems.count("highContrastDark")) { | ||
fromRawValue(context, dynamicItems.at("highContrastDark"), highContrastDarkSharedColor); | ||
} | ||
|
||
Color color = Color(DynamicColor{ | ||
(*lightSharedColor).getColor(), | ||
(*darkSharedColor).getColor(), | ||
(*highContrastLightSharedColor).getColor(), | ||
(*highContrastDarkSharedColor).getColor()}); | ||
return SharedColor(color); | ||
} | ||
|
||
SharedColor parsePlatformColor(const PropsParserContext &context, 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 {colorFromComponents(RCTPlatformColorComponentsFromSemanticItems(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(context, dynamicItems); | ||
} | ||
} | ||
|
||
return clearColor(); | ||
} | ||
|
||
} // namespace facebook::react | ||
|
||
NS_ASSUME_NONNULL_END |
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
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