react-native 0.74.0-nightly-20240129-39cb02f6f → 1000.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/Libraries/Animated/NativeAnimatedHelper.js +1 -1
  2. package/Libraries/Animated/nodes/AnimatedStyle.js +1 -1
  3. package/Libraries/Animated/useAnimatedProps.js +1 -1
  4. package/Libraries/AppDelegate/RCTAppDelegate.mm +2 -1
  5. package/Libraries/Blob/React-RCTBlob.podspec +1 -0
  6. package/Libraries/Components/PopupMenuAndroid/PopupMenuAndroid.android.js +69 -0
  7. package/Libraries/Components/PopupMenuAndroid/PopupMenuAndroid.d.ts +24 -0
  8. package/Libraries/Components/PopupMenuAndroid/PopupMenuAndroid.js +33 -0
  9. package/Libraries/Components/PopupMenuAndroid/PopupMenuAndroidNativeComponent.js +13 -0
  10. package/Libraries/Core/ReactNativeVersion.js +2 -3
  11. package/Libraries/Core/registerCallableModule.js +42 -0
  12. package/Libraries/Image/RCTImageLoader.mm +4 -11
  13. package/Libraries/LayoutAnimation/LayoutAnimation.js +1 -1
  14. package/Libraries/ReactNative/BridgelessUIManager.js +31 -13
  15. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +1 -1
  16. package/Libraries/ReactNative/ReactNativeFeatureFlags.js +0 -33
  17. package/Libraries/ReactNative/__mocks__/FabricUIManager.js +12 -0
  18. package/Libraries/Renderer/implementations/ReactFabric-dev.js +24543 -21110
  19. package/Libraries/Renderer/implementations/ReactFabric-prod.js +4104 -3058
  20. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +4352 -3273
  21. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +25038 -21457
  22. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +3721 -2600
  23. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +4024 -2869
  24. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +43 -4
  25. package/Libraries/WebPerformance/Performance.js +1 -1
  26. package/React/Base/RCTBridge+Private.h +14 -0
  27. package/React/Base/RCTBridge.mm +6 -0
  28. package/React/Base/RCTKeyCommands.m +12 -1
  29. package/React/Base/RCTVersion.m +3 -3
  30. package/React/CoreModules/RCTAlertController.mm +2 -3
  31. package/React/CoreModules/RCTAppearance.mm +1 -1
  32. package/React/CoreModules/React-CoreModules.podspec +1 -0
  33. package/React/CxxBridge/RCTCxxBridge.mm +21 -3
  34. package/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm +22 -1
  35. package/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +13 -2
  36. package/React/Fabric/RCTConversions.h +2 -18
  37. package/React/React-RCTFabric.podspec +1 -0
  38. package/React-Core.podspec +1 -3
  39. package/ReactAndroid/api/ReactAndroid.api +53 -1
  40. package/ReactAndroid/gradle.properties +1 -1
  41. package/ReactAndroid/src/main/java/com/facebook/react/animated/AnimatedNode.java +3 -1
  42. package/ReactAndroid/src/main/java/com/facebook/react/animated/DecayAnimation.java +2 -0
  43. package/ReactAndroid/src/main/java/com/facebook/react/animated/DiffClampAnimatedNode.java +3 -1
  44. package/ReactAndroid/src/main/java/com/facebook/react/animated/ModulusAnimatedNode.java +3 -1
  45. package/ReactAndroid/src/main/java/com/facebook/react/animated/ObjectAnimatedNode.java +3 -1
  46. package/ReactAndroid/src/main/java/com/facebook/react/animated/SpringAnimation.java +3 -1
  47. package/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java +1 -3
  48. package/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt +5 -2
  49. package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt +11 -1
  50. package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt +11 -1
  51. package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt +3 -1
  52. package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt +3 -1
  53. package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt +12 -1
  54. package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt +3 -1
  55. package/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutor.kt +1 -1
  56. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +3 -3
  57. package/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java +3 -0
  58. package/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java +13 -1
  59. package/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java +7 -0
  60. package/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +11 -0
  61. package/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIViewOperationQueue.java +24 -0
  62. package/ReactAndroid/src/main/java/com/facebook/react/views/image/ScaleTypeStartInside.java +1 -1
  63. package/ReactAndroid/src/main/java/com/facebook/react/views/popupmenu/PopupMenuSelectionEvent.kt +37 -0
  64. package/ReactAndroid/src/main/java/com/facebook/react/views/popupmenu/ReactPopupMenuContainer.kt +49 -0
  65. package/ReactAndroid/src/main/java/com/facebook/react/views/popupmenu/ReactPopupMenuManager.kt +54 -0
  66. package/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java +2 -2
  67. package/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java +2 -2
  68. package/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManagerMapBuffer.java +2 -2
  69. package/ReactAndroid/src/main/jni/react/fabric/CoreComponentsRegistry.cpp +2 -0
  70. package/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp +9 -1
  71. package/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h +4 -1
  72. package/ReactAndroid/src/main/jni/react/featureflags/ReactNativeFeatureFlagsProviderHolder.cpp +7 -1
  73. package/ReactAndroid/src/main/jni/react/featureflags/ReactNativeFeatureFlagsProviderHolder.h +2 -1
  74. package/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp +16 -10
  75. package/ReactAndroid/src/main/jni/react/jni/ProxyExecutor.cpp +0 -3
  76. package/ReactAndroid/src/main/jni/react/jni/ProxyExecutor.h +0 -1
  77. package/ReactAndroid/src/main/jni/react/newarchdefaults/DefaultComponentsRegistry.cpp +7 -6
  78. package/ReactCommon/cxxreact/Instance.cpp +34 -18
  79. package/ReactCommon/cxxreact/Instance.h +13 -2
  80. package/ReactCommon/cxxreact/React-cxxreact.podspec +1 -1
  81. package/ReactCommon/cxxreact/ReactNativeVersion.h +2 -2
  82. package/ReactCommon/jsinspector-modern/InstanceAgent.cpp +34 -0
  83. package/ReactCommon/jsinspector-modern/InstanceAgent.h +54 -0
  84. package/ReactCommon/jsinspector-modern/InstanceTarget.cpp +25 -0
  85. package/ReactCommon/jsinspector-modern/InstanceTarget.h +58 -0
  86. package/ReactCommon/jsinspector-modern/PageAgent.cpp +65 -0
  87. package/ReactCommon/jsinspector-modern/PageAgent.h +13 -0
  88. package/ReactCommon/jsinspector-modern/PageTarget.cpp +41 -0
  89. package/ReactCommon/jsinspector-modern/PageTarget.h +28 -1
  90. package/ReactCommon/jsinspector-modern/React-jsinspector.podspec +12 -1
  91. package/ReactCommon/jsinspector-modern/ReactCdp.h +1 -0
  92. package/ReactCommon/jsinspector-modern/tests/InspectorMocks.h +2 -0
  93. package/ReactCommon/jsinspector-modern/tests/PageTargetTest.cpp +164 -10
  94. package/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp +5 -1
  95. package/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h +6 -1
  96. package/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp +18 -1
  97. package/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h +3 -1
  98. package/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h +5 -1
  99. package/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h +2 -1
  100. package/ReactCommon/react/featureflags/tests/ReactNativeFeatureFlagsTest.cpp +4 -0
  101. package/ReactCommon/react/nativemodule/core/platform/ios/React-NativeModulesApple.podspec +1 -0
  102. package/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp +6 -1
  103. package/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h +3 -1
  104. package/ReactCommon/react/renderer/attributedstring/primitives.h +0 -86
  105. package/ReactCommon/react/renderer/components/view/AccessibilityPrimitives.h +0 -16
  106. package/ReactCommon/react/renderer/components/view/CSSTokenizer.cpp +187 -0
  107. package/ReactCommon/react/renderer/components/view/CSSTokenizer.h +101 -0
  108. package/ReactCommon/react/renderer/components/view/tests/CSSTokenizerTest.cpp +144 -0
  109. package/ReactCommon/react/renderer/core/ComponentDescriptor.h +0 -1
  110. package/ReactCommon/react/renderer/core/LayoutPrimitives.h +0 -17
  111. package/ReactCommon/react/renderer/core/propsConversions.h +0 -1
  112. package/ReactCommon/react/renderer/graphics/Color.h +7 -3
  113. package/ReactCommon/react/renderer/graphics/React-graphics.podspec +6 -1
  114. package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.h +55 -15
  115. package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm +132 -0
  116. package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/PlatformColorParser.h +4 -18
  117. package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/PlatformColorParser.mm +73 -0
  118. package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.h +8 -2
  119. package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.mm +14 -3
  120. package/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextPrimitivesConversions.h +4 -19
  121. package/ReactCommon/react/runtime/ReactInstance.cpp +15 -2
  122. package/ReactCommon/react/runtime/ReactInstance.h +13 -2
  123. package/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm +5 -3
  124. package/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.h +3 -1
  125. package/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm +10 -2
  126. package/ReactCommon/react/test_utils/ios/Shims/ShimRCTInstance.mm +5 -2
  127. package/ReactCommon/react/utils/hash_combine.h +8 -6
  128. package/gradle/libs.versions.toml +1 -1
  129. package/index.js +9 -0
  130. package/package.json +9 -9
  131. package/sdks/hermesc/osx-bin/hermes +0 -0
  132. package/sdks/hermesc/osx-bin/hermesc +0 -0
  133. package/sdks/hermesc/win64-bin/hermesc.exe +0 -0
  134. package/src/private/featureflags/NativeReactNativeFeatureFlags.js +2 -1
  135. package/src/private/featureflags/ReactNativeFeatureFlags.js +42 -1
  136. package/src/private/specs/components/PopupMenuAndroidNativeComponent.js +47 -0
  137. package/template/package.json +5 -5
  138. package/ReactAndroid/src/main/jni/react/jni/OnLoad.h +0 -16
@@ -0,0 +1,187 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ #include <cmath>
9
+ #include <cstdint>
10
+
11
+ #include <react/debug/react_native_assert.h>
12
+ #include <react/renderer/components/view/CSSTokenizer.h>
13
+
14
+ namespace facebook::react {
15
+
16
+ CSSTokenizer::CSSTokenizer(std::string_view characters)
17
+ : remainingCharacters_{characters} {}
18
+
19
+ CSSToken CSSTokenizer::next() {
20
+ // https://www.w3.org/TR/css-syntax-3/#token-diagrams
21
+ char nextChar = peek();
22
+ if (isWhitespace(nextChar)) {
23
+ return consumeWhitespace();
24
+ } else if (nextChar == '+') {
25
+ if (isDigit(peekNext())) {
26
+ return consumeNumeric();
27
+ } else {
28
+ return consumeDelim();
29
+ }
30
+ } else if (nextChar == '-') {
31
+ if (isDigit(peekNext())) {
32
+ return consumeNumeric();
33
+ } else {
34
+ return consumeDelim();
35
+ }
36
+ } else if (isDigit(nextChar)) {
37
+ return consumeNumeric();
38
+ } else if (isIdentStart(nextChar)) {
39
+ return consumeIdent();
40
+ } else if (nextChar == '\0') {
41
+ return CSSToken{CSSTokenType::EndOfFile};
42
+ } else {
43
+ return consumeDelim();
44
+ }
45
+ }
46
+
47
+ char CSSTokenizer::peek() const {
48
+ auto index = position_;
49
+ return index >= remainingCharacters_.size() ? '\0'
50
+ : remainingCharacters_[index];
51
+ }
52
+
53
+ char CSSTokenizer::peekNext() const {
54
+ auto index = position_ + 1;
55
+ return index >= remainingCharacters_.size() ? '\0'
56
+ : remainingCharacters_[index];
57
+ }
58
+
59
+ void CSSTokenizer::advance() {
60
+ react_native_assert(remainingCharacters_.size() > position_);
61
+ position_ += 1;
62
+ }
63
+
64
+ CSSToken CSSTokenizer::consumeDelim() {
65
+ advance();
66
+ return {CSSTokenType::Delim, consumeRunningValue()};
67
+ }
68
+
69
+ CSSToken CSSTokenizer::consumeWhitespace() {
70
+ while (isWhitespace(peek())) {
71
+ advance();
72
+ }
73
+
74
+ consumeRunningValue();
75
+ return CSSToken{CSSTokenType::WhiteSpace};
76
+ }
77
+
78
+ CSSToken CSSTokenizer::consumeNumber() {
79
+ // https://www.w3.org/TR/css-syntax-3/#consume-number
80
+ // https://www.w3.org/TR/css-syntax-3/#convert-a-string-to-a-number
81
+ int32_t signPart = 1.0;
82
+ if (peek() == '+' || peek() == '-') {
83
+ if (peek() == '-') {
84
+ signPart = -1.0;
85
+ }
86
+ advance();
87
+ }
88
+
89
+ int32_t intPart = 0;
90
+ while (isDigit(peek())) {
91
+ intPart = intPart * 10 + (peek() - '0');
92
+ advance();
93
+ }
94
+
95
+ int32_t fractionalPart = 0;
96
+ int32_t fractionDigits = 0;
97
+ if (peek() == '.') {
98
+ advance();
99
+ while (isDigit(peek())) {
100
+ fractionalPart = fractionalPart * 10 + (peek() - '0');
101
+ fractionDigits++;
102
+ advance();
103
+ }
104
+ }
105
+
106
+ int32_t exponentSign = 1.0;
107
+ int32_t exponentPart = 0;
108
+ if (peek() == 'e' || peek() == 'E') {
109
+ advance();
110
+ if (peek() == '+' || peek() == '-') {
111
+ if (peek() == '-') {
112
+ exponentSign = -1.0;
113
+ }
114
+ advance();
115
+ }
116
+
117
+ while (isDigit(peek())) {
118
+ exponentPart = exponentPart * 10 + (peek() - '0');
119
+ advance();
120
+ }
121
+ }
122
+
123
+ auto value = static_cast<float>(
124
+ signPart * (intPart + (fractionalPart * std::pow(10, -fractionDigits))) *
125
+ std::pow(10, exponentSign * exponentPart));
126
+
127
+ consumeRunningValue();
128
+ return {CSSTokenType::Number, value};
129
+ }
130
+
131
+ CSSToken CSSTokenizer::consumeNumeric() {
132
+ // https://www.w3.org/TR/css-syntax-3/#consume-numeric-token
133
+ auto numberToken = consumeNumber();
134
+
135
+ if (isIdent(peek())) {
136
+ auto ident = consumeIdent();
137
+ return {
138
+ CSSTokenType::Dimension,
139
+ numberToken.numericValue(),
140
+ ident.stringValue()};
141
+ } else if (peek() == '%') {
142
+ advance();
143
+ consumeRunningValue();
144
+ return {CSSTokenType::Percent, numberToken.numericValue()};
145
+ } else {
146
+ return numberToken;
147
+ }
148
+ }
149
+
150
+ CSSToken CSSTokenizer::consumeIdent() {
151
+ // https://www.w3.org/TR/css-syntax-3/#consume-an-ident-sequence
152
+ while (isIdent(peek())) {
153
+ advance();
154
+ }
155
+
156
+ return {CSSTokenType::Ident, consumeRunningValue()};
157
+ }
158
+
159
+ std::string_view CSSTokenizer::consumeRunningValue() {
160
+ auto next = remainingCharacters_.substr(0, position_);
161
+ remainingCharacters_ = remainingCharacters_.substr(next.size());
162
+ position_ = 0;
163
+ return next;
164
+ }
165
+
166
+ /*static*/ bool CSSTokenizer::isDigit(char c) {
167
+ // https://www.w3.org/TR/css-syntax-3/#digit
168
+ return c >= '0' && c <= '9';
169
+ }
170
+
171
+ /*static*/ bool CSSTokenizer::isIdentStart(char c) {
172
+ // https://www.w3.org/TR/css-syntax-3/#ident-start-code-point
173
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' ||
174
+ static_cast<unsigned char>(c) > 0x80;
175
+ }
176
+
177
+ /*static*/ bool CSSTokenizer::isIdent(char c) {
178
+ // https://www.w3.org/TR/css-syntax-3/#ident-code-point
179
+ return isIdentStart(c) || isDigit(c) || c == '-';
180
+ }
181
+
182
+ /*static*/ bool CSSTokenizer::isWhitespace(char c) {
183
+ // https://www.w3.org/TR/css-syntax-3/#whitespace
184
+ return c == ' ' || c == '\t' || c == '\r' || c == '\n';
185
+ }
186
+
187
+ } // namespace facebook::react
@@ -0,0 +1,101 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include <string_view>
11
+
12
+ namespace facebook::react {
13
+
14
+ /**
15
+ * One of the tokens defined as part of
16
+ * https://www.w3.org/TR/css-syntax-3/#tokenizer-definitions
17
+ */
18
+ enum class CSSTokenType {
19
+ Delim,
20
+ Dimension,
21
+ EndOfFile,
22
+ Ident,
23
+ Number,
24
+ Percent,
25
+ WhiteSpace,
26
+ };
27
+
28
+ struct CSSToken {
29
+ explicit CSSToken(CSSTokenType type) : type_(type) {}
30
+ CSSToken(CSSTokenType type, std::string_view value)
31
+ : type_{type}, stringValue_{value} {}
32
+ CSSToken(CSSTokenType type, float value)
33
+ : type_{type}, numericValue_{value} {}
34
+ CSSToken(CSSTokenType type, float value, std::string_view unit)
35
+ : type_{type}, numericValue_{value}, unit_{unit} {}
36
+
37
+ CSSToken(const CSSToken& other) = default;
38
+ CSSToken(CSSToken&& other) = default;
39
+ CSSToken& operator=(const CSSToken& other) = default;
40
+ CSSToken& operator=(CSSToken&& other) = default;
41
+
42
+ CSSTokenType type() const {
43
+ return type_;
44
+ }
45
+
46
+ std::string_view stringValue() const {
47
+ return stringValue_;
48
+ }
49
+
50
+ float numericValue() const {
51
+ return numericValue_;
52
+ }
53
+
54
+ std::string_view unit() const {
55
+ return unit_;
56
+ }
57
+
58
+ bool operator==(const CSSToken& other) const = default;
59
+
60
+ private:
61
+ CSSTokenType type_;
62
+ std::string_view stringValue_;
63
+ float numericValue_{0.0f};
64
+ std::string_view unit_;
65
+ };
66
+
67
+ /**
68
+ * A minimal tokenizer for a subset of CSS syntax.
69
+ * `auto`).
70
+ *
71
+ * This is based on the W3C CSS Syntax specification, with simplifications made
72
+ * for syntax which React Native does not attempt to support.
73
+ * https://www.w3.org/TR/css-syntax-3/#tokenizing-and-parsing
74
+ */
75
+ class CSSTokenizer {
76
+ public:
77
+ explicit CSSTokenizer(std::string_view characters);
78
+ CSSToken next();
79
+
80
+ private:
81
+ char peek() const;
82
+ char peekNext() const;
83
+ void advance();
84
+
85
+ CSSToken consumeDelim();
86
+ CSSToken consumeWhitespace();
87
+ CSSToken consumeNumber();
88
+ CSSToken consumeNumeric();
89
+ CSSToken consumeIdent();
90
+
91
+ std::string_view consumeRunningValue();
92
+
93
+ static bool isDigit(char c);
94
+ static bool isIdentStart(char c);
95
+ static bool isIdent(char c);
96
+ static bool isWhitespace(char c);
97
+
98
+ std::string_view remainingCharacters_;
99
+ size_t position_{0};
100
+ };
101
+ } // namespace facebook::react
@@ -0,0 +1,144 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ #include <gtest/gtest.h>
9
+ #include <react/renderer/components/view/CSSTokenizer.h>
10
+ #include <deque>
11
+
12
+ namespace facebook::react {
13
+
14
+ static void expectTokens(
15
+ std::string_view characters,
16
+ std::initializer_list<CSSToken> expectedTokens) {
17
+ CSSTokenizer tokenizer{characters};
18
+
19
+ for (const auto& expectedToken : expectedTokens) {
20
+ auto nextToken = tokenizer.next();
21
+ EXPECT_EQ(nextToken.type(), expectedToken.type());
22
+ EXPECT_EQ(nextToken.stringValue(), expectedToken.stringValue());
23
+ EXPECT_EQ(nextToken.numericValue(), expectedToken.numericValue());
24
+ EXPECT_EQ(nextToken.unit(), expectedToken.unit());
25
+ EXPECT_EQ(nextToken, expectedToken);
26
+ }
27
+ }
28
+
29
+ TEST(CSSTokenizer, eof_values) {
30
+ expectTokens("", {CSSToken{CSSTokenType::EndOfFile}});
31
+ }
32
+
33
+ TEST(CSSTokenizer, whitespace_values) {
34
+ expectTokens(
35
+ " ",
36
+ {CSSToken{CSSTokenType::WhiteSpace}, CSSToken{CSSTokenType::EndOfFile}});
37
+ expectTokens(
38
+ " \t",
39
+ {CSSToken{CSSTokenType::WhiteSpace}, CSSToken{CSSTokenType::EndOfFile}});
40
+ expectTokens(
41
+ "\n \t",
42
+ {CSSToken{CSSTokenType::WhiteSpace}, CSSToken{CSSTokenType::EndOfFile}});
43
+ }
44
+
45
+ TEST(CSSTokenizer, ident_values) {
46
+ expectTokens(
47
+ "auto",
48
+ {CSSToken{CSSTokenType::Ident, "auto"},
49
+ CSSToken{CSSTokenType::EndOfFile}});
50
+
51
+ expectTokens(
52
+ "inset auto left",
53
+ {CSSToken{CSSTokenType::Ident, "inset"},
54
+ CSSToken{CSSTokenType::WhiteSpace},
55
+ CSSToken{CSSTokenType::Ident, "auto"},
56
+ CSSToken{CSSTokenType::WhiteSpace},
57
+ CSSToken{CSSTokenType::Ident, "left"},
58
+ CSSToken{CSSTokenType::EndOfFile}});
59
+ }
60
+
61
+ TEST(CSSTokenizer, number_values) {
62
+ expectTokens(
63
+ "12",
64
+ {CSSToken{CSSTokenType::Number, 12.0f},
65
+ CSSToken{CSSTokenType::EndOfFile}});
66
+
67
+ expectTokens(
68
+ "-5",
69
+ {CSSToken{CSSTokenType::Number, -5.0f},
70
+ CSSToken{CSSTokenType::EndOfFile}});
71
+
72
+ expectTokens(
73
+ "123.0",
74
+ {CSSToken{CSSTokenType::Number, 123.0f},
75
+ CSSToken{CSSTokenType::EndOfFile}});
76
+
77
+ expectTokens(
78
+ "4.2E-1",
79
+ {CSSToken{CSSTokenType::Number, 4.2e-1},
80
+ CSSToken{CSSTokenType::EndOfFile}});
81
+
82
+ expectTokens(
83
+ "6e-10",
84
+ {CSSToken{CSSTokenType::Number, 6e-10f},
85
+ CSSToken{CSSTokenType::EndOfFile}});
86
+
87
+ expectTokens(
88
+ "+81.07e+0",
89
+ {CSSToken{CSSTokenType::Number, +81.07e+0},
90
+ CSSToken{CSSTokenType::EndOfFile}});
91
+ }
92
+
93
+ TEST(CSSTokenizer, dimension_values) {
94
+ expectTokens(
95
+ "12px",
96
+ {CSSToken{CSSTokenType::Dimension, 12.0f, "px"},
97
+ CSSToken{CSSTokenType::EndOfFile}});
98
+
99
+ expectTokens(
100
+ "463.2abc",
101
+ {CSSToken{CSSTokenType::Dimension, 463.2, "abc"},
102
+ CSSToken{CSSTokenType::EndOfFile}});
103
+ }
104
+
105
+ TEST(CSSTokenizer, percent_values) {
106
+ expectTokens(
107
+ "12%",
108
+ {CSSToken{CSSTokenType::Percent, 12.0f},
109
+ CSSToken{CSSTokenType::EndOfFile}});
110
+
111
+ expectTokens(
112
+ "-28.5%",
113
+ {CSSToken{CSSTokenType::Percent, -28.5f},
114
+ CSSToken{CSSTokenType::EndOfFile}});
115
+ }
116
+
117
+ TEST(CSSTokenizer, mixed_values) {
118
+ expectTokens(
119
+ "12px -100vh",
120
+ {CSSToken{CSSTokenType::Dimension, 12.0f, "px"},
121
+ CSSToken{CSSTokenType::WhiteSpace},
122
+ CSSToken{CSSTokenType::Dimension, -100.0f, "vh"},
123
+ CSSToken{CSSTokenType::EndOfFile}});
124
+ }
125
+
126
+ TEST(CSSTokenizer, invalid_values) {
127
+ expectTokens(
128
+ "100*",
129
+ {CSSToken{CSSTokenType::Number, 100.0f},
130
+ CSSToken{CSSTokenType::Delim, "*"},
131
+ CSSToken{CSSTokenType::EndOfFile}});
132
+
133
+ expectTokens(
134
+ "+",
135
+ {CSSToken{CSSTokenType::Delim, "+"}, CSSToken{CSSTokenType::EndOfFile}});
136
+
137
+ expectTokens(
138
+ "(%",
139
+ {CSSToken{CSSTokenType::Delim, "("},
140
+ CSSToken{CSSTokenType::Delim, "%"},
141
+ CSSToken{CSSTokenType::EndOfFile}});
142
+ }
143
+
144
+ } // namespace facebook::react
@@ -15,7 +15,6 @@
15
15
  #include <react/renderer/core/ShadowNode.h>
16
16
  #include <react/renderer/core/State.h>
17
17
  #include <react/renderer/core/StateData.h>
18
- #include <react/renderer/graphics/Float.h>
19
18
  #include <react/utils/ContextContainer.h>
20
19
 
21
20
  namespace facebook::react {
@@ -38,20 +38,3 @@ enum class LayoutDirection {
38
38
  };
39
39
 
40
40
  } // namespace facebook::react
41
-
42
- namespace std {
43
- template <>
44
- struct hash<facebook::react::LayoutDirection> {
45
- size_t operator()(const facebook::react::LayoutDirection& v) const {
46
- return hash<int>()(static_cast<int>(v));
47
- }
48
- };
49
-
50
- template <>
51
- struct hash<facebook::react::DisplayType> {
52
- size_t operator()(const facebook::react::DisplayType& v) const {
53
- return hash<int>()(static_cast<int>(v));
54
- }
55
- };
56
-
57
- } // namespace std
@@ -13,7 +13,6 @@
13
13
  #include <react/renderer/core/RawProps.h>
14
14
  #include <react/renderer/core/RawPropsKey.h>
15
15
  #include <react/renderer/core/graphicsConversions.h>
16
- #include <react/renderer/graphics/Color.h>
17
16
 
18
17
  namespace facebook::react {
19
18
 
@@ -29,7 +29,11 @@ class SharedColor {
29
29
 
30
30
  SharedColor(Color color) : color_(color) {}
31
31
 
32
- Color operator*() const {
32
+ Color& operator*() {
33
+ return color_;
34
+ }
35
+
36
+ const Color& operator*() const {
33
37
  return color_;
34
38
  }
35
39
 
@@ -61,7 +65,7 @@ SharedColor whiteColor();
61
65
 
62
66
  template <>
63
67
  struct std::hash<facebook::react::SharedColor> {
64
- size_t operator()(facebook::react::SharedColor color) const {
65
- return std::hash<decltype(*color)>{}(*color);
68
+ size_t operator()(const facebook::react::SharedColor& color) const {
69
+ return std::hash<facebook::react::Color>{}(*color);
66
70
  }
67
71
  };
@@ -28,6 +28,8 @@ Pod::Spec.new do |s|
28
28
  "\"$(PODS_ROOT)/boost\"",
29
29
  "\"$(PODS_TARGET_SRCROOT)/../../../\"",
30
30
  "\"$(PODS_ROOT)/RCT-Folly\"",
31
+ "\"$(PODS_ROOT)/DoubleConversion\"",
32
+ "\"$(PODS_ROOT)/fmt/include\""
31
33
  ]
32
34
 
33
35
  s.name = "React-graphics"
@@ -42,7 +44,8 @@ Pod::Spec.new do |s|
42
44
  s.source_files = source_files
43
45
  s.exclude_files = "tests",
44
46
  "platform/android",
45
- "platform/cxx"
47
+ "platform/cxx",
48
+ "platform/windows",
46
49
  s.header_dir = "react/renderer/graphics"
47
50
 
48
51
  if ENV['USE_FRAMEWORKS']
@@ -60,4 +63,6 @@ Pod::Spec.new do |s|
60
63
  s.dependency "RCT-Folly/Fabric", folly_version
61
64
  s.dependency "React-Core/Default", version
62
65
  s.dependency "React-utils"
66
+ s.dependency "DoubleConversion"
67
+ s.dependency "fmt", "9.1.0"
63
68
  end
@@ -8,32 +8,72 @@
8
8
  #pragma once
9
9
 
10
10
  #include <react/renderer/graphics/ColorComponents.h>
11
+ #include <react/utils/hash_combine.h>
11
12
  #include <cmath>
12
13
 
13
14
  namespace facebook::react {
14
15
 
15
- using Color = int32_t;
16
+ struct DynamicColor {
17
+ int32_t lightColor = 0;
18
+ int32_t darkColor = 0;
19
+ int32_t highContrastLightColor = 0;
20
+ int32_t highContrastDarkColor = 0;
21
+ };
22
+
23
+ struct Color {
24
+ Color(int32_t color);
25
+ Color(const DynamicColor& dynamicColor);
26
+ Color(const ColorComponents& components);
27
+ Color(std::shared_ptr<void> uiColor);
28
+ int32_t getColor() const;
29
+ std::shared_ptr<void> getUIColor() const {
30
+ return uiColor_;
31
+ }
32
+ ColorComponents getColorComponents() const {
33
+ float ratio = 255;
34
+ int32_t primitiveColor = getColor();
35
+ return ColorComponents{
36
+ (float)((primitiveColor >> 16) & 0xff) / ratio,
37
+ (float)((primitiveColor >> 8) & 0xff) / ratio,
38
+ (float)((primitiveColor >> 0) & 0xff) / ratio,
39
+ (float)((primitiveColor >> 24) & 0xff) / ratio};
40
+ }
41
+ bool operator==(const Color& other) const;
42
+ bool operator!=(const Color& other) const;
43
+ operator int32_t() const {
44
+ return getColor();
45
+ }
46
+
47
+ private:
48
+ std::shared_ptr<void> uiColor_;
49
+ };
16
50
 
17
51
  namespace HostPlatformColor {
18
- static const facebook::react::Color UndefinedColor =
19
- std::numeric_limits<facebook::react::Color>::max();
20
- }
52
+
53
+ #if defined(__clang__)
54
+ #define NO_DESTROY [[clang::no_destroy]]
55
+ #else
56
+ #define NO_DESTROY
57
+ #endif
58
+
59
+ NO_DESTROY static const facebook::react::Color UndefinedColor = Color(nullptr);
60
+ } // namespace HostPlatformColor
21
61
 
22
62
  inline Color hostPlatformColorFromComponents(ColorComponents components) {
23
- float ratio = 255;
24
- return ((int)round(components.alpha * ratio) & 0xff) << 24 |
25
- ((int)round(components.red * ratio) & 0xff) << 16 |
26
- ((int)round(components.green * ratio) & 0xff) << 8 |
27
- ((int)round(components.blue * ratio) & 0xff);
63
+ return Color(components);
28
64
  }
29
65
 
30
66
  inline ColorComponents colorComponentsFromHostPlatformColor(Color color) {
31
- float ratio = 255;
32
- return ColorComponents{
33
- (float)((color >> 16) & 0xff) / ratio,
34
- (float)((color >> 8) & 0xff) / ratio,
35
- (float)((color >> 0) & 0xff) / ratio,
36
- (float)((color >> 24) & 0xff) / ratio};
67
+ return color.getColorComponents();
37
68
  }
38
69
 
39
70
  } // namespace facebook::react
71
+
72
+ template <>
73
+ struct std::hash<facebook::react::Color> {
74
+ size_t operator()(const facebook::react::Color& color) const {
75
+ auto seed = size_t{0};
76
+ facebook::react::hash_combine(seed, color.getColor());
77
+ return seed;
78
+ }
79
+ };