react-native 0.74.0-nightly-20240128-cfc0ba04a → 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.
- package/Libraries/Animated/NativeAnimatedHelper.js +1 -1
- package/Libraries/Animated/nodes/AnimatedStyle.js +1 -1
- package/Libraries/Animated/useAnimatedProps.js +1 -1
- package/Libraries/AppDelegate/RCTAppDelegate.mm +2 -1
- package/Libraries/Blob/React-RCTBlob.podspec +1 -0
- package/Libraries/Components/PopupMenuAndroid/PopupMenuAndroid.android.js +69 -0
- package/Libraries/Components/PopupMenuAndroid/PopupMenuAndroid.d.ts +24 -0
- package/Libraries/Components/PopupMenuAndroid/PopupMenuAndroid.js +33 -0
- package/Libraries/Components/PopupMenuAndroid/PopupMenuAndroidNativeComponent.js +13 -0
- package/Libraries/Core/ReactNativeVersion.js +2 -3
- package/Libraries/Core/ReactNativeVersionCheck.js +1 -1
- package/Libraries/Core/registerCallableModule.js +42 -0
- package/Libraries/Image/RCTImageLoader.mm +4 -11
- package/Libraries/LayoutAnimation/LayoutAnimation.js +1 -1
- package/Libraries/ReactNative/BridgelessUIManager.js +31 -13
- package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +1 -1
- package/Libraries/ReactNative/ReactNativeFeatureFlags.js +0 -33
- package/Libraries/ReactNative/__mocks__/FabricUIManager.js +12 -0
- package/Libraries/Renderer/implementations/ReactFabric-dev.js +24543 -21110
- package/Libraries/Renderer/implementations/ReactFabric-prod.js +4104 -3058
- package/Libraries/Renderer/implementations/ReactFabric-profiling.js +4352 -3273
- package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +25038 -21457
- package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +3721 -2600
- package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +4024 -2869
- package/Libraries/StyleSheet/StyleSheetTypes.d.ts +43 -4
- package/Libraries/WebPerformance/Performance.js +1 -1
- package/React/Base/RCTBridge+Private.h +14 -0
- package/React/Base/RCTBridge.mm +6 -0
- package/React/Base/RCTKeyCommands.m +12 -1
- package/React/Base/RCTVersion.m +3 -3
- package/React/CoreModules/RCTAlertController.mm +2 -3
- package/React/CoreModules/RCTAppearance.mm +1 -1
- package/React/CoreModules/React-CoreModules.podspec +1 -0
- package/React/CxxBridge/RCTCxxBridge.mm +21 -3
- package/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm +22 -1
- package/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +13 -2
- package/React/Fabric/RCTConversions.h +2 -18
- package/React/React-RCTFabric.podspec +1 -0
- package/React-Core.podspec +1 -3
- package/ReactAndroid/api/ReactAndroid.api +53 -1
- package/ReactAndroid/gradle.properties +1 -1
- package/ReactAndroid/src/main/java/com/facebook/react/animated/AnimatedNode.java +3 -1
- package/ReactAndroid/src/main/java/com/facebook/react/animated/DecayAnimation.java +2 -0
- package/ReactAndroid/src/main/java/com/facebook/react/animated/DiffClampAnimatedNode.java +3 -1
- package/ReactAndroid/src/main/java/com/facebook/react/animated/ModulusAnimatedNode.java +3 -1
- package/ReactAndroid/src/main/java/com/facebook/react/animated/ObjectAnimatedNode.java +3 -1
- package/ReactAndroid/src/main/java/com/facebook/react/animated/SpringAnimation.java +3 -1
- package/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java +1 -3
- package/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt +5 -2
- package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt +11 -1
- package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt +11 -1
- package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt +3 -1
- package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt +3 -1
- package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt +12 -1
- package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt +3 -1
- package/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutor.kt +1 -1
- package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +3 -3
- package/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java +3 -0
- package/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java +13 -1
- package/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java +7 -0
- package/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +11 -0
- package/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstantsHelper.java +9 -1
- package/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIViewOperationQueue.java +24 -0
- package/ReactAndroid/src/main/java/com/facebook/react/views/image/ScaleTypeStartInside.java +1 -1
- package/ReactAndroid/src/main/java/com/facebook/react/views/popupmenu/PopupMenuSelectionEvent.kt +37 -0
- package/ReactAndroid/src/main/java/com/facebook/react/views/popupmenu/ReactPopupMenuContainer.kt +49 -0
- package/ReactAndroid/src/main/java/com/facebook/react/views/popupmenu/ReactPopupMenuManager.kt +54 -0
- package/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java +2 -2
- package/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java +2 -2
- package/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManagerMapBuffer.java +2 -2
- package/ReactAndroid/src/main/jni/react/fabric/CoreComponentsRegistry.cpp +2 -0
- package/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp +9 -1
- package/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h +4 -1
- package/ReactAndroid/src/main/jni/react/featureflags/ReactNativeFeatureFlagsProviderHolder.cpp +7 -1
- package/ReactAndroid/src/main/jni/react/featureflags/ReactNativeFeatureFlagsProviderHolder.h +2 -1
- package/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp +16 -10
- package/ReactAndroid/src/main/jni/react/jni/ProxyExecutor.cpp +0 -3
- package/ReactAndroid/src/main/jni/react/jni/ProxyExecutor.h +0 -1
- package/ReactAndroid/src/main/jni/react/newarchdefaults/DefaultComponentsRegistry.cpp +7 -6
- package/ReactCommon/cxxreact/Instance.cpp +34 -18
- package/ReactCommon/cxxreact/Instance.h +13 -2
- package/ReactCommon/cxxreact/React-cxxreact.podspec +1 -1
- package/ReactCommon/cxxreact/ReactNativeVersion.h +2 -2
- package/ReactCommon/jsinspector-modern/InstanceAgent.cpp +34 -0
- package/ReactCommon/jsinspector-modern/InstanceAgent.h +54 -0
- package/ReactCommon/jsinspector-modern/InstanceTarget.cpp +25 -0
- package/ReactCommon/jsinspector-modern/InstanceTarget.h +58 -0
- package/ReactCommon/jsinspector-modern/PageAgent.cpp +65 -0
- package/ReactCommon/jsinspector-modern/PageAgent.h +13 -0
- package/ReactCommon/jsinspector-modern/PageTarget.cpp +41 -0
- package/ReactCommon/jsinspector-modern/PageTarget.h +28 -1
- package/ReactCommon/jsinspector-modern/React-jsinspector.podspec +12 -1
- package/ReactCommon/jsinspector-modern/ReactCdp.h +1 -0
- package/ReactCommon/jsinspector-modern/tests/InspectorMocks.h +2 -0
- package/ReactCommon/jsinspector-modern/tests/PageTargetTest.cpp +164 -10
- package/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp +5 -1
- package/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h +6 -1
- package/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp +18 -1
- package/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h +3 -1
- package/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h +5 -1
- package/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h +2 -1
- package/ReactCommon/react/featureflags/tests/ReactNativeFeatureFlagsTest.cpp +4 -0
- package/ReactCommon/react/nativemodule/core/platform/ios/React-NativeModulesApple.podspec +1 -0
- package/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp +6 -1
- package/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h +3 -1
- package/ReactCommon/react/renderer/attributedstring/primitives.h +0 -86
- package/ReactCommon/react/renderer/components/text/ParagraphShadowNode.cpp +4 -1
- package/ReactCommon/react/renderer/components/view/AccessibilityPrimitives.h +0 -16
- package/ReactCommon/react/renderer/components/view/CSSTokenizer.cpp +187 -0
- package/ReactCommon/react/renderer/components/view/CSSTokenizer.h +101 -0
- package/ReactCommon/react/renderer/components/view/tests/CSSTokenizerTest.cpp +144 -0
- package/ReactCommon/react/renderer/core/ComponentDescriptor.h +0 -1
- package/ReactCommon/react/renderer/core/EventEmitter.cpp +14 -6
- package/ReactCommon/react/renderer/core/LayoutPrimitives.h +0 -17
- package/ReactCommon/react/renderer/core/graphicsConversions.h +2 -23
- package/ReactCommon/react/renderer/core/propsConversions.h +0 -1
- package/ReactCommon/react/renderer/graphics/Color.h +7 -3
- package/ReactCommon/react/renderer/graphics/React-graphics.podspec +6 -1
- package/ReactCommon/react/renderer/graphics/fromRawValueShared.h +50 -0
- package/ReactCommon/react/renderer/graphics/platform/android/react/renderer/graphics/PlatformColorParser.h +18 -7
- package/ReactCommon/react/renderer/graphics/platform/cxx/react/renderer/graphics/PlatformColorParser.h +16 -4
- package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.h +55 -15
- package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm +132 -0
- package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/PlatformColorParser.h +15 -17
- package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/PlatformColorParser.mm +73 -0
- package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.h +8 -2
- package/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.mm +14 -3
- package/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextPrimitivesConversions.h +4 -19
- package/ReactCommon/react/runtime/ReactInstance.cpp +15 -2
- package/ReactCommon/react/runtime/ReactInstance.h +13 -2
- package/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm +5 -3
- package/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.h +3 -1
- package/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm +10 -2
- package/ReactCommon/react/test_utils/ios/Shims/ShimRCTInstance.mm +5 -2
- package/ReactCommon/react/utils/hash_combine.h +8 -6
- package/gradle/libs.versions.toml +1 -1
- package/index.js +9 -0
- package/package.json +9 -9
- package/sdks/hermesc/osx-bin/hermes +0 -0
- package/sdks/hermesc/osx-bin/hermesc +0 -0
- package/sdks/hermesc/win64-bin/hermesc.exe +0 -0
- package/src/private/featureflags/NativeReactNativeFeatureFlags.js +2 -1
- package/src/private/featureflags/ReactNativeFeatureFlags.js +42 -1
- package/src/private/specs/components/PopupMenuAndroidNativeComponent.js +47 -0
- package/template/Gemfile +3 -1
- package/template/package.json +5 -5
- package/Libraries/Performance/QuickPerformanceLogger.js +0 -155
- 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
|
|
@@ -16,18 +16,26 @@
|
|
|
16
16
|
|
|
17
17
|
namespace facebook::react {
|
|
18
18
|
|
|
19
|
+
static bool hasPrefix(const std::string& str, const std::string& prefix) {
|
|
20
|
+
return str.compare(0, prefix.length(), prefix) == 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
19
23
|
// TODO(T29874519): Get rid of "top" prefix once and for all.
|
|
20
24
|
/*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
25
|
+
* Replaces "on" with "top" if present. Or capitalizes the first letter and adds
|
|
26
|
+
* "top" prefix. E.g. "eventName" becomes "topEventName", "onEventName" also
|
|
27
|
+
* becomes "topEventName".
|
|
23
28
|
*/
|
|
24
29
|
static std::string normalizeEventType(std::string type) {
|
|
25
30
|
auto prefixedType = std::move(type);
|
|
26
|
-
if (prefixedType
|
|
27
|
-
prefixedType
|
|
28
|
-
|
|
31
|
+
if (facebook::react::hasPrefix(prefixedType, "top")) {
|
|
32
|
+
return prefixedType;
|
|
33
|
+
}
|
|
34
|
+
if (facebook::react::hasPrefix(prefixedType, "on")) {
|
|
35
|
+
return "top" + prefixedType.substr(2);
|
|
29
36
|
}
|
|
30
|
-
|
|
37
|
+
prefixedType[0] = static_cast<char>(toupper(prefixedType[0]));
|
|
38
|
+
return "top" + prefixedType;
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
std::mutex& EventEmitter::DispatchMutex() {
|
|
@@ -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
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
#include <react/renderer/core/PropsParserContext.h>
|
|
15
15
|
#include <react/renderer/core/RawProps.h>
|
|
16
16
|
#include <react/renderer/graphics/Color.h>
|
|
17
|
+
#include <react/renderer/graphics/Float.h>
|
|
17
18
|
#include <react/renderer/graphics/PlatformColorParser.h>
|
|
18
19
|
#include <react/renderer/graphics/Point.h>
|
|
19
20
|
#include <react/renderer/graphics/Rect.h>
|
|
@@ -29,29 +30,7 @@ inline void fromRawValue(
|
|
|
29
30
|
const PropsParserContext& context,
|
|
30
31
|
const RawValue& value,
|
|
31
32
|
SharedColor& result) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (value.hasType<int>()) {
|
|
35
|
-
auto argb = (int64_t)value;
|
|
36
|
-
auto ratio = 255.f;
|
|
37
|
-
colorComponents.alpha = ((argb >> 24) & 0xFF) / ratio;
|
|
38
|
-
colorComponents.red = ((argb >> 16) & 0xFF) / ratio;
|
|
39
|
-
colorComponents.green = ((argb >> 8) & 0xFF) / ratio;
|
|
40
|
-
colorComponents.blue = (argb & 0xFF) / ratio;
|
|
41
|
-
} else if (value.hasType<std::vector<float>>()) {
|
|
42
|
-
auto items = (std::vector<float>)value;
|
|
43
|
-
auto length = items.size();
|
|
44
|
-
react_native_expect(length == 3 || length == 4);
|
|
45
|
-
colorComponents.red = items.at(0);
|
|
46
|
-
colorComponents.green = items.at(1);
|
|
47
|
-
colorComponents.blue = items.at(2);
|
|
48
|
-
colorComponents.alpha = length == 4 ? items.at(3) : 1.0f;
|
|
49
|
-
} else {
|
|
50
|
-
result = parsePlatformColor(context, value);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
result = colorFromComponents(colorComponents);
|
|
33
|
+
fromRawValue(context.contextContainer, context.surfaceId, value, result);
|
|
55
34
|
}
|
|
56
35
|
|
|
57
36
|
#ifdef ANDROID
|
|
@@ -29,7 +29,11 @@ class SharedColor {
|
|
|
29
29
|
|
|
30
30
|
SharedColor(Color color) : color_(color) {}
|
|
31
31
|
|
|
32
|
-
Color operator*()
|
|
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<
|
|
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
|
|
@@ -0,0 +1,50 @@
|
|
|
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 <react/debug/react_native_expect.h>
|
|
9
|
+
#include <react/renderer/core/RawValue.h>
|
|
10
|
+
#include <react/renderer/graphics/Color.h>
|
|
11
|
+
#include <react/utils/ContextContainer.h>
|
|
12
|
+
|
|
13
|
+
#pragma once
|
|
14
|
+
|
|
15
|
+
namespace facebook::react {
|
|
16
|
+
using parsePlatformColorFn =
|
|
17
|
+
SharedColor (*)(const ContextContainer&, int32_t, const RawValue&);
|
|
18
|
+
|
|
19
|
+
inline void fromRawValueShared(
|
|
20
|
+
const ContextContainer& contextContainer,
|
|
21
|
+
int32_t surfaceId,
|
|
22
|
+
const RawValue& value,
|
|
23
|
+
SharedColor& result,
|
|
24
|
+
parsePlatformColorFn parsePlatformColor) {
|
|
25
|
+
ColorComponents colorComponents = {0, 0, 0, 0};
|
|
26
|
+
|
|
27
|
+
if (value.hasType<int>()) {
|
|
28
|
+
auto argb = (int64_t)value;
|
|
29
|
+
auto ratio = 255.f;
|
|
30
|
+
colorComponents.alpha = ((argb >> 24) & 0xFF) / ratio;
|
|
31
|
+
colorComponents.red = ((argb >> 16) & 0xFF) / ratio;
|
|
32
|
+
colorComponents.green = ((argb >> 8) & 0xFF) / ratio;
|
|
33
|
+
colorComponents.blue = (argb & 0xFF) / ratio;
|
|
34
|
+
|
|
35
|
+
result = colorFromComponents(colorComponents);
|
|
36
|
+
} else if (value.hasType<std::vector<float>>()) {
|
|
37
|
+
auto items = (std::vector<float>)value;
|
|
38
|
+
auto length = items.size();
|
|
39
|
+
react_native_expect(length == 3 || length == 4);
|
|
40
|
+
colorComponents.red = items.at(0);
|
|
41
|
+
colorComponents.green = items.at(1);
|
|
42
|
+
colorComponents.blue = items.at(2);
|
|
43
|
+
colorComponents.alpha = length == 4 ? items.at(3) : 1.0f;
|
|
44
|
+
|
|
45
|
+
result = colorFromComponents(colorComponents);
|
|
46
|
+
} else {
|
|
47
|
+
result = parsePlatformColor(contextContainer, surfaceId, value);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} // namespace facebook::react
|