react-native-unistyles 3.0.0-alpha.40 → 3.0.0-alpha.41
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +3 -0
- package/android/build.gradle +10 -0
- package/android/src/main/java/com/unistyles/NativePlatform+android.kt +10 -1
- package/cxx/common/Constants.h +1 -0
- package/cxx/core/UnistyleData.h +3 -2
- package/cxx/core/UnistylesRegistry.cpp +9 -5
- package/cxx/core/UnistylesRegistry.h +2 -2
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +5 -2
- package/cxx/parser/Parser.cpp +24 -3
- package/cxx/parser/Parser.h +1 -0
- package/cxx/shadowTree/ShadowLeafUpdate.h +1 -0
- package/cxx/shadowTree/ShadowTreeManager.cpp +4 -0
- package/ios/Extensions.swift +3 -1
- package/ios/NativePlatform+ios.swift +13 -2
- package/ios/NativePlatformListener+ios.swift +0 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +2 -2
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +2 -2
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -2
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +1 -1
- package/package.json +3 -3
- package/plugin/index.js +5 -5
- package/plugin/ref.js +21 -11
- package/plugin/style.js +21 -2
- package/src/specs/ShadowRegistry/index.ts +4 -4
package/android/CMakeLists.txt
CHANGED
@@ -34,3 +34,6 @@ set_target_properties(unistyles PROPERTIES
|
|
34
34
|
|
35
35
|
# For React Native 0.76 and above, we don't need to link anything
|
36
36
|
# as NitroModules will automatically add ReactAndroid::reactnative prefab
|
37
|
+
if (ReactAndroid_VERSION_MINOR LESS 76)
|
38
|
+
message(FATAL_ERROR "Unistyles 3.0 requires min. React Native version to be 0.76")
|
39
|
+
endif ()
|
package/android/build.gradle
CHANGED
@@ -79,3 +79,13 @@ dependencies {
|
|
79
79
|
implementation 'com.facebook.react:react-native'
|
80
80
|
implementation project(":react-native-nitro-modules")
|
81
81
|
}
|
82
|
+
|
83
|
+
tasks.register("checkNativeTurboUnistylesSpec") {
|
84
|
+
doLast {
|
85
|
+
if (!isNewArchitectureEnabled()) {
|
86
|
+
throw new GradleException("Unistyles 3.0 requires your project to have New Architecture enabled.")
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
preBuild.dependsOn checkNativeTurboUnistylesSpec
|
@@ -8,6 +8,7 @@ import android.view.View
|
|
8
8
|
import android.view.WindowManager
|
9
9
|
import androidx.core.text.TextUtilsCompat
|
10
10
|
import androidx.core.view.ViewCompat
|
11
|
+
import androidx.core.view.WindowCompat
|
11
12
|
import androidx.core.view.WindowInsetsCompat
|
12
13
|
import androidx.core.view.WindowInsetsControllerCompat
|
13
14
|
import com.facebook.react.bridge.LifecycleEventListener
|
@@ -279,7 +280,15 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
279
280
|
try {
|
280
281
|
Class.forName("com.zoontek.rnedgetoedge.EdgeToEdgePackage")
|
281
282
|
} catch (exception: ClassNotFoundException) {
|
282
|
-
|
283
|
+
enableEdgeToEdge()
|
284
|
+
}
|
285
|
+
}
|
286
|
+
|
287
|
+
private fun enableEdgeToEdge() {
|
288
|
+
reactContext.currentActivity?.let { activity ->
|
289
|
+
activity.runOnUiThread {
|
290
|
+
WindowCompat.setDecorFitsSystemWindows(activity.window, false)
|
291
|
+
}
|
283
292
|
}
|
284
293
|
}
|
285
294
|
}
|
package/cxx/common/Constants.h
CHANGED
@@ -9,5 +9,6 @@ static const std::string STYLE_VARIANTS = "uni__variants";
|
|
9
9
|
static const std::string WEB_STYLE_KEY = "_web";
|
10
10
|
static const std::string EXOTIC_STYLE_KEY = "_exotic";
|
11
11
|
static const std::string NAME_STYLE_KEY = "__unistyles_name";
|
12
|
+
static const std::string UNI_PRESSABLE_ID = "__uni_pressable_id";
|
12
13
|
|
13
14
|
}
|
package/cxx/core/UnistyleData.h
CHANGED
@@ -8,8 +8,8 @@ namespace margelo::nitro::unistyles::core {
|
|
8
8
|
using Variants = std::vector<std::pair<std::string, std::string>>;
|
9
9
|
|
10
10
|
struct UnistyleData {
|
11
|
-
UnistyleData(Unistyle::Shared unistyle, const Variants& variants, std::vector<folly::dynamic>& arguments)
|
12
|
-
: unistyle{unistyle}, variants(std::move(variants)), dynamicFunctionMetadata{std::move(arguments)} {}
|
11
|
+
UnistyleData(Unistyle::Shared unistyle, const Variants& variants, std::vector<folly::dynamic>& arguments, std::optional<std::string> uniquePressableId)
|
12
|
+
: unistyle{unistyle}, variants(std::move(variants)), dynamicFunctionMetadata{std::move(arguments)}, pressableId{std::move(uniquePressableId)} {}
|
13
13
|
|
14
14
|
UnistyleData(const UnistyleData&) = delete;
|
15
15
|
UnistyleData(UnistyleData&& other) = delete;
|
@@ -18,6 +18,7 @@ struct UnistyleData {
|
|
18
18
|
core::Variants variants;
|
19
19
|
std::optional<jsi::Object> parsedStyle = std::nullopt;
|
20
20
|
std::optional<std::vector<folly::dynamic>> dynamicFunctionMetadata = std::nullopt;
|
21
|
+
std::optional<std::string> pressableId = std::nullopt;
|
21
22
|
};
|
22
23
|
|
23
24
|
}
|
@@ -73,7 +73,8 @@ void core::UnistylesRegistry::linkShadowNodeWithUnistyle(
|
|
73
73
|
const ShadowNodeFamily* shadowNodeFamily,
|
74
74
|
std::vector<core::Unistyle::Shared>& unistyles,
|
75
75
|
Variants& variants,
|
76
|
-
std::vector<std::vector<folly::dynamic>>& arguments
|
76
|
+
std::vector<std::vector<folly::dynamic>>& arguments,
|
77
|
+
std::optional<std::string> uniquePressableId
|
77
78
|
) {
|
78
79
|
auto parser = parser::Parser(nullptr);
|
79
80
|
shadow::ShadowLeafUpdates updates;
|
@@ -81,7 +82,7 @@ void core::UnistylesRegistry::linkShadowNodeWithUnistyle(
|
|
81
82
|
for (size_t index = 0; index < unistyles.size(); index++) {
|
82
83
|
Unistyle::Shared unistyle = unistyles[index];
|
83
84
|
|
84
|
-
this->_shadowRegistry[&rt][shadowNodeFamily].emplace_back(std::make_shared<UnistyleData>(unistyle, variants, arguments[index]));
|
85
|
+
this->_shadowRegistry[&rt][shadowNodeFamily].emplace_back(std::make_shared<UnistyleData>(unistyle, variants, arguments[index], uniquePressableId));
|
85
86
|
|
86
87
|
// add or update node for shadow leaf updates
|
87
88
|
// dynamic functions are parsed later
|
@@ -148,15 +149,18 @@ core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt
|
|
148
149
|
|
149
150
|
// called from proxied function only, we don't know host
|
150
151
|
// so we need to rebuild all instances as they may have different variants
|
151
|
-
void core::UnistylesRegistry::shadowLeafUpdateFromUnistyle(jsi::Runtime& rt, Unistyle::Shared unistyle) {
|
152
|
+
void core::UnistylesRegistry::shadowLeafUpdateFromUnistyle(jsi::Runtime& rt, Unistyle::Shared unistyle, std::optional<std::string> uniquePressableId) {
|
152
153
|
shadow::ShadowLeafUpdates updates;
|
153
154
|
auto parser = parser::Parser(nullptr);
|
154
155
|
|
155
156
|
for (const auto& [family, unistyles] : this->_shadowRegistry[&rt]) {
|
156
157
|
for (const auto& unistyleData : unistyles) {
|
157
158
|
if (unistyleData->unistyle == unistyle) {
|
158
|
-
//
|
159
|
-
unistyleData->
|
159
|
+
// special case for pressable
|
160
|
+
if (uniquePressableId.has_value() && unistyleData->pressableId.has_value() && uniquePressableId.value() == unistyleData->pressableId.value()) {
|
161
|
+
unistyleData->parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
|
162
|
+
}
|
163
|
+
|
160
164
|
updates[family] = parser.parseStylesToShadowTreeStyles(rt, { unistyleData });
|
161
165
|
}
|
162
166
|
}
|
@@ -37,11 +37,11 @@ struct UnistylesRegistry: public StyleSheetRegistry {
|
|
37
37
|
UnistylesState& getState(jsi::Runtime& rt);
|
38
38
|
void createState(jsi::Runtime& rt);
|
39
39
|
std::vector<std::shared_ptr<core::StyleSheet>> getStyleSheetsToRefresh(jsi::Runtime& rt, std::vector<UnistyleDependency>& unistylesDependencies);
|
40
|
-
void linkShadowNodeWithUnistyle(jsi::Runtime& rt, const ShadowNodeFamily*, std::vector<core::Unistyle::Shared>& unistyles, Variants& variants, std::vector<std::vector<folly::dynamic
|
40
|
+
void linkShadowNodeWithUnistyle(jsi::Runtime& rt, const ShadowNodeFamily*, std::vector<core::Unistyle::Shared>& unistyles, Variants& variants, std::vector<std::vector<folly::dynamic>>&, std::optional<std::string> uniquePressableId);
|
41
41
|
void unlinkShadowNodeWithUnistyles(jsi::Runtime& rt, const ShadowNodeFamily*);
|
42
42
|
std::shared_ptr<core::StyleSheet> addStyleSheet(jsi::Runtime& rt, int tag, core::StyleSheetType type, jsi::Object&& rawValue);
|
43
43
|
DependencyMap buildDependencyMap(jsi::Runtime& rt, std::vector<UnistyleDependency>& deps);
|
44
|
-
void shadowLeafUpdateFromUnistyle(jsi::Runtime& rt, Unistyle::Shared unistyle);
|
44
|
+
void shadowLeafUpdateFromUnistyle(jsi::Runtime& rt, Unistyle::Shared unistyle, std::optional<std::string> uniquePressableId);
|
45
45
|
shadow::ShadowTrafficController trafficController{};
|
46
46
|
|
47
47
|
private:
|
@@ -4,12 +4,15 @@ using namespace margelo::nitro::unistyles;
|
|
4
4
|
using namespace facebook::react;
|
5
5
|
|
6
6
|
jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
|
7
|
-
helpers::assertThat(rt, count ==
|
7
|
+
helpers::assertThat(rt, count == 5, "Unistyles: Invalid babel transform 'ShadowRegistry link' expected 5 arguments.");
|
8
8
|
|
9
9
|
ShadowNode::Shared shadowNodeWrapper = shadowNodeFromValue(rt, args[0]);
|
10
10
|
std::vector<core::Unistyle::Shared> unistyleWrappers = core::unistyleFromValue(rt, args[1]);
|
11
11
|
core::Variants variants = helpers::variantsToPairs(rt, args[2].asObject(rt));
|
12
12
|
jsi::Array rawArguments = args[3].asObject(rt).asArray(rt);
|
13
|
+
std::optional<std::string> uniquePressableId = args[4].isUndefined()
|
14
|
+
? std::nullopt
|
15
|
+
: std::make_optional<std::string>(args[4].asString(rt).utf8(rt));
|
13
16
|
std::vector<std::vector<folly::dynamic>> arguments;
|
14
17
|
auto& registry = core::UnistylesRegistry::get();
|
15
18
|
|
@@ -17,7 +20,7 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
|
|
17
20
|
arguments.push_back(helpers::parseDynamicFunctionArguments(rt, value.asObject(rt).asArray(rt)));
|
18
21
|
});
|
19
22
|
|
20
|
-
registry.linkShadowNodeWithUnistyle(rt, &shadowNodeWrapper->getFamily(), unistyleWrappers, variants, arguments);
|
23
|
+
registry.linkShadowNodeWithUnistyle(rt, &shadowNodeWrapper->getFamily(), unistyleWrappers, variants, arguments, uniquePressableId);
|
21
24
|
|
22
25
|
return jsi::Value::undefined();
|
23
26
|
}
|
package/cxx/parser/Parser.cpp
CHANGED
@@ -210,6 +210,7 @@ void parser::Parser::rebuildShadowLeafUpdates(jsi::Runtime& rt, core::Dependency
|
|
210
210
|
auto& registry = core::UnistylesRegistry::get();
|
211
211
|
|
212
212
|
for (const auto& [shadowNode, unistyles] : dependencyMap) {
|
213
|
+
// this step is required to parse string colors eg. #000000 to int representation
|
213
214
|
auto rawProps = this->parseStylesToShadowTreeStyles(rt, unistyles);
|
214
215
|
|
215
216
|
updates.emplace(shadowNode, std::move(rawProps));
|
@@ -333,6 +334,26 @@ jsi::Object parser::Parser::parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared u
|
|
333
334
|
return parsedStyle;
|
334
335
|
}
|
335
336
|
|
337
|
+
std::optional<std::string> parser::Parser::getUniquePressableIdFromArguments(jsi::Runtime& rt, const jsi::Value* args, size_t count) {
|
338
|
+
if (count == 0) {
|
339
|
+
return std::nullopt;
|
340
|
+
}
|
341
|
+
|
342
|
+
auto& lastArg = args[count - 1];
|
343
|
+
|
344
|
+
if (!lastArg.isObject()) {
|
345
|
+
return std::nullopt;
|
346
|
+
}
|
347
|
+
|
348
|
+
auto lastArgObj = lastArg.asObject(rt);
|
349
|
+
|
350
|
+
if (!lastArgObj.hasProperty(rt, helpers::UNI_PRESSABLE_ID.c_str())) {
|
351
|
+
return std::nullopt;
|
352
|
+
}
|
353
|
+
|
354
|
+
return lastArgObj.getProperty(rt, helpers::UNI_PRESSABLE_ID.c_str()).asString(rt).utf8(rt);
|
355
|
+
}
|
356
|
+
|
336
357
|
// function replaces original user dynamic function with additional logic to memoize arguments
|
337
358
|
jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unistyle::Shared unistyle) {
|
338
359
|
auto unistylesRuntime = this->_unistylesRuntime;
|
@@ -371,13 +392,13 @@ jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unist
|
|
371
392
|
// update shadow leaf updates to indicate newest changes
|
372
393
|
auto& registry = core::UnistylesRegistry::get();
|
373
394
|
|
374
|
-
registry.shadowLeafUpdateFromUnistyle(rt, unistyle);
|
395
|
+
registry.shadowLeafUpdateFromUnistyle(rt, unistyle, getUniquePressableIdFromArguments(rt, args, count));
|
375
396
|
|
376
397
|
return style;
|
377
398
|
});
|
378
399
|
}
|
379
400
|
|
380
|
-
// function
|
401
|
+
// function converts babel generated dependencies to C++ dependencies
|
381
402
|
std::vector<UnistyleDependency> parser::Parser::parseDependencies(jsi::Runtime &rt, jsi::Object&& dependencies) {
|
382
403
|
helpers::assertThat(rt, dependencies.isArray(rt), "Unistyles: Babel transform is invalid - unexpected type for dependencies.");
|
383
404
|
|
@@ -640,7 +661,7 @@ jsi::Object parser::Parser::parseCompoundVariants(jsi::Runtime& rt, Unistyle::Sh
|
|
640
661
|
return parsedCompoundVariants;
|
641
662
|
}
|
642
663
|
|
643
|
-
// check every condition in compound variants,
|
664
|
+
// check every condition in compound variants, supports boolean variants
|
644
665
|
bool parser::Parser::shouldApplyCompoundVariants(jsi::Runtime& rt, const Variants& variants, jsi::Object& compoundVariant) {
|
645
666
|
if (variants.empty()) {
|
646
667
|
return false;
|
package/cxx/parser/Parser.h
CHANGED
@@ -43,6 +43,7 @@ private:
|
|
43
43
|
jsi::Value getStylesForVariant(jsi::Runtime& rt, const std::string groupName, jsi::Object&& groupValue, std::optional<std::string> selectedVariant, Variants& variants);
|
44
44
|
jsi::Object parseCompoundVariants(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj, Variants& variants);
|
45
45
|
bool shouldApplyCompoundVariants(jsi::Runtime& rt, const Variants& variants, jsi::Object& compoundVariant);
|
46
|
+
std::optional<std::string> getUniquePressableIdFromArguments(jsi::Runtime& rt, const jsi::Value* args, size_t count);
|
46
47
|
bool isColor(const std::string& propertyName);
|
47
48
|
|
48
49
|
std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
|
@@ -9,6 +9,7 @@ namespace margelo::nitro::unistyles::shadow {
|
|
9
9
|
using namespace facebook;
|
10
10
|
using namespace facebook::react;
|
11
11
|
|
12
|
+
// translates Unistyles changes to unified shadow tree changes
|
12
13
|
using ShadowLeafUpdates = std::unordered_map<const ShadowNodeFamily*, folly::dynamic>;
|
13
14
|
|
14
15
|
}
|
@@ -109,6 +109,10 @@ ShadowNode::Unshared shadow::ShadowTreeManager::cloneShadowTree(const ShadowNode
|
|
109
109
|
*shadowNode.getContextContainer()
|
110
110
|
};
|
111
111
|
|
112
|
+
// this is important and critical
|
113
|
+
// first of all Android doesn't like nullish props (they work perfectly fine on iOS)
|
114
|
+
// second of all Android props MUST be constructed from previous props, otherwise RawProps::~RawProps error occurs
|
115
|
+
// Meta wants to remove shadowNode.getProps()->rawProps, but for now it's the only viable solution
|
112
116
|
#ifdef ANDROID
|
113
117
|
auto safeProps = rawPropsIt->second == nullptr ? folly::dynamic::object() : rawPropsIt->second;
|
114
118
|
auto newProps = folly::dynamic::merge(shadowNode.getProps()->rawProps, safeProps);
|
package/ios/Extensions.swift
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
import Foundation
|
2
2
|
|
3
3
|
extension UIColor {
|
4
|
+
// int is universal way of color representation
|
5
|
+
// iOS API expects UIColor, so we need to translate it
|
4
6
|
public static func fromInt(_ color: Int) -> UIColor {
|
5
7
|
let red = CGFloat((color >> 16) & 0xFF) / 255.0
|
6
8
|
let green = CGFloat((color >> 8) & 0xFF) / 255.0
|
7
9
|
let blue = CGFloat(color & 0xFF) / 255.0
|
8
|
-
|
10
|
+
|
9
11
|
return UIColor(red: red, green: green, blue: blue, alpha: 1.0)
|
10
12
|
}
|
11
13
|
}
|
@@ -187,11 +187,22 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
|
|
187
187
|
return getContentSizeCategoryFn()
|
188
188
|
}
|
189
189
|
}
|
190
|
+
|
191
|
+
func getMainWindow() -> UIWindow? {
|
192
|
+
guard let mainWindow = UIApplication.shared.connectedScenes
|
193
|
+
.compactMap({ $0 as? UIWindowScene })
|
194
|
+
.flatMap({ $0.windows })
|
195
|
+
.first(where: { $0.isKeyWindow }) else {
|
196
|
+
return nil
|
197
|
+
}
|
198
|
+
|
199
|
+
return mainWindow
|
200
|
+
}
|
190
201
|
|
191
202
|
// todo handle IME animation
|
192
203
|
func getInsets() -> Insets {
|
193
204
|
func getInsetsFn() -> Insets {
|
194
|
-
guard let window =
|
205
|
+
guard let window = getMainWindow() else {
|
195
206
|
// this should never happen, but it's better to return zeros
|
196
207
|
return Insets(top: 0, bottom: 0, left: 0, right: 0, ime: 0)
|
197
208
|
}
|
@@ -235,7 +246,7 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
|
|
235
246
|
|
236
247
|
func getStatusBarDimensions() -> Dimensions {
|
237
248
|
func getStatusBarDimensionsFn() -> Dimensions {
|
238
|
-
guard let window =
|
249
|
+
guard let window = getMainWindow(),
|
239
250
|
let statusBarManager = window.windowScene?.statusBarManager else {
|
240
251
|
// this should never happen, but it's better to return defaults
|
241
252
|
return Dimensions(width: 0, height: 0)
|
@@ -4,7 +4,6 @@ extension NativeIOSPlatform {
|
|
4
4
|
func setupPlatformListeners() {
|
5
5
|
NotificationCenter.default.publisher(for: NSNotification.Name("RCTWindowFrameDidChangeNotification"))
|
6
6
|
// add small delay (10ms) to make sure all values are up ot date
|
7
|
-
// we MUST call it on current thread, otherwise random crashes occurs
|
8
7
|
.delay(for: .milliseconds(10), scheduler: RunLoop.current)
|
9
8
|
.sink { [weak self] notification in
|
10
9
|
self?.onWindowChange(notification)
|
@@ -14,7 +14,7 @@ const findShadowNodeForHandle = handle => {
|
|
14
14
|
}
|
15
15
|
return node;
|
16
16
|
};
|
17
|
-
HybridShadowRegistry.add = (handle, styles, variants, args) => {
|
17
|
+
HybridShadowRegistry.add = (handle, styles, variants, args, uniquePressableId) => {
|
18
18
|
// virtualized nodes can be null
|
19
19
|
if (!handle || !styles || !Array.isArray(styles)) {
|
20
20
|
return;
|
@@ -22,7 +22,7 @@ HybridShadowRegistry.add = (handle, styles, variants, args) => {
|
|
22
22
|
|
23
23
|
// filter Reanimated styles and styles that are undefined
|
24
24
|
const filteredStyles = styles.filter(style => !style?.initial?.updater).filter(Boolean);
|
25
|
-
HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles, variants ?? {}, args ?? []);
|
25
|
+
HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles, variants ?? {}, args ?? [], uniquePressableId);
|
26
26
|
};
|
27
27
|
HybridShadowRegistry.remove = handle => {
|
28
28
|
if (!handle) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_reactNativeNitroModules","require","HybridShadowRegistry","NitroModules","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","styles","variants","args","Array","isArray","filteredStyles","filter","style","initial","updater","Boolean","link","remove","unlink","UnistylesShadowRegistry","exports"],"sourceRoot":"../../../../src","sources":["specs/ShadowRegistry/index.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAaA,MAAMC,oBAAoB,GAAGC,qCAAY,CAACC,kBAAkB,CAAiB,yBAAyB,CAAC;AAEvG,MAAMC,uBAAuB,GAAIC,MAAkB,IAAK;EACpD,MAAMC,IAAI,GAAGD,MAAM,EAAEE,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACvDD,MAAM,EAAEI,kBAAkB,GAAG,CAAC,EAAEC,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACjGD,MAAM,EAAEK,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI;EAEhF,IAAI,CAACA,IAAI,EAAE;IACP;IACA,MAAM,IAAIK,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EAEA,OAAOL,IAAI;AACf,CAAC;AAEDL,oBAAoB,CAACW,GAAG,GAAG,CAACP,MAAM,EAAEQ,MAAM,EAAEC,QAAQ,EAAEC,IAAI,KAAK;
|
1
|
+
{"version":3,"names":["_reactNativeNitroModules","require","HybridShadowRegistry","NitroModules","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","styles","variants","args","uniquePressableId","Array","isArray","filteredStyles","filter","style","initial","updater","Boolean","link","remove","unlink","UnistylesShadowRegistry","exports"],"sourceRoot":"../../../../src","sources":["specs/ShadowRegistry/index.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAaA,MAAMC,oBAAoB,GAAGC,qCAAY,CAACC,kBAAkB,CAAiB,yBAAyB,CAAC;AAEvG,MAAMC,uBAAuB,GAAIC,MAAkB,IAAK;EACpD,MAAMC,IAAI,GAAGD,MAAM,EAAEE,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACvDD,MAAM,EAAEI,kBAAkB,GAAG,CAAC,EAAEC,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACjGD,MAAM,EAAEK,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI;EAEhF,IAAI,CAACA,IAAI,EAAE;IACP;IACA,MAAM,IAAIK,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EAEA,OAAOL,IAAI;AACf,CAAC;AAEDL,oBAAoB,CAACW,GAAG,GAAG,CAACP,MAAM,EAAEQ,MAAM,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,iBAAiB,KAAK;EAC9E;EACA,IAAI,CAACX,MAAM,IAAI,CAACQ,MAAM,IAAI,CAACI,KAAK,CAACC,OAAO,CAACL,MAAM,CAAC,EAAE;IAC9C;EACJ;;EAEA;EACA,MAAMM,cAAc,GAAGN,MAAM,CACxBO,MAAM,CAACC,KAAK,IAAI,CAACA,KAAK,EAAEC,OAAO,EAAEC,OAAO,CAAC,CACzCH,MAAM,CAACI,OAAO,CAAC;EAEpBvB,oBAAoB,CAACwB,IAAI,CAACrB,uBAAuB,CAACC,MAAM,CAAC,EAAEc,cAAc,EAAEL,QAAQ,IAAI,CAAC,CAAC,EAAEC,IAAI,IAAI,EAAE,EAAEC,iBAAiB,CAAC;AAC7H,CAAC;AAEDf,oBAAoB,CAACyB,MAAM,GAAGrB,MAAM,IAAI;EACpC,IAAI,CAACA,MAAM,EAAE;IACT;EACJ;EAEAJ,oBAAoB,CAAC0B,MAAM,CAACvB,uBAAuB,CAACC,MAAM,CAAC,CAAC;AAChE,CAAC;AAQM,MAAMuB,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAG3B,oBAA4D","ignoreList":[]}
|
@@ -10,7 +10,7 @@ const findShadowNodeForHandle = handle => {
|
|
10
10
|
}
|
11
11
|
return node;
|
12
12
|
};
|
13
|
-
HybridShadowRegistry.add = (handle, styles, variants, args) => {
|
13
|
+
HybridShadowRegistry.add = (handle, styles, variants, args, uniquePressableId) => {
|
14
14
|
// virtualized nodes can be null
|
15
15
|
if (!handle || !styles || !Array.isArray(styles)) {
|
16
16
|
return;
|
@@ -18,7 +18,7 @@ HybridShadowRegistry.add = (handle, styles, variants, args) => {
|
|
18
18
|
|
19
19
|
// filter Reanimated styles and styles that are undefined
|
20
20
|
const filteredStyles = styles.filter(style => !style?.initial?.updater).filter(Boolean);
|
21
|
-
HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles, variants ?? {}, args ?? []);
|
21
|
+
HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles, variants ?? {}, args ?? [], uniquePressableId);
|
22
22
|
};
|
23
23
|
HybridShadowRegistry.remove = handle => {
|
24
24
|
if (!handle) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["NitroModules","HybridShadowRegistry","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","styles","variants","args","Array","isArray","filteredStyles","filter","style","initial","updater","Boolean","link","remove","unlink","UnistylesShadowRegistry"],"sourceRoot":"../../../../src","sources":["specs/ShadowRegistry/index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAazD,MAAMC,oBAAoB,GAAGD,YAAY,CAACE,kBAAkB,CAAiB,yBAAyB,CAAC;AAEvG,MAAMC,uBAAuB,GAAIC,MAAkB,IAAK;EACpD,MAAMC,IAAI,GAAGD,MAAM,EAAEE,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACvDD,MAAM,EAAEI,kBAAkB,GAAG,CAAC,EAAEC,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACjGD,MAAM,EAAEK,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI;EAEhF,IAAI,CAACA,IAAI,EAAE;IACP;IACA,MAAM,IAAIK,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EAEA,OAAOL,IAAI;AACf,CAAC;AAEDJ,oBAAoB,CAACU,GAAG,GAAG,CAACP,MAAM,EAAEQ,MAAM,EAAEC,QAAQ,EAAEC,IAAI,KAAK;
|
1
|
+
{"version":3,"names":["NitroModules","HybridShadowRegistry","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","styles","variants","args","uniquePressableId","Array","isArray","filteredStyles","filter","style","initial","updater","Boolean","link","remove","unlink","UnistylesShadowRegistry"],"sourceRoot":"../../../../src","sources":["specs/ShadowRegistry/index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAazD,MAAMC,oBAAoB,GAAGD,YAAY,CAACE,kBAAkB,CAAiB,yBAAyB,CAAC;AAEvG,MAAMC,uBAAuB,GAAIC,MAAkB,IAAK;EACpD,MAAMC,IAAI,GAAGD,MAAM,EAAEE,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACvDD,MAAM,EAAEI,kBAAkB,GAAG,CAAC,EAAEC,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACjGD,MAAM,EAAEK,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI;EAEhF,IAAI,CAACA,IAAI,EAAE;IACP;IACA,MAAM,IAAIK,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EAEA,OAAOL,IAAI;AACf,CAAC;AAEDJ,oBAAoB,CAACU,GAAG,GAAG,CAACP,MAAM,EAAEQ,MAAM,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,iBAAiB,KAAK;EAC9E;EACA,IAAI,CAACX,MAAM,IAAI,CAACQ,MAAM,IAAI,CAACI,KAAK,CAACC,OAAO,CAACL,MAAM,CAAC,EAAE;IAC9C;EACJ;;EAEA;EACA,MAAMM,cAAc,GAAGN,MAAM,CACxBO,MAAM,CAACC,KAAK,IAAI,CAACA,KAAK,EAAEC,OAAO,EAAEC,OAAO,CAAC,CACzCH,MAAM,CAACI,OAAO,CAAC;EAEpBtB,oBAAoB,CAACuB,IAAI,CAACrB,uBAAuB,CAACC,MAAM,CAAC,EAAEc,cAAc,EAAEL,QAAQ,IAAI,CAAC,CAAC,EAAEC,IAAI,IAAI,EAAE,EAAEC,iBAAiB,CAAC;AAC7H,CAAC;AAEDd,oBAAoB,CAACwB,MAAM,GAAGrB,MAAM,IAAI;EACpC,IAAI,CAACA,MAAM,EAAE;IACT;EACJ;EAEAH,oBAAoB,CAACyB,MAAM,CAACvB,uBAAuB,CAACC,MAAM,CAAC,CAAC;AAChE,CAAC;AAQD,OAAO,MAAMuB,uBAAuB,GAAG1B,oBAA4D","ignoreList":[]}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import type { UnistylesShadowRegistry as UnistylesShadowRegistrySpec } from './ShadowRegistry.nitro';
|
2
2
|
import type { ShadowNode, Unistyle, ViewHandle } from './types';
|
3
3
|
interface ShadowRegistry extends UnistylesShadowRegistrySpec {
|
4
|
-
add(handle?: ViewHandle, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any
|
4
|
+
add(handle?: ViewHandle, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>, uniquePressableId?: string): void;
|
5
5
|
remove(handle?: ViewHandle): void;
|
6
|
-
link(node: ShadowNode, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any
|
6
|
+
link(node: ShadowNode, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>, uniquePressableId?: string): void;
|
7
7
|
unlink(node: ShadowNode): void;
|
8
8
|
}
|
9
9
|
type PrivateMethods = 'add' | 'remove' | 'link' | 'unlink';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/specs/ShadowRegistry/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,IAAI,2BAA2B,EAAE,MAAM,wBAAwB,CAAA;AACpG,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE/D,UAAU,cAAe,SAAQ,2BAA2B;IAExD,GAAG,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/specs/ShadowRegistry/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,IAAI,2BAA2B,EAAE,MAAM,wBAAwB,CAAA;AACpG,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE/D,UAAU,cAAe,SAAQ,2BAA2B;IAExD,GAAG,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5J,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAElC,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1J,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAA;CACjC;AAuCD,KAAK,cAAc,GACb,KAAK,GACL,QAAQ,GACR,MAAM,GACN,QAAQ,CAAA;AAEd,eAAO,MAAM,uBAAuB,EAA2B,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,CAAA"}
|
@@ -43,7 +43,7 @@ namespace margelo::nitro::unistyles { struct UnistylesNativeMiniRuntime; }
|
|
43
43
|
#include <NitroModules/ArrayBufferHolder.hpp>
|
44
44
|
#include <NitroModules/AnyMapHolder.hpp>
|
45
45
|
#include <NitroModules/HybridContext.hpp>
|
46
|
-
#include <NitroModules/
|
46
|
+
#include <NitroModules/RuntimeError.hpp>
|
47
47
|
|
48
48
|
// Forward declarations of Swift defined types
|
49
49
|
// Forward declaration of `HybridNativePlatformSpecCxx` to properly resolve imports.
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-native-unistyles",
|
3
|
-
"version": "3.0.0-alpha.
|
3
|
+
"version": "3.0.0-alpha.41",
|
4
4
|
"description": "Level up your React Native StyleSheet",
|
5
5
|
"scripts": {
|
6
6
|
"test": "jest",
|
@@ -74,11 +74,11 @@
|
|
74
74
|
"husky": "9.1.6",
|
75
75
|
"jest": "29.7.0",
|
76
76
|
"metro-react-native-babel-preset": "0.77.0",
|
77
|
-
"nitro-codegen": "0.
|
77
|
+
"nitro-codegen": "0.17.0",
|
78
78
|
"react": "18.3.1",
|
79
79
|
"react-native": "0.76.0",
|
80
80
|
"react-native-builder-bob": "0.30.2",
|
81
|
-
"react-native-nitro-modules": "0.
|
81
|
+
"react-native-nitro-modules": "0.17.0",
|
82
82
|
"react-test-renderer": "18.3.1",
|
83
83
|
"release-it": "17.10.0",
|
84
84
|
"typescript": "5.6.3"
|
package/plugin/index.js
CHANGED
@@ -128,9 +128,9 @@ module.exports = function ({ types: t }) {
|
|
128
128
|
return
|
129
129
|
}
|
130
130
|
|
131
|
-
|
132
|
-
handlePressable(t, path, styleAttr, metadata)
|
133
|
-
|
131
|
+
const uniquePressableId = openingElementName === 'Pressable'
|
132
|
+
? handlePressable(t, path, styleAttr, metadata)
|
133
|
+
: undefined
|
134
134
|
|
135
135
|
styleAttributeToArray(t, path)
|
136
136
|
|
@@ -144,8 +144,8 @@ module.exports = function ({ types: t }) {
|
|
144
144
|
}
|
145
145
|
|
146
146
|
refProp
|
147
|
-
? overrideRef(t, path, refProp, metadata, state)
|
148
|
-
: addRef(t, path, metadata, state)
|
147
|
+
? overrideRef(t, path, refProp, metadata, state, uniquePressableId)
|
148
|
+
: addRef(t, path, metadata, state, uniquePressableId)
|
149
149
|
},
|
150
150
|
CallExpression(path, state) {
|
151
151
|
if (isUsingVariants(t, path)) {
|
package/plugin/ref.js
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
const { PRESSABLE_STATE_NAME } = require('./common')
|
2
2
|
|
3
|
+
function generateUniqueId() {
|
4
|
+
return `${Math.random().toString(36).substring(2, 9)}`
|
5
|
+
}
|
6
|
+
|
3
7
|
function getRefProp(t, path) {
|
4
8
|
return path.node.openingElement.attributes.find(attr =>
|
5
9
|
t.isJSXAttribute(attr) &&
|
@@ -90,7 +94,8 @@ function arrayFromDynamicFunctionArgs(t, metadata, path) {
|
|
90
94
|
|
91
95
|
return t.arrayExpression(memberExpressions)
|
92
96
|
}
|
93
|
-
|
97
|
+
|
98
|
+
function addRef(t, path, metadata, state, uniquePressableId) {
|
94
99
|
const hasVariants = state.file.hasVariants
|
95
100
|
|
96
101
|
const newRefFunction = t.arrowFunctionExpression(
|
@@ -103,8 +108,9 @@ function addRef(t, path, metadata, state) {
|
|
103
108
|
t.identifier('ref'),
|
104
109
|
arrayExpressionFromMetadata(t, metadata),
|
105
110
|
t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
|
106
|
-
arrayFromDynamicFunctionArgs(t, metadata, path)
|
107
|
-
|
111
|
+
arrayFromDynamicFunctionArgs(t, metadata, path),
|
112
|
+
uniquePressableId ? t.stringLiteral(uniquePressableId) : undefined
|
113
|
+
].filter(Boolean)
|
108
114
|
)
|
109
115
|
),
|
110
116
|
t.returnStatement(
|
@@ -126,7 +132,7 @@ function addRef(t, path, metadata, state) {
|
|
126
132
|
path.node.openingElement.attributes.push(newRefProp)
|
127
133
|
}
|
128
134
|
|
129
|
-
function overrideRef(t, path, refProp, metadata, state) {
|
135
|
+
function overrideRef(t, path, refProp, metadata, state, uniquePressableId) {
|
130
136
|
const hasVariants = state.file.hasVariants
|
131
137
|
const uniqueRefName = path.scope.generateUidIdentifier('ref').name
|
132
138
|
const isIdentifier = t.isIdentifier(refProp.value.expression)
|
@@ -152,8 +158,9 @@ function overrideRef(t, path, refProp, metadata, state) {
|
|
152
158
|
t.identifier(uniqueRefName),
|
153
159
|
arrayExpressionFromMetadata(t, metadata),
|
154
160
|
t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
|
155
|
-
arrayFromDynamicFunctionArgs(t, metadata, path)
|
156
|
-
|
161
|
+
arrayFromDynamicFunctionArgs(t, metadata, path),
|
162
|
+
uniquePressableId ? t.stringLiteral(uniquePressableId) : undefined
|
163
|
+
].filter(Boolean)
|
157
164
|
)
|
158
165
|
),
|
159
166
|
t.returnStatement(
|
@@ -197,8 +204,9 @@ function overrideRef(t, path, refProp, metadata, state) {
|
|
197
204
|
t.identifier(userRefName),
|
198
205
|
arrayExpressionFromMetadata(t, metadata),
|
199
206
|
t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
|
200
|
-
arrayFromDynamicFunctionArgs(t, metadata, path)
|
201
|
-
|
207
|
+
arrayFromDynamicFunctionArgs(t, metadata, path),
|
208
|
+
uniquePressableId ? t.stringLiteral(uniquePressableId) : undefined
|
209
|
+
].filter(Boolean)
|
202
210
|
)
|
203
211
|
),
|
204
212
|
// Merged cleanup function
|
@@ -259,8 +267,9 @@ function overrideRef(t, path, refProp, metadata, state) {
|
|
259
267
|
t.identifier(uniqueRefName),
|
260
268
|
arrayExpressionFromMetadata(t, metadata),
|
261
269
|
t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
|
262
|
-
arrayFromDynamicFunctionArgs(t, metadata, path)
|
263
|
-
|
270
|
+
arrayFromDynamicFunctionArgs(t, metadata, path),
|
271
|
+
uniquePressableId ? t.stringLiteral(uniquePressableId) : undefined
|
272
|
+
].filter(Boolean)
|
264
273
|
)
|
265
274
|
),
|
266
275
|
t.returnStatement(
|
@@ -291,5 +300,6 @@ module.exports = {
|
|
291
300
|
getRefProp,
|
292
301
|
addRef,
|
293
302
|
overrideRef,
|
294
|
-
hasStringRef
|
303
|
+
hasStringRef,
|
304
|
+
generateUniqueId
|
295
305
|
}
|
package/plugin/style.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
const { PRESSABLE_STATE_NAME } = require('./common')
|
2
|
+
const { generateUniqueId } = require('./ref')
|
2
3
|
|
3
4
|
function getStyleMetadata(t, node, dynamicFunction = null) {
|
4
5
|
// {styles.container}
|
@@ -143,6 +144,8 @@ function handlePressable(t, path, styleAttr, metadata) {
|
|
143
144
|
t.identifier(members[0])
|
144
145
|
)
|
145
146
|
|
147
|
+
const uniquePressableId = generateUniqueId()
|
148
|
+
|
146
149
|
// state => typeof style.pressable === 'function' ? style.pressable(state) : style.pressable
|
147
150
|
styleAttr.value.expression = t.arrowFunctionExpression(
|
148
151
|
[t.identifier("state")],
|
@@ -157,13 +160,18 @@ function handlePressable(t, path, styleAttr, metadata) {
|
|
157
160
|
),
|
158
161
|
t.callExpression(
|
159
162
|
stylePath,
|
160
|
-
[t.identifier("state")
|
163
|
+
[t.identifier("state"), t.objectExpression([
|
164
|
+
t.objectProperty(
|
165
|
+
t.identifier("__uni_pressable_id"),
|
166
|
+
t.stringLiteral(uniquePressableId)
|
167
|
+
)
|
168
|
+
])]
|
161
169
|
),
|
162
170
|
stylePath
|
163
171
|
)
|
164
172
|
)
|
165
173
|
|
166
|
-
return
|
174
|
+
return uniquePressableId
|
167
175
|
}
|
168
176
|
|
169
177
|
// {style.pressable(1, 2)}
|
@@ -212,8 +220,19 @@ function handlePressable(t, path, styleAttr, metadata) {
|
|
212
220
|
return arg
|
213
221
|
})
|
214
222
|
|
223
|
+
const uniquePressableId = generateUniqueId()
|
224
|
+
|
225
|
+
args.arguments.push(t.objectExpression([
|
226
|
+
t.objectProperty(
|
227
|
+
t.identifier("__uni_pressable_id"),
|
228
|
+
t.stringLiteral(uniquePressableId)
|
229
|
+
)
|
230
|
+
]))
|
231
|
+
|
215
232
|
// update arrow function arg name
|
216
233
|
styleExpression.params[0].name = PRESSABLE_STATE_NAME
|
234
|
+
|
235
|
+
return uniquePressableId
|
217
236
|
}
|
218
237
|
}
|
219
238
|
|
@@ -4,10 +4,10 @@ import type { ShadowNode, Unistyle, ViewHandle } from './types'
|
|
4
4
|
|
5
5
|
interface ShadowRegistry extends UnistylesShadowRegistrySpec {
|
6
6
|
// Babel API
|
7
|
-
add(handle?: ViewHandle, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any
|
7
|
+
add(handle?: ViewHandle, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>, uniquePressableId?: string): void,
|
8
8
|
remove(handle?: ViewHandle): void,
|
9
9
|
// JSI
|
10
|
-
link(node: ShadowNode, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any
|
10
|
+
link(node: ShadowNode, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>, uniquePressableId?: string): void,
|
11
11
|
unlink(node: ShadowNode): void
|
12
12
|
}
|
13
13
|
|
@@ -26,7 +26,7 @@ const findShadowNodeForHandle = (handle: ViewHandle) => {
|
|
26
26
|
return node
|
27
27
|
}
|
28
28
|
|
29
|
-
HybridShadowRegistry.add = (handle, styles, variants, args) => {
|
29
|
+
HybridShadowRegistry.add = (handle, styles, variants, args, uniquePressableId) => {
|
30
30
|
// virtualized nodes can be null
|
31
31
|
if (!handle || !styles || !Array.isArray(styles)) {
|
32
32
|
return
|
@@ -37,7 +37,7 @@ HybridShadowRegistry.add = (handle, styles, variants, args) => {
|
|
37
37
|
.filter(style => !style?.initial?.updater)
|
38
38
|
.filter(Boolean)
|
39
39
|
|
40
|
-
HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles, variants ?? {}, args ?? [])
|
40
|
+
HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles, variants ?? {}, args ?? [], uniquePressableId)
|
41
41
|
}
|
42
42
|
|
43
43
|
HybridShadowRegistry.remove = handle => {
|