react-native-unistyles 3.0.0-alpha.40 → 3.0.0-alpha.42
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +7 -1
- 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/core/UnistyleData.h +3 -2
- package/cxx/core/UnistylesRegistry.cpp +15 -5
- package/cxx/core/UnistylesRegistry.h +2 -2
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +5 -2
- package/cxx/parser/Parser.cpp +10 -4
- 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/components/Display.js +2 -2
- package/lib/commonjs/components/Display.js.map +1 -1
- package/lib/commonjs/components/Hide.js +2 -2
- package/lib/commonjs/components/Hide.js.map +1 -1
- package/lib/commonjs/components/Pressable.js +64 -0
- package/lib/commonjs/components/Pressable.js.map +1 -0
- package/lib/commonjs/components/Pressable.web.js +97 -0
- package/lib/commonjs/components/Pressable.web.js.map +1 -0
- package/lib/commonjs/components/index.js +7 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/core/getBoundArgs.js +18 -0
- package/lib/commonjs/core/getBoundArgs.js.map +1 -0
- package/lib/commonjs/core/getId.js +9 -0
- package/lib/commonjs/core/getId.js.map +1 -0
- package/lib/commonjs/core/index.js +14 -0
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/hooks/index.js +13 -0
- package/lib/commonjs/hooks/index.js.map +1 -0
- package/lib/commonjs/hooks/useMedia.js.map +1 -0
- package/lib/commonjs/hooks/useMedia.web.js.map +1 -0
- package/lib/commonjs/index.js +8 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mq.js +6 -6
- package/lib/commonjs/mq.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +3 -4
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js +1 -2
- package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js.map +1 -1
- package/lib/commonjs/specs/index.web.js +0 -7
- package/lib/commonjs/specs/index.web.js.map +1 -1
- package/lib/commonjs/utils.js +1 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/convert/types.js.map +1 -1
- package/lib/commonjs/web/convert/utils.js +1 -1
- package/lib/commonjs/web/convert/utils.js.map +1 -1
- package/lib/commonjs/web/create.js +4 -1
- package/lib/commonjs/web/create.js.map +1 -1
- package/lib/commonjs/web/index.js +7 -5
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/commonjs/web/listener.js.map +1 -1
- package/lib/commonjs/web/runtime.js +7 -7
- package/lib/commonjs/web/runtime.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/state.js +23 -16
- package/lib/commonjs/web/state.js.map +1 -1
- package/lib/commonjs/web/utils/common.js +3 -3
- package/lib/commonjs/web/utils/common.js.map +1 -1
- package/lib/commonjs/web/utils/unistyle.js +2 -4
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/commonjs/web/variants/getVariants.js +1 -1
- package/lib/commonjs/web/variants/getVariants.js.map +1 -1
- package/lib/commonjs/web/variants/useVariants.js +1 -1
- package/lib/module/components/Display.js +1 -1
- package/lib/module/components/Display.js.map +1 -1
- package/lib/module/components/Hide.js +1 -1
- package/lib/module/components/Hide.js.map +1 -1
- package/lib/module/components/Pressable.js +58 -0
- package/lib/module/components/Pressable.js.map +1 -0
- package/lib/module/components/Pressable.web.js +91 -0
- package/lib/module/components/Pressable.web.js.map +1 -0
- package/lib/module/components/index.js +1 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/core/getBoundArgs.js +13 -0
- package/lib/module/core/getBoundArgs.js.map +1 -0
- package/lib/module/core/getId.js +4 -0
- package/lib/module/core/getId.js.map +1 -0
- package/lib/module/core/index.js +2 -0
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/hooks/index.js +4 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/useMedia.js.map +1 -0
- package/lib/module/hooks/useMedia.web.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/mq.js +6 -6
- package/lib/module/mq.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +3 -4
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/specs/TurboUnistyles/NativeTurboUnistyles.js +1 -2
- package/lib/module/specs/TurboUnistyles/NativeTurboUnistyles.js.map +1 -1
- package/lib/module/specs/index.web.js +0 -1
- package/lib/module/specs/index.web.js.map +1 -1
- package/lib/module/utils.js +1 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/convert/types.js.map +1 -1
- package/lib/module/web/convert/utils.js +1 -1
- package/lib/module/web/convert/utils.js.map +1 -1
- package/lib/module/web/create.js +5 -2
- package/lib/module/web/create.js.map +1 -1
- package/lib/module/web/index.js +7 -3
- package/lib/module/web/index.js.map +1 -1
- package/lib/module/web/listener.js.map +1 -1
- package/lib/module/web/runtime.js +8 -8
- package/lib/module/web/runtime.js.map +1 -1
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/module/web/state.js +24 -17
- package/lib/module/web/state.js.map +1 -1
- package/lib/module/web/utils/common.js +1 -1
- package/lib/module/web/utils/common.js.map +1 -1
- package/lib/module/web/utils/unistyle.js +1 -2
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/module/web/variants/getVariants.js +1 -1
- package/lib/module/web/variants/getVariants.js.map +1 -1
- package/lib/module/web/variants/useVariants.js +1 -1
- package/lib/typescript/src/components/Pressable.d.ts +7 -0
- package/lib/typescript/src/components/Pressable.d.ts.map +1 -0
- package/lib/typescript/src/components/Pressable.web.d.ts +13 -0
- package/lib/typescript/src/components/Pressable.web.d.ts.map +1 -0
- package/lib/typescript/src/components/index.d.ts +1 -0
- package/lib/typescript/src/components/index.d.ts.map +1 -1
- package/lib/typescript/src/core/getBoundArgs.d.ts +2 -0
- package/lib/typescript/src/core/getBoundArgs.d.ts.map +1 -0
- package/lib/typescript/src/core/getId.d.ts +2 -0
- package/lib/typescript/src/core/getId.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +2 -0
- package/lib/typescript/src/core/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/index.d.ts +2 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useMedia.web.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +1 -1
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.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/lib/typescript/src/specs/ShadowRegistry/types.d.ts +1 -0
- package/lib/typescript/src/specs/ShadowRegistry/types.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts +1 -1
- package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts +3 -2
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.web.d.ts +0 -2
- package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
- package/lib/typescript/src/types/common.d.ts +1 -0
- package/lib/typescript/src/types/common.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +1 -1
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/types.d.ts +1 -1
- package/lib/typescript/src/web/convert/types.d.ts.map +1 -1
- package/lib/typescript/src/web/create.d.ts +1 -1
- package/lib/typescript/src/web/create.d.ts.map +1 -1
- package/lib/typescript/src/web/index.d.ts +8 -2
- package/lib/typescript/src/web/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener.d.ts.map +1 -1
- package/lib/typescript/src/web/runtime.d.ts.map +1 -1
- package/lib/typescript/src/web/state.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/common.d.ts +1 -1
- package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts +0 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +1 -1
- package/package.json +14 -18
- package/plugin/common.js +1 -4
- package/plugin/import.js +29 -3
- package/plugin/index.js +16 -6
- package/plugin/ref.js +4 -54
- package/plugin/style.js +116 -43
- package/src/components/Display.tsx +1 -1
- package/src/components/Hide.tsx +1 -1
- package/src/components/Pressable.tsx +72 -0
- package/src/components/Pressable.web.tsx +103 -0
- package/src/components/index.ts +1 -0
- package/src/core/getBoundArgs.ts +15 -0
- package/src/core/getId.ts +1 -0
- package/src/core/index.ts +2 -0
- package/src/hooks/index.ts +1 -0
- package/src/index.ts +1 -1
- package/src/mq.ts +6 -6
- package/src/specs/NativePlatform/NativePlatform.nitro.ts +1 -1
- package/src/specs/ShadowRegistry/index.ts +5 -6
- package/src/specs/ShadowRegistry/types.ts +2 -1
- package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.ts +1 -1
- package/src/specs/StyleSheet/index.ts +3 -2
- package/src/specs/TurboUnistyles/NativeTurboUnistyles.ts +1 -2
- package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +1 -1
- package/src/specs/UnistylesRuntime/index.ts +1 -1
- package/src/specs/index.web.ts +0 -4
- package/src/types/common.ts +1 -0
- package/src/types/index.ts +1 -1
- package/src/utils.ts +1 -1
- package/src/web/convert/types.ts +1 -1
- package/src/web/convert/utils.ts +2 -2
- package/src/web/create.ts +6 -2
- package/src/web/index.ts +7 -3
- package/src/web/listener.ts +2 -0
- package/src/web/registry.ts +1 -1
- package/src/web/runtime.ts +9 -9
- package/src/web/shadowRegistry.ts +2 -2
- package/src/web/state.ts +36 -17
- package/src/web/utils/common.ts +1 -1
- package/src/web/utils/unistyle.ts +3 -9
- package/src/web/variants/getVariants.ts +1 -1
- package/src/web/variants/useVariants.ts +1 -1
- package/lib/commonjs/components/useMedia.js.map +0 -1
- package/lib/commonjs/components/useMedia.web.js.map +0 -1
- package/lib/module/components/useMedia.js.map +0 -1
- package/lib/module/components/useMedia.web.js.map +0 -1
- package/lib/typescript/src/components/useMedia.d.ts.map +0 -1
- package/lib/typescript/src/components/useMedia.web.d.ts.map +0 -1
- /package/lib/commonjs/{components → hooks}/useMedia.js +0 -0
- /package/lib/commonjs/{components → hooks}/useMedia.web.js +0 -0
- /package/lib/module/{components → hooks}/useMedia.js +0 -0
- /package/lib/module/{components → hooks}/useMedia.web.js +0 -0
- /package/lib/typescript/src/{components → hooks}/useMedia.d.ts +0 -0
- /package/lib/typescript/src/{components → hooks}/useMedia.web.d.ts +0 -0
- /package/src/{components → hooks}/useMedia.ts +0 -0
- /package/src/{components → hooks}/useMedia.web.ts +0 -0
package/README.md
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
## Installation
|
23
23
|
|
24
24
|
```shell
|
25
|
-
|
25
|
+
yarn install react-native-unistyles
|
26
26
|
```
|
27
27
|
Install CocoaPods dependencies / generate native folders with Expo:
|
28
28
|
|
@@ -75,6 +75,12 @@ npx expo prebuild
|
|
75
75
|
<a href="https://github.com/happyfloat">
|
76
76
|
<img src="https://avatars.githubusercontent.com/u/186333704?s=200&v=4" height="70px" width="70px" alt="happyfloat" />
|
77
77
|
</a>
|
78
|
+
<a href="https://github.com">
|
79
|
+
<img src="https://avatars.githubusercontent.com/u/138339?v=4" height="70px" width="70px" alt="anonymous" />
|
80
|
+
</a>
|
81
|
+
<a href="https://github.com/hyoban">
|
82
|
+
<img src="https://avatars.githubusercontent.com/u/38493346?v=4" height="70px" width="70px" alt="hyoban" />
|
83
|
+
</a>
|
78
84
|
|
79
85
|
## Past sponsors
|
80
86
|
|
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/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,8 @@ 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]
|
85
|
+
this->_shadowRegistry[&rt][shadowNodeFamily]
|
86
|
+
.emplace_back(std::make_shared<UnistyleData>(unistyle, variants, arguments[index], uniquePressableId));
|
85
87
|
|
86
88
|
// add or update node for shadow leaf updates
|
87
89
|
// dynamic functions are parsed later
|
@@ -148,15 +150,23 @@ core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt
|
|
148
150
|
|
149
151
|
// called from proxied function only, we don't know host
|
150
152
|
// so we need to rebuild all instances as they may have different variants
|
151
|
-
void core::UnistylesRegistry::shadowLeafUpdateFromUnistyle(jsi::Runtime& rt, Unistyle::Shared unistyle) {
|
153
|
+
void core::UnistylesRegistry::shadowLeafUpdateFromUnistyle(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Value& maybePressableId) {
|
152
154
|
shadow::ShadowLeafUpdates updates;
|
153
155
|
auto parser = parser::Parser(nullptr);
|
156
|
+
std::optional<std::string> pressableId = maybePressableId.isString()
|
157
|
+
? std::make_optional(maybePressableId.asString(rt).utf8(rt))
|
158
|
+
: std::nullopt;
|
154
159
|
|
155
160
|
for (const auto& [family, unistyles] : this->_shadowRegistry[&rt]) {
|
156
161
|
for (const auto& unistyleData : unistyles) {
|
157
162
|
if (unistyleData->unistyle == unistyle) {
|
158
|
-
//
|
159
|
-
|
163
|
+
// special case for pressable
|
164
|
+
if (pressableId.has_value() && unistyleData->pressableId.has_value()) {
|
165
|
+
if (pressableId.value() == unistyleData->pressableId.value()) {
|
166
|
+
unistyleData->parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
160
170
|
updates[family] = parser.parseStylesToShadowTreeStyles(rt, { unistyleData });
|
161
171
|
}
|
162
172
|
}
|
@@ -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, jsi::Value& maybePressableId);
|
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));
|
@@ -342,7 +343,9 @@ jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unist
|
|
342
343
|
jsi::PropNameID::forUtf8(rt, unistyle->styleKey),
|
343
344
|
1,
|
344
345
|
[this, unistylesRuntime, unistyle](jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
|
345
|
-
auto thisObject = thisVal.
|
346
|
+
auto thisObject = thisVal.isObject()
|
347
|
+
? thisVal.asObject(rt)
|
348
|
+
: jsi::Object(rt);
|
346
349
|
auto parser = parser::Parser(unistylesRuntime);
|
347
350
|
|
348
351
|
// call user function
|
@@ -370,14 +373,17 @@ jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unist
|
|
370
373
|
|
371
374
|
// update shadow leaf updates to indicate newest changes
|
372
375
|
auto& registry = core::UnistylesRegistry::get();
|
376
|
+
auto lastArg = count == 0
|
377
|
+
? jsi::Value::undefined()
|
378
|
+
: jsi::Value(rt, args[count - 1]);
|
373
379
|
|
374
|
-
registry.shadowLeafUpdateFromUnistyle(rt, unistyle);
|
380
|
+
registry.shadowLeafUpdateFromUnistyle(rt, unistyle, lastArg);
|
375
381
|
|
376
382
|
return style;
|
377
383
|
});
|
378
384
|
}
|
379
385
|
|
380
|
-
// function
|
386
|
+
// function converts babel generated dependencies to C++ dependencies
|
381
387
|
std::vector<UnistyleDependency> parser::Parser::parseDependencies(jsi::Runtime &rt, jsi::Object&& dependencies) {
|
382
388
|
helpers::assertThat(rt, dependencies.isArray(rt), "Unistyles: Babel transform is invalid - unexpected type for dependencies.");
|
383
389
|
|
@@ -640,7 +646,7 @@ jsi::Object parser::Parser::parseCompoundVariants(jsi::Runtime& rt, Unistyle::Sh
|
|
640
646
|
return parsedCompoundVariants;
|
641
647
|
}
|
642
648
|
|
643
|
-
// check every condition in compound variants,
|
649
|
+
// check every condition in compound variants, supports boolean variants
|
644
650
|
bool parser::Parser::shouldApplyCompoundVariants(jsi::Runtime& rt, const Variants& variants, jsi::Object& compoundVariant) {
|
645
651
|
if (variants.empty()) {
|
646
652
|
return false;
|
@@ -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)
|
@@ -4,14 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.Display = void 0;
|
7
|
-
var
|
7
|
+
var _hooks = require("../hooks");
|
8
8
|
const Display = ({
|
9
9
|
children,
|
10
10
|
...props
|
11
11
|
}) => {
|
12
12
|
const {
|
13
13
|
isVisible
|
14
|
-
} = (0,
|
14
|
+
} = (0, _hooks.useMedia)(props);
|
15
15
|
return isVisible ? children : null;
|
16
16
|
};
|
17
17
|
exports.Display = Display;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["_hooks","require","Display","children","props","isVisible","useMedia","exports"],"sourceRoot":"../../../src","sources":["components/Display.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAIO,MAAMC,OAA8C,GAAGA,CAAC;EAAEC,QAAQ;EAAE,GAAGC;AAAM,CAAC,KAAK;EACtF,MAAM;IAAEC;EAAU,CAAC,GAAG,IAAAC,eAAQ,EAACF,KAAK,CAAC;EAErC,OAAOC,SAAS,GACVF,QAAQ,GACR,IAAI;AACd,CAAC;AAAAI,OAAA,CAAAL,OAAA,GAAAA,OAAA","ignoreList":[]}
|
@@ -4,14 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.Hide = void 0;
|
7
|
-
var
|
7
|
+
var _hooks = require("../hooks");
|
8
8
|
const Hide = ({
|
9
9
|
children,
|
10
10
|
...props
|
11
11
|
}) => {
|
12
12
|
const {
|
13
13
|
isVisible
|
14
|
-
} = (0,
|
14
|
+
} = (0, _hooks.useMedia)(props);
|
15
15
|
return !isVisible ? children : null;
|
16
16
|
};
|
17
17
|
exports.Hide = Hide;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["_hooks","require","Hide","children","props","isVisible","useMedia","exports"],"sourceRoot":"../../../src","sources":["components/Hide.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAIO,MAAMC,IAAwC,GAAGA,CAAC;EAAEC,QAAQ;EAAE,GAAGC;AAAM,CAAC,KAAK;EAChF,MAAM;IAAEC;EAAU,CAAC,GAAG,IAAAC,eAAQ,EAACF,KAAK,CAAC;EAErC,OAAO,CAACC,SAAS,GACXF,QAAQ,GACR,IAAI;AACd,CAAC;AAAAI,OAAA,CAAAL,IAAA,GAAAA,IAAA","ignoreList":[]}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Pressable = void 0;
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
8
|
+
var _reactNative = require("react-native");
|
9
|
+
var _specs = require("../specs");
|
10
|
+
var _core = require("../core");
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
12
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
13
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
14
|
+
const Pressable = exports.Pressable = /*#__PURE__*/(0, _react.forwardRef)(({
|
15
|
+
variants,
|
16
|
+
style,
|
17
|
+
rawStyle,
|
18
|
+
...props
|
19
|
+
}, passedRef) => {
|
20
|
+
const storedRef = (0, _react.useRef)();
|
21
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
|
22
|
+
...props,
|
23
|
+
ref: ref => {
|
24
|
+
storedRef.current = ref;
|
25
|
+
const styleResult = typeof style === 'function' ? style({
|
26
|
+
pressed: false
|
27
|
+
}) : style;
|
28
|
+
const fnArgs = typeof styleResult === 'function'
|
29
|
+
// @ts-expect-error - this is hidden from TS
|
30
|
+
? styleResult.getBoundArgs() : [];
|
31
|
+
if (typeof passedRef === 'object' && passedRef !== null) {
|
32
|
+
passedRef.current = ref;
|
33
|
+
}
|
34
|
+
const returnFn = typeof passedRef === 'function' ? passedRef(ref) : () => {};
|
35
|
+
|
36
|
+
// @ts-expect-error - this is hidden from TS
|
37
|
+
_specs.UnistylesShadowRegistry.add(ref, rawStyle ?? [], variants, [fnArgs]);
|
38
|
+
return () => {
|
39
|
+
// @ts-expect-error - this is hidden from TS
|
40
|
+
_specs.UnistylesShadowRegistry.remove(ref);
|
41
|
+
if (typeof returnFn === 'function') {
|
42
|
+
returnFn();
|
43
|
+
}
|
44
|
+
};
|
45
|
+
},
|
46
|
+
style: state => {
|
47
|
+
const styleResult = typeof style === 'function' ? style(state) : style;
|
48
|
+
const fnArgs = typeof styleResult === 'function'
|
49
|
+
// @ts-expect-error - this is hidden from TS
|
50
|
+
? styleResult.getBoundArgs() : [];
|
51
|
+
const pressId = (0, _core.getId)();
|
52
|
+
if (storedRef.current) {
|
53
|
+
// @ts-expect-error - this is hidden from TS
|
54
|
+
_specs.UnistylesShadowRegistry.remove(storedRef.current);
|
55
|
+
// @ts-expect-error - this is hidden from TS
|
56
|
+
_specs.UnistylesShadowRegistry.add(storedRef.current, rawStyle ?? [], variants, [fnArgs], pressId);
|
57
|
+
}
|
58
|
+
return typeof styleResult === 'function'
|
59
|
+
// @ts-expect-error - this is hidden from TS
|
60
|
+
? styleResult(pressId) : styleResult;
|
61
|
+
}
|
62
|
+
});
|
63
|
+
});
|
64
|
+
//# sourceMappingURL=Pressable.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_specs","_core","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","Pressable","exports","forwardRef","variants","style","rawStyle","props","passedRef","storedRef","useRef","jsx","ref","current","styleResult","pressed","fnArgs","getBoundArgs","returnFn","UnistylesShadowRegistry","add","remove","state","pressId","getId"],"sourceRoot":"../../../src","sources":["components/Pressable.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAA+B,IAAAI,WAAA,GAAAJ,OAAA;AAAA,SAAAK,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAP,wBAAAO,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAA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AI,EAAE,EAAEF,QAAQ,EAAE,CAACY,MAAM,CAAC,CAAC;MAEpE,OAAO,MAAM;QACT;QACAG,8BAAuB,CAACE,MAAM,CAACT,GAAG,CAAC;QAEnC,IAAI,OAAOM,QAAQ,KAAK,UAAU,EAAE;UAChCA,QAAQ,CAAC,CAAC;QACd;MACJ,CAAC;IACL,CAAE;IACFb,KAAK,EAAEiB,KAAK,IAAI;MACZ,MAAMR,WAAW,GAAG,OAAOT,KAAK,KAAK,UAAU,GACzCA,KAAK,CAACiB,KAAK,CAAC,GACZjB,KAAK;MACX,MAAMW,MAAM,GAAG,OAAOF,WAAW,KAAK;MAClC;MAAA,EACEA,WAAW,CAACG,YAAY,CAAC,CAAC,GAC1B,EAAE;MACR,MAAMM,OAAO,GAAG,IAAAC,WAAK,EAAC,CAAC;MAEvB,IAAIf,SAAS,CAACI,OAAO,EAAE;QACnB;QACAM,8BAAuB,CAACE,MAAM,CAACZ,SAAS,CAACI,OAAO,CAAC;QACjD;QACAM,8BAAuB,CAACC,GAAG,CAACX,SAAS,CAACI,OAAO,EAAEP,QAAQ,IAAI,EAAE,EAAEF,QAAQ,EAAE,CAACY,MAAM,CAAC,EAAEO,OAAO,CAAC;MAC/F;MAEA,OAAO,OAAOT,WAAW,KAAK;MAC1B;MAAA,EACEA,WAAW,CAACS,OAAO,CAAC,GACpBT,WAAW;IACrB;EAAE,CACL,CAAC;AAEV,CAAC,CAAC","ignoreList":[]}
|
@@ -0,0 +1,97 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Pressable = void 0;
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
8
|
+
var _reactNative = require("react-native");
|
9
|
+
var _specs = require("../specs");
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
13
|
+
const initialState = {
|
14
|
+
pressed: false,
|
15
|
+
hovered: false,
|
16
|
+
focused: false
|
17
|
+
};
|
18
|
+
const events = {
|
19
|
+
'pointerdown': {
|
20
|
+
pressed: true
|
21
|
+
},
|
22
|
+
'pointerup': {
|
23
|
+
pressed: false
|
24
|
+
},
|
25
|
+
'pointerenter': {
|
26
|
+
hovered: true
|
27
|
+
},
|
28
|
+
'pointerleave': {
|
29
|
+
hovered: false
|
30
|
+
},
|
31
|
+
'focus': {
|
32
|
+
focused: true
|
33
|
+
},
|
34
|
+
'blur': {
|
35
|
+
focused: false
|
36
|
+
}
|
37
|
+
};
|
38
|
+
const Pressable = exports.Pressable = /*#__PURE__*/(0, _react.forwardRef)(({
|
39
|
+
variants,
|
40
|
+
style,
|
41
|
+
...props
|
42
|
+
}, passedRef) => {
|
43
|
+
const storedRef = (0, _react.useRef)();
|
44
|
+
const state = (0, _react.useRef)(initialState);
|
45
|
+
const styleRef = (0, _react.useRef)(style);
|
46
|
+
(0, _react.useEffect)(() => {
|
47
|
+
styleRef.current = style;
|
48
|
+
}, [style]);
|
49
|
+
(0, _react.useEffect)(() => {
|
50
|
+
const handler = newState => () => {
|
51
|
+
state.current = {
|
52
|
+
...state.current,
|
53
|
+
...newState
|
54
|
+
};
|
55
|
+
const styleResult = typeof styleRef.current === 'function' ? styleRef.current(state.current) : styleRef.current;
|
56
|
+
const fnArgs = typeof styleResult === 'function'
|
57
|
+
// @ts-expect-error - this is hidden from TS
|
58
|
+
? styleResult.getBoundArgs() : [];
|
59
|
+
const extractedResult = typeof styleResult === 'function' ? styleResult() : styleResult;
|
60
|
+
|
61
|
+
// @ts-expect-error - this is hidden from TS
|
62
|
+
_specs.UnistylesShadowRegistry.add(storedRef.current, [extractedResult], variants, [fnArgs]);
|
63
|
+
};
|
64
|
+
if (!storedRef.current) {
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
|
68
|
+
// ref on the web is dom element
|
69
|
+
const ref = storedRef.current;
|
70
|
+
Object.entries(events).forEach(([event, state]) => {
|
71
|
+
ref.addEventListener(event, handler(state));
|
72
|
+
});
|
73
|
+
return () => {
|
74
|
+
Object.entries(events).forEach(([event, state]) => {
|
75
|
+
ref.removeEventListener(event, handler(state));
|
76
|
+
});
|
77
|
+
};
|
78
|
+
}, []);
|
79
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
|
80
|
+
...props,
|
81
|
+
ref: ref => {
|
82
|
+
storedRef.current = ref;
|
83
|
+
const styleResult = typeof style === 'function' ? style(initialState) : style;
|
84
|
+
const fnArgs = typeof styleResult === 'function'
|
85
|
+
// @ts-expect-error - this is hidden from TS
|
86
|
+
? styleResult.getBoundArgs() : [];
|
87
|
+
const extractedResult = typeof styleResult === 'function' ? styleResult() : styleResult;
|
88
|
+
if (typeof passedRef === 'object' && passedRef !== null) {
|
89
|
+
passedRef.current = ref;
|
90
|
+
}
|
91
|
+
|
92
|
+
// @ts-expect-error - this is hidden from TS
|
93
|
+
_specs.UnistylesShadowRegistry.add(ref, [extractedResult], variants, [fnArgs]);
|
94
|
+
}
|
95
|
+
});
|
96
|
+
});
|
97
|
+
//# sourceMappingURL=Pressable.web.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_specs","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","initialState","pressed","hovered","focused","events","Pressable","exports","forwardRef","variants","style","props","passedRef","storedRef","useRef","state","styleRef","useEffect","current","handler","newState","styleResult","fnArgs","getBoundArgs","extractedResult","UnistylesShadowRegistry","add","ref","entries","forEach","event","addEventListener","removeEventListener","jsx"],"sourceRoot":"../../../src","sources":["components/Pressable.web.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AAAkD,IAAAG,WAAA,GAAAH,OAAA;AAAA,SAAAI,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAN,wBAAAM,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,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TgB,GAAG,EAAEA,GAAG,IAAI;MACRd,SAAS,CAACK,OAAO,GAAGS,GAAG;MACvB,MAAMN,WAAW,GAAG,OAAOX,KAAK,KAAK,UAAU,GACzCA,KAAK,CAACT,YAAY,CAAC,GACnBS,KAAK;MACX,MAAMY,MAAM,GAAG,OAAOD,WAAW,KAAK;MAClC;MAAA,EACEA,WAAW,CAACE,YAAY,CAAC,CAAC,GAC1B,EAAE;MACR,MAAMC,eAAe,GAAG,OAAOH,WAAW,KAAK,UAAU,GAClDA,WAAW,CAAc,CAAC,GAC3BA,WAAW;MAEjB,IAAI,OAAOT,SAAS,KAAK,QAAQ,IAAIA,SAAS,KAAK,IAAI,EAAE;QACrDA,SAAS,CAACM,OAAO,GAAGS,GAAG;MAC3B;;MAEA;MACAF,8BAAuB,CAACC,GAAG,CAACC,GAAG,EAAE,CAACH,eAAe,CAAC,EAAEf,QAAQ,EAAE,CAACa,MAAM,CAAC,CAAC;IAC3E;EAAE,CACL,CAAC;AAEV,CAAC,CAAC","ignoreList":[]}
|
@@ -15,6 +15,13 @@ Object.defineProperty(exports, "Hide", {
|
|
15
15
|
return _Hide.Hide;
|
16
16
|
}
|
17
17
|
});
|
18
|
+
Object.defineProperty(exports, "Pressable", {
|
19
|
+
enumerable: true,
|
20
|
+
get: function () {
|
21
|
+
return _Pressable.Pressable;
|
22
|
+
}
|
23
|
+
});
|
18
24
|
var _Hide = require("./Hide");
|
19
25
|
var _Display = require("./Display");
|
26
|
+
var _Pressable = require("./Pressable");
|
20
27
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_Hide","require","_Display"],"sourceRoot":"../../../src","sources":["components/index.ts"],"mappings":"
|
1
|
+
{"version":3,"names":["_Hide","require","_Display","_Pressable"],"sourceRoot":"../../../src","sources":["components/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA","ignoreList":[]}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.getBoundArgs = void 0;
|
7
|
+
const getBoundArgs = fn => {
|
8
|
+
const boundArgs = [];
|
9
|
+
fn.bind = (thisArg, ...args) => {
|
10
|
+
boundArgs.push(...args);
|
11
|
+
const newFn = Function.prototype.bind.apply(fn, [thisArg, ...args]);
|
12
|
+
newFn.getBoundArgs = () => boundArgs;
|
13
|
+
return newFn;
|
14
|
+
};
|
15
|
+
return fn;
|
16
|
+
};
|
17
|
+
exports.getBoundArgs = getBoundArgs;
|
18
|
+
//# sourceMappingURL=getBoundArgs.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["getBoundArgs","fn","boundArgs","bind","thisArg","args","push","newFn","Function","prototype","apply","exports"],"sourceRoot":"../../../src","sources":["core/getBoundArgs.ts"],"mappings":";;;;;;AAAO,MAAMA,YAAY,GAAIC,EAAY,IAAK;EAC1C,MAAMC,SAAS,GAAG,EAAgB;EAElCD,EAAE,CAACE,IAAI,GAAG,CAACC,OAAO,EAAE,GAAGC,IAAI,KAAK;IAC5BH,SAAS,CAACI,IAAI,CAAC,GAAGD,IAAI,CAAC;IAEvB,MAAME,KAAK,GAAGC,QAAQ,CAACC,SAAS,CAACN,IAAI,CAACO,KAAK,CAACT,EAAE,EAAE,CAACG,OAAO,EAAE,GAAGC,IAAI,CAAC,CAAC;IAEnEE,KAAK,CAACP,YAAY,GAAG,MAAME,SAAS;IAEpC,OAAOK,KAAK;EAChB,CAAC;EAED,OAAON,EAAE;AACb,CAAC;AAAAU,OAAA,CAAAX,YAAA,GAAAA,YAAA","ignoreList":[]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["getId","Math","random","toString","substring","exports"],"sourceRoot":"../../../src","sources":["core/getId.ts"],"mappings":";;;;;;AAAO,MAAMA,KAAK,GAAGA,CAAA,KAAM,GAAGC,IAAI,CAACC,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC,CAACC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;AAAAC,OAAA,CAAAL,KAAA,GAAAA,KAAA","ignoreList":[]}
|
@@ -9,5 +9,19 @@ Object.defineProperty(exports, "createUnistylesComponent", {
|
|
9
9
|
return _createUnistylesComponent.createUnistylesComponent;
|
10
10
|
}
|
11
11
|
});
|
12
|
+
Object.defineProperty(exports, "getBoundArgs", {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return _getBoundArgs.getBoundArgs;
|
16
|
+
}
|
17
|
+
});
|
18
|
+
Object.defineProperty(exports, "getId", {
|
19
|
+
enumerable: true,
|
20
|
+
get: function () {
|
21
|
+
return _getId.getId;
|
22
|
+
}
|
23
|
+
});
|
12
24
|
var _createUnistylesComponent = require("./createUnistylesComponent");
|
25
|
+
var _getBoundArgs = require("./getBoundArgs");
|
26
|
+
var _getId = require("./getId");
|
13
27
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_createUnistylesComponent","require"],"sourceRoot":"../../../src","sources":["core/index.ts"],"mappings":"
|
1
|
+
{"version":3,"names":["_createUnistylesComponent","require","_getBoundArgs","_getId"],"sourceRoot":"../../../src","sources":["core/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,yBAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA","ignoreList":[]}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
Object.defineProperty(exports, "useMedia", {
|
7
|
+
enumerable: true,
|
8
|
+
get: function () {
|
9
|
+
return _useMedia.useMedia;
|
10
|
+
}
|
11
|
+
});
|
12
|
+
var _useMedia = require("./useMedia");
|
13
|
+
//# sourceMappingURL=index.js.map
|