react-native-unistyles 3.0.0-alpha.2 → 3.0.0-alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- package/Unistyles.podspec +3 -2
- package/cxx/core/HostStyle.cpp +9 -7
- package/cxx/core/UnistylesCommitHook.cpp +3 -6
- package/cxx/core/UnistylesCommitHook.h +6 -1
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +4 -0
- package/cxx/hybridObjects/HybridStyleSheet.cpp +4 -9
- package/cxx/hybridObjects/HybridStyleSheet.h +6 -6
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +15 -11
- package/cxx/parser/Parser.cpp +9 -1
- package/ios/UnistylesModuleOnLoad.h +2 -0
- package/ios/UnistylesModuleOnLoad.mm +8 -1
- package/package.json +1 -1
package/Unistyles.podspec
CHANGED
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
|
|
10
10
|
s.license = package["license"]
|
11
11
|
s.authors = package["author"]
|
12
12
|
|
13
|
-
s.platforms = { :ios => min_ios_version_supported
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
14
14
|
s.source = { :git => package["repository"], :tag => "#{s.version}" }
|
15
15
|
|
16
16
|
s.source_files = [
|
@@ -18,7 +18,8 @@ Pod::Spec.new do |s|
|
|
18
18
|
"cxx/**/*.{h,cpp,hpp}"
|
19
19
|
]
|
20
20
|
s.pod_target_xcconfig = {
|
21
|
-
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20"
|
21
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
22
|
+
"GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES"
|
22
23
|
}
|
23
24
|
|
24
25
|
s.public_header_files = [
|
package/cxx/core/HostStyle.cpp
CHANGED
@@ -7,10 +7,12 @@ using namespace facebook;
|
|
7
7
|
std::vector<jsi::PropNameID> HostStyle::getPropertyNames(jsi::Runtime& rt) {
|
8
8
|
auto propertyNames = std::vector<jsi::PropNameID> {};
|
9
9
|
|
10
|
+
propertyNames.reserve(8);
|
11
|
+
|
10
12
|
for (const auto& pair : this->_styleSheet->unistyles) {
|
11
13
|
propertyNames.emplace_back(jsi::PropNameID::forUtf8(rt, pair.first));
|
12
14
|
}
|
13
|
-
|
15
|
+
|
14
16
|
return propertyNames;
|
15
17
|
}
|
16
18
|
|
@@ -20,7 +22,7 @@ jsi::Value HostStyle::get(jsi::Runtime& rt, const jsi::PropNameID& propNameId) {
|
|
20
22
|
if (propertyName == helpers::UNISTYLES_ID) {
|
21
23
|
return jsi::Value(this->_styleSheet->tag);
|
22
24
|
}
|
23
|
-
|
25
|
+
|
24
26
|
if (propertyName == helpers::ADD_VARIANTS_FN) {
|
25
27
|
return this->createAddVariantsProxyFunction(rt);
|
26
28
|
}
|
@@ -28,7 +30,7 @@ jsi::Value HostStyle::get(jsi::Runtime& rt, const jsi::PropNameID& propNameId) {
|
|
28
30
|
if (this->_styleSheet->unistyles.contains(propertyName)) {
|
29
31
|
return valueFromUnistyle(rt, this->_styleSheet->unistyles[propertyName]);
|
30
32
|
}
|
31
|
-
|
33
|
+
|
32
34
|
return jsi::Value::undefined();
|
33
35
|
}
|
34
36
|
|
@@ -41,15 +43,15 @@ jsi::Function HostStyle::createAddVariantsProxyFunction(jsi::Runtime& rt) {
|
|
41
43
|
|
42
44
|
auto parser = parser::Parser(this->_unistylesRuntime);
|
43
45
|
auto pairs = parser.variantsToPairs(rt, arguments[0].asObject(rt));
|
44
|
-
|
46
|
+
|
45
47
|
if (pairs == this->_styleSheet->variants) {
|
46
48
|
return jsi::Value::undefined();
|
47
49
|
}
|
48
|
-
|
50
|
+
|
49
51
|
this->_styleSheet->variants = pairs;
|
50
|
-
|
52
|
+
|
51
53
|
parser.rebuildUnistylesWithVariants(rt, this->_styleSheet);
|
52
|
-
|
54
|
+
|
53
55
|
return jsi::Value::undefined();
|
54
56
|
});
|
55
57
|
}
|
@@ -3,12 +3,9 @@
|
|
3
3
|
using namespace margelo::nitro::unistyles;
|
4
4
|
using namespace facebook::react;
|
5
5
|
|
6
|
-
core::UnistylesCommitHook
|
7
|
-
|
8
|
-
|
9
|
-
};
|
10
|
-
|
11
|
-
core::UnistylesCommitHook::~UnistylesCommitHook() noexcept {}
|
6
|
+
core::UnistylesCommitHook::~UnistylesCommitHook() noexcept {
|
7
|
+
_uiManager->unregisterCommitHook(*this);
|
8
|
+
}
|
12
9
|
|
13
10
|
void core::UnistylesCommitHook::commitHookWasRegistered(const UIManager &uiManager) noexcept {}
|
14
11
|
void core::UnistylesCommitHook::commitHookWasUnregistered(const UIManager &uiManager) noexcept {}
|
@@ -11,7 +11,11 @@ namespace margelo::nitro::unistyles::core {
|
|
11
11
|
using namespace facebook::react;
|
12
12
|
|
13
13
|
struct UnistylesCommitHook : public UIManagerCommitHook {
|
14
|
-
UnistylesCommitHook(UIManager
|
14
|
+
UnistylesCommitHook(std::shared_ptr<UIManager> uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime)
|
15
|
+
: _unistylesRuntime{unistylesRuntime}, _uiManager{uiManager} {
|
16
|
+
_uiManager->registerCommitHook(*this);
|
17
|
+
}
|
18
|
+
|
15
19
|
~UnistylesCommitHook() noexcept override;
|
16
20
|
|
17
21
|
void commitHookWasRegistered(const UIManager &uiManager) noexcept override;
|
@@ -22,6 +26,7 @@ struct UnistylesCommitHook : public UIManagerCommitHook {
|
|
22
26
|
|
23
27
|
private:
|
24
28
|
std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
|
29
|
+
std::shared_ptr<UIManager> _uiManager;
|
25
30
|
};
|
26
31
|
|
27
32
|
}
|
@@ -4,6 +4,8 @@ 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 == 2, "Invalid babel transform. ShadowRegistry link expected two arguments.");
|
8
|
+
|
7
9
|
ShadowNode::Shared shadowNodeWrapper = shadowNodeFromValue(rt, args[0]);
|
8
10
|
core::Unistyle::Shared unistyleWrapper = core::unistyleFromValue(rt, args[1]);
|
9
11
|
|
@@ -15,6 +17,8 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
|
|
15
17
|
}
|
16
18
|
|
17
19
|
jsi::Value HybridShadowRegistry::unlink(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
|
20
|
+
helpers::assertThat(rt, count == 2, "Invalid babel transform. ShadowRegistry unlink expected two arguments.");
|
21
|
+
|
18
22
|
ShadowNode::Shared shadowNodeWrapper = shadowNodeFromValue(rt, args[0]);
|
19
23
|
core::Unistyle::Shared unistyleWrapper = core::unistyleFromValue(rt, args[1]);
|
20
24
|
|
@@ -14,7 +14,8 @@ double HybridStyleSheet::get___unid() {
|
|
14
14
|
}
|
15
15
|
|
16
16
|
jsi::Value HybridStyleSheet::create(jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) {
|
17
|
-
helpers::assertThat(rt,
|
17
|
+
helpers::assertThat(rt, count == 1, "StyleSheet.create expected to be called with one argument.");
|
18
|
+
helpers::assertThat(rt, arguments[0].isObject(), "StyleSheet.create expected to be called with object or function.");
|
18
19
|
|
19
20
|
auto thisStyleSheet = thisVal.asObject(rt);
|
20
21
|
auto& registry = core::UnistylesRegistry::get();
|
@@ -45,7 +46,8 @@ jsi::Value HybridStyleSheet::create(jsi::Runtime &rt, const jsi::Value &thisVal,
|
|
45
46
|
}
|
46
47
|
|
47
48
|
jsi::Value HybridStyleSheet::configure(jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) {
|
48
|
-
helpers::assertThat(rt,
|
49
|
+
helpers::assertThat(rt, count == 1, "StyleSheet.configure expected to be called with one argument.");
|
50
|
+
helpers::assertThat(rt, arguments[0].isObject(), "StyleSheet.configure expected to be called with object.");
|
49
51
|
|
50
52
|
// create new state
|
51
53
|
auto config = arguments[0].asObject(rt);
|
@@ -77,7 +79,6 @@ jsi::Value HybridStyleSheet::configure(jsi::Runtime &rt, const jsi::Value &thisV
|
|
77
79
|
|
78
80
|
verifyAndSelectTheme(rt);
|
79
81
|
loadExternalMethods(thisVal, rt);
|
80
|
-
registerCommitHook(rt);
|
81
82
|
|
82
83
|
return jsi::Value::undefined();
|
83
84
|
}
|
@@ -237,9 +238,3 @@ void HybridStyleSheet::onPlatformDependenciesChange(std::vector<UnistyleDependen
|
|
237
238
|
|
238
239
|
shadow::ShadowTreeManager::updateShadowTree(rt, shadowLeafUpdates);
|
239
240
|
}
|
240
|
-
|
241
|
-
void HybridStyleSheet::registerCommitHook(jsi::Runtime &rt) {
|
242
|
-
UIManager& uiManager = const_cast<UIManager&>(UIManagerBinding::getBinding(rt)->getUIManager());
|
243
|
-
|
244
|
-
this->_unistylesCommitHook = std::make_shared<core::UnistylesCommitHook>(uiManager, this->_unistylesRuntime);
|
245
|
-
}
|
@@ -16,11 +16,12 @@ using namespace margelo::nitro::unistyles;
|
|
16
16
|
using namespace facebook::react;
|
17
17
|
|
18
18
|
struct HybridStyleSheet: public HybridUnistylesStyleSheetSpec {
|
19
|
-
HybridStyleSheet(std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
HybridStyleSheet(std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime, std::shared_ptr<UIManager> uiManager)
|
20
|
+
: HybridObject(TAG), _unistylesRuntime{unistylesRuntime} {
|
21
|
+
this->_unistylesCommitHook = std::make_shared<core::UnistylesCommitHook>(uiManager, unistylesRuntime);
|
22
|
+
this->_unistylesRuntime->registerPlatformListener(
|
23
|
+
std::bind(&HybridStyleSheet::onPlatformDependenciesChange, this, std::placeholders::_1)
|
24
|
+
);
|
24
25
|
}
|
25
26
|
|
26
27
|
jsi::Value create(jsi::Runtime& rt,
|
@@ -52,7 +53,6 @@ private:
|
|
52
53
|
void setThemeFromColorScheme(jsi::Runtime& rt);
|
53
54
|
void loadExternalMethods(const jsi::Value& thisValue, jsi::Runtime& rt);
|
54
55
|
void onPlatformDependenciesChange(std::vector<UnistyleDependency> dependencies);
|
55
|
-
void registerCommitHook(jsi::Runtime& rt);
|
56
56
|
|
57
57
|
double __unid = -1;
|
58
58
|
std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
|
@@ -45,7 +45,7 @@ Insets HybridUnistylesRuntime::getInsets() {
|
|
45
45
|
|
46
46
|
Orientation HybridUnistylesRuntime::getOrientation() {
|
47
47
|
int orientation = this->_nativePlatform.getOrientation();
|
48
|
-
|
48
|
+
|
49
49
|
return static_cast<Orientation>(orientation);
|
50
50
|
};
|
51
51
|
|
@@ -68,14 +68,17 @@ void HybridUnistylesRuntime::setTheme(const std::string &themeName) {
|
|
68
68
|
|
69
69
|
void HybridUnistylesRuntime::setAdaptiveThemes(bool isEnabled) {
|
70
70
|
auto& registry = core::UnistylesRegistry::get();
|
71
|
-
|
71
|
+
|
72
72
|
std::vector<UnistyleDependency> changedDependencies{};
|
73
|
+
|
74
|
+
changedDependencies.reserve(5);
|
75
|
+
|
73
76
|
bool hadAdaptiveThemes = this->getHasAdaptiveThemes();
|
74
77
|
|
75
78
|
registry.setPrefersAdaptiveThemes(*_rt, isEnabled);
|
76
|
-
|
79
|
+
|
77
80
|
bool haveAdaptiveThemes = this->getHasAdaptiveThemes();
|
78
|
-
|
81
|
+
|
79
82
|
if (hadAdaptiveThemes != haveAdaptiveThemes) {
|
80
83
|
changedDependencies.push_back(UnistyleDependency::ADAPTIVETHEMES);
|
81
84
|
}
|
@@ -83,7 +86,7 @@ void HybridUnistylesRuntime::setAdaptiveThemes(bool isEnabled) {
|
|
83
86
|
// if user disabled it, or can't have adaptive themes, do nothing
|
84
87
|
if (!this->getHasAdaptiveThemes()) {
|
85
88
|
this->_onDependenciesChange(changedDependencies);
|
86
|
-
|
89
|
+
|
87
90
|
return;
|
88
91
|
}
|
89
92
|
|
@@ -99,16 +102,17 @@ void HybridUnistylesRuntime::setAdaptiveThemes(bool isEnabled) {
|
|
99
102
|
if (!currentThemeName.has_value() || nextTheme != currentThemeName.value()) {
|
100
103
|
changedDependencies.push_back(UnistyleDependency::THEME);
|
101
104
|
changedDependencies.push_back(UnistyleDependency::THEMENAME);
|
102
|
-
|
105
|
+
|
103
106
|
state.setTheme(nextTheme);
|
104
107
|
}
|
105
|
-
|
108
|
+
|
106
109
|
this->_onDependenciesChange(changedDependencies);
|
107
110
|
};
|
108
111
|
|
109
112
|
jsi::Value HybridUnistylesRuntime::updateTheme(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
|
110
|
-
helpers::assertThat(rt,
|
111
|
-
helpers::assertThat(rt, args[
|
113
|
+
helpers::assertThat(rt, count == 2, "UnistylesRuntime.updateTheme expected to be called with 2 arguments.");
|
114
|
+
helpers::assertThat(rt, args[0].isString(), "UnistylesRuntime.updateTheme expected first argument to be a string.");
|
115
|
+
helpers::assertThat(rt, args[1].isObject(), "UnistylesRuntime.updateTheme expected first argument to be a function.");
|
112
116
|
|
113
117
|
auto& registry = core::UnistylesRegistry::get();
|
114
118
|
auto themeName = args[0].asString(rt).utf8(rt);
|
@@ -116,7 +120,7 @@ jsi::Value HybridUnistylesRuntime::updateTheme(jsi::Runtime &rt, const jsi::Valu
|
|
116
120
|
helpers::assertThat(rt, args[1].asObject(rt).isFunction(rt), "second argument expected to be a function.");
|
117
121
|
|
118
122
|
registry.updateTheme(rt, themeName, args[1].asObject(rt).asFunction(rt));
|
119
|
-
|
123
|
+
|
120
124
|
this->_onDependenciesChange({UnistyleDependency::THEME});
|
121
125
|
|
122
126
|
return jsi::Value::undefined();
|
@@ -163,7 +167,7 @@ UnistylesCxxMiniRuntime HybridUnistylesRuntime::getMiniRuntime() {
|
|
163
167
|
nativeMiniRuntime.statusBar,
|
164
168
|
nativeMiniRuntime.navigationBar
|
165
169
|
};
|
166
|
-
|
170
|
+
|
167
171
|
return cxxMiniRuntime;
|
168
172
|
}
|
169
173
|
|
package/cxx/parser/Parser.cpp
CHANGED
@@ -133,6 +133,8 @@ void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleShee
|
|
133
133
|
// convert arguments to jsi::Value
|
134
134
|
auto metadata = unistyleFn->dynamicFunctionMetadata.value();
|
135
135
|
std::vector<jsi::Value> args{};
|
136
|
+
|
137
|
+
args.reserve(3);
|
136
138
|
|
137
139
|
for (int i = 0; i < metadata.count; i++) {
|
138
140
|
folly::dynamic& arg = metadata.arguments.at(i);
|
@@ -177,6 +179,8 @@ shadow::ShadowLeafUpdates parser::Parser::dependencyMapToShadowLeafUpdates(Depen
|
|
177
179
|
// convert jsi::Value arguments to folly::dynamic
|
178
180
|
std::vector<folly::dynamic> parser::Parser::parseDynamicFunctionArguments(jsi::Runtime& rt, size_t count, const jsi::Value* arguments) {
|
179
181
|
std::vector<folly::dynamic> parsedArgument{};
|
182
|
+
|
183
|
+
parsedArgument.reserve(3);
|
180
184
|
|
181
185
|
for (size_t i = 0; i < count; i++) {
|
182
186
|
auto& arg = arguments[i];
|
@@ -369,7 +373,9 @@ jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unist
|
|
369
373
|
std::vector<UnistyleDependency> parser::Parser::parseDependencies(jsi::Runtime &rt, jsi::Object&& dependencies) {
|
370
374
|
helpers::assertThat(rt, dependencies.isArray(rt), "babel transform is invalid. Unexpected type for dependencies. Please report new Github issue.");
|
371
375
|
|
372
|
-
std::vector<UnistyleDependency> parsedDependencies;
|
376
|
+
std::vector<UnistyleDependency> parsedDependencies{};
|
377
|
+
|
378
|
+
parsedDependencies.reserve(5);
|
373
379
|
|
374
380
|
helpers::iterateJSIArray(rt, dependencies.asArray(rt), [&](size_t i, jsi::Value& value){
|
375
381
|
auto dependency = static_cast<UnistyleDependency>(value.asNumber());
|
@@ -387,6 +393,8 @@ jsi::Value parser::Parser::parseTransforms(jsi::Runtime& rt, Unistyle::Shared un
|
|
387
393
|
}
|
388
394
|
|
389
395
|
std::vector<jsi::Value> parsedTransforms{};
|
396
|
+
|
397
|
+
parsedTransforms.reserve(2);
|
390
398
|
|
391
399
|
helpers::iterateJSIArray(rt, obj.asArray(rt), [&](size_t i, jsi::Value& value){
|
392
400
|
if (!value.isObject()) {
|
@@ -3,6 +3,8 @@
|
|
3
3
|
#import <React/RCTEventEmitter.h>
|
4
4
|
#import <ReactCommon/RCTTurboModuleWithJSIBindings.h>
|
5
5
|
#import "TurboUnistyles/TurboUnistyles.h"
|
6
|
+
#import <React/RCTSurfacePresenter.h>
|
7
|
+
#import <React/RCTScheduler.h>
|
6
8
|
|
7
9
|
@interface UnistylesModule: RCTEventEmitter<NativeTurboUnistylesSpec>
|
8
10
|
@end
|
@@ -10,10 +10,16 @@ using namespace margelo::nitro;
|
|
10
10
|
|
11
11
|
RCT_EXPORT_MODULE(Unistyles)
|
12
12
|
|
13
|
+
__weak RCTSurfacePresenter* _surfacePresenter;
|
14
|
+
|
13
15
|
+ (BOOL)requiresMainQueueSetup {
|
14
16
|
return YES;
|
15
17
|
}
|
16
18
|
|
19
|
+
- (void)setSurfacePresenter:(id<RCTSurfacePresenterStub>)surfacePresenter {
|
20
|
+
_surfacePresenter = surfacePresenter;
|
21
|
+
}
|
22
|
+
|
17
23
|
- (void)installJSIBindingsWithRuntime:(jsi::Runtime&)rt {
|
18
24
|
// function is called on: first init and every live reload
|
19
25
|
// check if this is live reload, if so let's replace UnistylesRuntime with new runtime
|
@@ -31,7 +37,8 @@ RCT_EXPORT_MODULE(Unistyles)
|
|
31
37
|
- (void)createHybrids:(jsi::Runtime&)rt {
|
32
38
|
auto nativePlatform = Unistyles::NativePlatform::create();
|
33
39
|
auto unistylesRuntime = std::make_shared<HybridUnistylesRuntime>(nativePlatform, rt);
|
34
|
-
auto
|
40
|
+
auto uiManager = [_surfacePresenter scheduler].uiManager;
|
41
|
+
auto styleSheet = std::make_shared<HybridStyleSheet>(unistylesRuntime, uiManager);
|
35
42
|
|
36
43
|
HybridObjectRegistry::registerHybridObjectConstructor("UnistylesRuntime", [unistylesRuntime]() -> std::shared_ptr<HybridObject>{
|
37
44
|
return unistylesRuntime;
|