react-native-unistyles 2.0.0-alpha.7 → 2.0.0-alpha.9
Sign up to get free protection for your applications and to get access to all the features.
- package/cxx/UnistylesRuntime.cpp +24 -31
- package/cxx/UnistylesRuntime.h +11 -12
- package/ios/UnistylesModule.mm +20 -20
- package/lib/commonjs/{types/cxx.js → common.js} +6 -6
- package/lib/commonjs/common.js.map +1 -0
- package/lib/commonjs/{UnistyleRegistry.js → core/UnistyleRegistry.js} +1 -8
- package/lib/commonjs/core/UnistyleRegistry.js.map +1 -0
- package/lib/commonjs/{Unistyles.js → core/Unistyles.js} +2 -7
- package/lib/commonjs/core/Unistyles.js.map +1 -0
- package/lib/commonjs/core/UnistylesModule.js.map +1 -0
- package/lib/commonjs/{UnistylesRuntime.js → core/UnistylesRuntime.js} +6 -6
- package/lib/commonjs/core/UnistylesRuntime.js.map +1 -0
- package/lib/commonjs/core/index.js +13 -0
- package/lib/commonjs/core/index.js.map +1 -0
- package/lib/commonjs/hooks/index.js +10 -3
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/{useInitialTheme.js → hooks/useInitialTheme.js} +6 -2
- package/lib/commonjs/hooks/useInitialTheme.js.map +1 -0
- package/lib/commonjs/hooks/useUnistyles.js +54 -0
- package/lib/commonjs/hooks/useUnistyles.js.map +1 -0
- package/lib/commonjs/index.js +10 -16
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/common.js +2 -0
- package/lib/commonjs/types/{mediaQueries.js.map → common.js.map} +1 -1
- package/lib/commonjs/types/index.js +4 -4
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/types/mq.js +6 -0
- package/lib/{module/types/mediaQueries.js.map → commonjs/types/mq.js.map} +1 -1
- package/lib/commonjs/types/unistyles.js +6 -0
- package/lib/commonjs/types/unistyles.js.map +1 -0
- package/lib/commonjs/useStyles.js +7 -4
- package/lib/commonjs/useStyles.js.map +1 -1
- package/lib/commonjs/utils/breakpoints.js +18 -20
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/index.js +10 -38
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/mq.js +67 -53
- package/lib/commonjs/utils/mq.js.map +1 -1
- package/lib/commonjs/utils/mqParser.js +86 -0
- package/lib/commonjs/utils/mqParser.js.map +1 -0
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/module/{types/cxx.js → common.js} +8 -6
- package/lib/module/common.js.map +1 -0
- package/lib/module/{UnistyleRegistry.js → core/UnistyleRegistry.js} +1 -8
- package/lib/module/core/UnistyleRegistry.js.map +1 -0
- package/lib/module/{Unistyles.js → core/Unistyles.js} +1 -6
- package/lib/module/core/Unistyles.js.map +1 -0
- package/lib/module/core/UnistylesModule.js.map +1 -0
- package/lib/module/{UnistylesRuntime.js → core/UnistylesRuntime.js} +2 -2
- package/lib/module/core/UnistylesRuntime.js.map +1 -0
- package/lib/module/core/index.js +2 -0
- package/lib/module/core/index.js.map +1 -0
- package/lib/module/hooks/index.js +2 -1
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useInitialTheme.js +10 -0
- package/lib/module/hooks/useInitialTheme.js.map +1 -0
- package/lib/module/hooks/useUnistyles.js +47 -0
- package/lib/module/hooks/useUnistyles.js.map +1 -0
- package/lib/module/index.js +11 -18
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/common.js +2 -0
- package/lib/module/types/common.js.map +1 -0
- package/lib/module/types/index.js +1 -1
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/types/mq.js +2 -0
- package/lib/module/types/mq.js.map +1 -0
- package/lib/module/types/unistyles.js +2 -0
- package/lib/module/types/unistyles.js.map +1 -0
- package/lib/module/useStyles.js +6 -3
- package/lib/module/useStyles.js.map +1 -1
- package/lib/module/utils/breakpoints.js +14 -16
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/index.js +2 -2
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/mq.js +65 -51
- package/lib/module/utils/mq.js.map +1 -1
- package/lib/module/utils/mqParser.js +79 -0
- package/lib/module/utils/mqParser.js.map +1 -0
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/typescript/src/common.d.ts +17 -0
- package/lib/typescript/src/common.d.ts.map +1 -0
- package/lib/typescript/src/{UnistyleRegistry.d.ts → core/UnistyleRegistry.d.ts} +2 -3
- package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -0
- package/lib/typescript/src/{Unistyles.d.ts → core/Unistyles.d.ts} +0 -3
- package/lib/typescript/src/core/Unistyles.d.ts.map +1 -0
- package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -0
- package/lib/typescript/src/{UnistylesRuntime.d.ts → core/UnistylesRuntime.d.ts} +6 -6
- package/lib/typescript/src/core/UnistylesRuntime.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 -0
- package/lib/typescript/src/hooks/index.d.ts +2 -1
- package/lib/typescript/src/hooks/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useInitialTheme.d.ts +3 -0
- package/lib/typescript/src/hooks/useInitialTheme.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts +12 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +10 -12
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +5 -9
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/common.d.ts +3 -0
- package/lib/typescript/src/types/common.d.ts.map +1 -0
- package/lib/typescript/src/types/core.d.ts +9 -4
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +5 -4
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/mq.d.ts +3 -0
- package/lib/typescript/src/types/mq.d.ts.map +1 -0
- package/lib/typescript/src/types/{cxx.d.ts → unistyles.d.ts} +4 -23
- package/lib/typescript/src/types/unistyles.d.ts.map +1 -0
- package/lib/typescript/src/useStyles.d.ts +8 -6
- package/lib/typescript/src/useStyles.d.ts.map +1 -1
- package/lib/typescript/src/utils/breakpoints.d.ts +2 -2
- package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +2 -2
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/mq.d.ts +15 -9
- package/lib/typescript/src/utils/mq.d.ts.map +1 -1
- package/lib/typescript/src/utils/mqParser.d.ts +3 -0
- package/lib/typescript/src/utils/mqParser.d.ts.map +1 -0
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/common.ts +19 -0
- package/src/{UnistyleRegistry.ts → core/UnistyleRegistry.ts} +3 -12
- package/src/{Unistyles.ts → core/Unistyles.ts} +2 -9
- package/src/{UnistylesRuntime.ts → core/UnistylesRuntime.ts} +4 -4
- package/src/core/index.ts +1 -0
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useInitialTheme.ts +11 -0
- package/src/hooks/useUnistyles.ts +55 -0
- package/src/index.ts +17 -20
- package/src/types/breakpoints.ts +6 -11
- package/src/types/common.ts +2 -0
- package/src/types/core.ts +10 -4
- package/src/types/index.ts +5 -9
- package/src/types/mq.ts +3 -0
- package/src/types/{cxx.ts → unistyles.ts} +4 -28
- package/src/useStyles.ts +15 -8
- package/src/utils/breakpoints.ts +13 -12
- package/src/utils/index.ts +2 -9
- package/src/utils/mq.ts +75 -46
- package/src/utils/mqParser.ts +99 -0
- package/src/utils/styles.ts +2 -2
- package/lib/commonjs/UnistyleRegistry.js.map +0 -1
- package/lib/commonjs/Unistyles.js.map +0 -1
- package/lib/commonjs/UnistylesEngine.js +0 -26
- package/lib/commonjs/UnistylesEngine.js.map +0 -1
- package/lib/commonjs/UnistylesModule.js.map +0 -1
- package/lib/commonjs/UnistylesRuntime.js.map +0 -1
- package/lib/commonjs/hooks/useDimensions.js +0 -10
- package/lib/commonjs/hooks/useDimensions.js.map +0 -1
- package/lib/commonjs/hooks/useDimensions.web.js +0 -34
- package/lib/commonjs/hooks/useDimensions.web.js.map +0 -1
- package/lib/commonjs/types/cxx.js.map +0 -1
- package/lib/commonjs/types/mediaQueries.js +0 -2
- package/lib/commonjs/useInitialTheme.js.map +0 -1
- package/lib/commonjs/useUnistyles.js +0 -51
- package/lib/commonjs/useUnistyles.js.map +0 -1
- package/lib/commonjs/utils/mediaQueries.js +0 -98
- package/lib/commonjs/utils/mediaQueries.js.map +0 -1
- package/lib/module/UnistyleRegistry.js.map +0 -1
- package/lib/module/Unistyles.js.map +0 -1
- package/lib/module/UnistylesEngine.js +0 -19
- package/lib/module/UnistylesEngine.js.map +0 -1
- package/lib/module/UnistylesModule.js.map +0 -1
- package/lib/module/UnistylesRuntime.js.map +0 -1
- package/lib/module/hooks/useDimensions.js +0 -3
- package/lib/module/hooks/useDimensions.js.map +0 -1
- package/lib/module/hooks/useDimensions.web.js +0 -27
- package/lib/module/hooks/useDimensions.web.js.map +0 -1
- package/lib/module/types/cxx.js.map +0 -1
- package/lib/module/types/mediaQueries.js +0 -2
- package/lib/module/useInitialTheme.js +0 -6
- package/lib/module/useInitialTheme.js.map +0 -1
- package/lib/module/useUnistyles.js +0 -44
- package/lib/module/useUnistyles.js.map +0 -1
- package/lib/module/utils/mediaQueries.js +0 -85
- package/lib/module/utils/mediaQueries.js.map +0 -1
- package/lib/typescript/src/UnistyleRegistry.d.ts.map +0 -1
- package/lib/typescript/src/Unistyles.d.ts.map +0 -1
- package/lib/typescript/src/UnistylesEngine.d.ts +0 -11
- package/lib/typescript/src/UnistylesEngine.d.ts.map +0 -1
- package/lib/typescript/src/UnistylesModule.d.ts.map +0 -1
- package/lib/typescript/src/UnistylesRuntime.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useDimensions.d.ts +0 -3
- package/lib/typescript/src/hooks/useDimensions.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useDimensions.web.d.ts +0 -3
- package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +0 -1
- package/lib/typescript/src/types/cxx.d.ts.map +0 -1
- package/lib/typescript/src/types/mediaQueries.d.ts +0 -10
- package/lib/typescript/src/types/mediaQueries.d.ts.map +0 -1
- package/lib/typescript/src/useInitialTheme.d.ts +0 -3
- package/lib/typescript/src/useInitialTheme.d.ts.map +0 -1
- package/lib/typescript/src/useUnistyles.d.ts +0 -10
- package/lib/typescript/src/useUnistyles.d.ts.map +0 -1
- package/lib/typescript/src/utils/mediaQueries.d.ts +0 -11
- package/lib/typescript/src/utils/mediaQueries.d.ts.map +0 -1
- package/src/UnistylesEngine.ts +0 -24
- package/src/hooks/useDimensions.ts +0 -4
- package/src/hooks/useDimensions.web.ts +0 -34
- package/src/types/mediaQueries.ts +0 -15
- package/src/useInitialTheme.ts +0 -7
- package/src/useUnistyles.ts +0 -61
- package/src/utils/mediaQueries.ts +0 -152
- /package/lib/commonjs/{UnistylesModule.js → core/UnistylesModule.js} +0 -0
- /package/lib/module/{UnistylesModule.js → core/UnistylesModule.js} +0 -0
- /package/lib/typescript/src/{UnistylesModule.d.ts → core/UnistylesModule.d.ts} +0 -0
- /package/src/{UnistylesModule.ts → core/UnistylesModule.ts} +0 -0
package/cxx/UnistylesRuntime.cpp
CHANGED
@@ -98,11 +98,11 @@ jsi::Value UnistylesRuntime::get(jsi::Runtime& runtime, const jsi::PropNameID& p
|
|
98
98
|
std::sort(sortedBreakpointEntriesVec.begin(), sortedBreakpointEntriesVec.end(), [](const std::pair<std::string, double>& a, const std::pair<std::string, double>& b) {
|
99
99
|
return a.second < b.second;
|
100
100
|
});
|
101
|
-
|
101
|
+
|
102
102
|
if (sortedBreakpointEntriesVec.size() == 0) {
|
103
103
|
throw jsi::JSError(runtime, UnistylesErrorBreakpointsCannotBeEmpty);
|
104
104
|
}
|
105
|
-
|
105
|
+
|
106
106
|
if (sortedBreakpointEntriesVec.at(0).second != 0) {
|
107
107
|
throw jsi::JSError(runtime, UnistylesErrorBreakpointsMustStartFromZero);
|
108
108
|
}
|
@@ -125,9 +125,11 @@ jsi::Value UnistylesRuntime::get(jsi::Runtime& runtime, const jsi::PropNameID& p
|
|
125
125
|
[this](jsi::Runtime &runtime, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) -> jsi::Value {
|
126
126
|
std::string themeName = arguments[0].asString(runtime).utf8(runtime);
|
127
127
|
|
128
|
-
this->themeName
|
129
|
-
|
130
|
-
|
128
|
+
if (this->themeName != themeName) {
|
129
|
+
this->themeName = themeName;
|
130
|
+
this->onThemeChangeCallback(themeName);
|
131
|
+
}
|
132
|
+
|
131
133
|
return jsi::Value::undefined();
|
132
134
|
}
|
133
135
|
);
|
@@ -145,26 +147,11 @@ jsi::Value UnistylesRuntime::get(jsi::Runtime& runtime, const jsi::PropNameID& p
|
|
145
147
|
if (!enableAdaptiveThemes || !this->supportsAutomaticColorScheme) {
|
146
148
|
return jsi::Value::undefined();
|
147
149
|
}
|
148
|
-
|
149
|
-
this->themeName
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
}
|
154
|
-
);
|
155
|
-
}
|
156
|
-
|
157
|
-
if (propName == "unregister") {
|
158
|
-
return jsi::Function::createFromHostFunction(runtime,
|
159
|
-
jsi::PropNameID::forAscii(runtime, "unregister"),
|
160
|
-
1,
|
161
|
-
[this](jsi::Runtime &runtime, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) -> jsi::Value {
|
162
|
-
this->hasAdaptiveThemes = false;
|
163
|
-
this->supportsAutomaticColorScheme = false;
|
164
|
-
this->themeName = "";
|
165
|
-
this->breakpoint = "";
|
166
|
-
this->themes.clear();
|
167
|
-
this->sortedBreakpointPairs.clear();
|
150
|
+
|
151
|
+
if (this->themeName != this->colorScheme) {
|
152
|
+
this->themeName = this->colorScheme;
|
153
|
+
this->onThemeChangeCallback(this->themeName);
|
154
|
+
}
|
168
155
|
|
169
156
|
return jsi::Value::undefined();
|
170
157
|
}
|
@@ -190,12 +177,13 @@ void UnistylesRuntime::set(jsi::Runtime& runtime, const jsi::PropNameID& propNam
|
|
190
177
|
themesVector.push_back(theme);
|
191
178
|
}
|
192
179
|
}
|
193
|
-
|
180
|
+
|
194
181
|
if (themesVector.size() == 0) {
|
195
182
|
throw jsi::JSError(runtime, UnistylesErrorThemesCannotBeEmpty);
|
196
183
|
}
|
197
184
|
|
198
185
|
this->themes = themesVector;
|
186
|
+
this->themeName = "";
|
199
187
|
|
200
188
|
bool hasLightTheme = std::find(themesVector.begin(), themesVector.end(), "light") != themesVector.end();
|
201
189
|
bool hasDarkTheme = std::find(themesVector.begin(), themesVector.end(), "dark") != themesVector.end();
|
@@ -224,16 +212,19 @@ std::string UnistylesRuntime::getBreakpointFromScreenWidth(int width, const std:
|
|
224
212
|
|
225
213
|
void UnistylesRuntime::handleScreenSizeChange(int width, int height) {
|
226
214
|
std::string breakpoint = this->getBreakpointFromScreenWidth(width, this->sortedBreakpointPairs);
|
215
|
+
bool shouldNotify = this->breakpoint != breakpoint || this->screenWidth != width || this->screenHeight != height;
|
227
216
|
|
228
217
|
this->breakpoint = breakpoint;
|
229
218
|
this->screenWidth = width;
|
230
219
|
this->screenHeight = height;
|
231
|
-
|
220
|
+
|
232
221
|
int orientation = width > height
|
233
222
|
? UnistylesOrientationLandscape
|
234
223
|
: UnistylesOrientationPortrait;
|
235
224
|
|
236
|
-
|
225
|
+
if (shouldNotify) {
|
226
|
+
this->onLayoutChangeCallback(breakpoint, orientation, width, height);
|
227
|
+
}
|
237
228
|
}
|
238
229
|
|
239
230
|
void UnistylesRuntime::handleAppearanceChange(std::string colorScheme) {
|
@@ -242,9 +233,11 @@ void UnistylesRuntime::handleAppearanceChange(std::string colorScheme) {
|
|
242
233
|
if (!this->supportsAutomaticColorScheme || !this->hasAdaptiveThemes) {
|
243
234
|
return;
|
244
235
|
}
|
245
|
-
|
246
|
-
this->themeName
|
247
|
-
|
236
|
+
|
237
|
+
if (this->themeName != this->colorScheme) {
|
238
|
+
this->onThemeChangeCallback(this->colorScheme);
|
239
|
+
this->themeName = this->colorScheme;
|
240
|
+
}
|
248
241
|
}
|
249
242
|
|
250
243
|
jsi::Value UnistylesRuntime::getThemeOrFail(jsi::Runtime& runtime) {
|
package/cxx/UnistylesRuntime.h
CHANGED
@@ -16,13 +16,10 @@ const std::string UnistylesErrorBreakpointsCannotBeEmpty = "UNISTYLES_ERROR_BREA
|
|
16
16
|
const std::string UnistylesErrorBreakpointsMustStartFromZero = "UNISTYLES_ERROR_BREAKPOINTS_MUST_START_FROM_ZER0";
|
17
17
|
const std::string UnistylesErrorThemesCannotBeEmpty = "UNISTYLES_ERROR_THEMES_CANNOT_BE_EMPTY";
|
18
18
|
|
19
|
-
typedef void(^UnistylesThemeChangeEvent)(std::string themeName);
|
20
|
-
typedef void(^UnistylesBreakpointChangeEvent)(std::string breakpoint, int layout, int screenWidth, int screenHeight);
|
21
|
-
|
22
19
|
class JSI_EXPORT UnistylesRuntime : public jsi::HostObject {
|
23
20
|
private:
|
24
|
-
|
25
|
-
|
21
|
+
std::function<void(std::string)> onThemeChangeCallback;
|
22
|
+
std::function<void(std::string breakpoint, int layout, int screenWidth, int screenHeight)> onLayoutChangeCallback;
|
26
23
|
|
27
24
|
int screenWidth;
|
28
25
|
int screenHeight;
|
@@ -30,16 +27,10 @@ private:
|
|
30
27
|
|
31
28
|
public:
|
32
29
|
UnistylesRuntime(
|
33
|
-
UnistylesThemeChangeEvent onThemeChange,
|
34
|
-
UnistylesBreakpointChangeEvent onBreakpointChange,
|
35
30
|
int screenWidth,
|
36
31
|
int screenHeight,
|
37
32
|
std::string colorScheme
|
38
|
-
):
|
39
|
-
onBreakpointChange(onBreakpointChange),
|
40
|
-
screenWidth(screenWidth),
|
41
|
-
screenHeight(screenHeight),
|
42
|
-
colorScheme(colorScheme) {}
|
33
|
+
): screenWidth(screenWidth), screenHeight(screenHeight), colorScheme(colorScheme) {}
|
43
34
|
|
44
35
|
bool hasAdaptiveThemes;
|
45
36
|
bool supportsAutomaticColorScheme;
|
@@ -48,6 +39,14 @@ public:
|
|
48
39
|
std::string breakpoint;
|
49
40
|
std::vector<std::string> themes;
|
50
41
|
std::vector<std::pair<std::string, double>> sortedBreakpointPairs;
|
42
|
+
|
43
|
+
void onThemeChange(std::function<void(std::string)> callback) {
|
44
|
+
this->onThemeChangeCallback = callback;
|
45
|
+
}
|
46
|
+
|
47
|
+
void onLayoutChange(std::function<void(std::string breakpoint, int layout, int screenWidth, int screenHeight)> callback) {
|
48
|
+
this->onLayoutChangeCallback = callback;
|
49
|
+
}
|
51
50
|
|
52
51
|
jsi::Value get(jsi::Runtime&, const jsi::PropNameID& name) override;
|
53
52
|
void set(jsi::Runtime& runtime, const jsi::PropNameID& propNameId, const jsi::Value& value) override;
|
package/ios/UnistylesModule.mm
CHANGED
@@ -31,7 +31,7 @@ RCT_EXPORT_MODULE(Unistyles)
|
|
31
31
|
|
32
32
|
- (void)dealloc {
|
33
33
|
if (self.unistylesRuntime != nullptr) {
|
34
|
-
|
34
|
+
self.unistylesRuntime = nullptr;
|
35
35
|
}
|
36
36
|
|
37
37
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
@@ -49,14 +49,18 @@ RCT_EXPORT_MODULE(Unistyles)
|
|
49
49
|
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
|
50
50
|
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
|
51
51
|
|
52
|
-
(
|
52
|
+
if (self.unistylesRuntime != nullptr) {
|
53
|
+
((UnistylesRuntime*)self.unistylesRuntime)->handleScreenSizeChange((int)screenWidth, (int)screenHeight);
|
54
|
+
}
|
53
55
|
});
|
54
56
|
}
|
55
57
|
|
56
58
|
- (void)appearanceChanged:(NSNotification *)notification {
|
57
59
|
std::string colorScheme = getColorScheme();
|
58
60
|
|
59
|
-
(
|
61
|
+
if (self.unistylesRuntime != nullptr) {
|
62
|
+
((UnistylesRuntime*)self.unistylesRuntime)->handleAppearanceChange(colorScheme);
|
63
|
+
}
|
60
64
|
}
|
61
65
|
|
62
66
|
#pragma mark - Event emitter
|
@@ -80,10 +84,7 @@ RCT_EXPORT_MODULE(Unistyles)
|
|
80
84
|
|
81
85
|
#pragma mark - Core
|
82
86
|
|
83
|
-
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install)
|
84
|
-
{
|
85
|
-
NSLog(@"Installing Unistyles 🦄...");
|
86
|
-
|
87
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
|
87
88
|
RCTBridge* bridge = [RCTBridge currentBridge];
|
88
89
|
RCTCxxBridge* cxxBridge = (RCTCxxBridge*)bridge;
|
89
90
|
|
@@ -107,12 +108,18 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install)
|
|
107
108
|
return @true;
|
108
109
|
}
|
109
110
|
|
110
|
-
|
111
111
|
void registerUnistylesHostObject(jsi::Runtime &runtime, UnistylesModule* weakSelf) {
|
112
112
|
CGFloat initialScreenWidth = [UIScreen mainScreen].bounds.size.width;
|
113
113
|
CGFloat initialScreenHeight = [UIScreen mainScreen].bounds.size.height;
|
114
114
|
std::string initialColorScheme = getColorScheme();
|
115
|
-
|
115
|
+
|
116
|
+
auto unistylesRuntime = std::make_shared<UnistylesRuntime>(
|
117
|
+
(int)initialScreenWidth,
|
118
|
+
(int)initialScreenHeight,
|
119
|
+
initialColorScheme
|
120
|
+
);
|
121
|
+
|
122
|
+
unistylesRuntime.get()->onThemeChange([=](std::string theme) {
|
116
123
|
NSDictionary *body = @{
|
117
124
|
@"type": @"theme",
|
118
125
|
@"payload": @{
|
@@ -121,8 +128,9 @@ void registerUnistylesHostObject(jsi::Runtime &runtime, UnistylesModule* weakSel
|
|
121
128
|
};
|
122
129
|
|
123
130
|
[weakSelf emitEvent:@"onChange" withBody:body];
|
124
|
-
};
|
125
|
-
|
131
|
+
});
|
132
|
+
|
133
|
+
unistylesRuntime.get()->onLayoutChange([=](std::string breakpoint, int orientation, int width, int height) {
|
126
134
|
NSDictionary *body = @{
|
127
135
|
@"type": @"layout",
|
128
136
|
@"payload": @{
|
@@ -136,15 +144,7 @@ void registerUnistylesHostObject(jsi::Runtime &runtime, UnistylesModule* weakSel
|
|
136
144
|
};
|
137
145
|
|
138
146
|
[weakSelf emitEvent:@"onChange" withBody:body];
|
139
|
-
};
|
140
|
-
|
141
|
-
auto unistylesRuntime = std::make_shared<UnistylesRuntime>(
|
142
|
-
onThemeChange,
|
143
|
-
onBreakpointChange,
|
144
|
-
(int)initialScreenWidth,
|
145
|
-
(int)initialScreenHeight,
|
146
|
-
initialColorScheme
|
147
|
-
);
|
147
|
+
});
|
148
148
|
|
149
149
|
weakSelf.unistylesRuntime = unistylesRuntime.get();
|
150
150
|
|
@@ -4,11 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.UnistylesError = exports.ScreenOrientation = exports.CxxUnistylesEventTypes = void 0;
|
7
|
-
let ScreenOrientation = exports.ScreenOrientation = /*#__PURE__*/function (ScreenOrientation) {
|
8
|
-
ScreenOrientation[ScreenOrientation["Portrait"] = 1] = "Portrait";
|
9
|
-
ScreenOrientation[ScreenOrientation["Landscape"] = 2] = "Landscape";
|
10
|
-
return ScreenOrientation;
|
11
|
-
}({});
|
12
7
|
let CxxUnistylesEventTypes = exports.CxxUnistylesEventTypes = /*#__PURE__*/function (CxxUnistylesEventTypes) {
|
13
8
|
CxxUnistylesEventTypes["Theme"] = "theme";
|
14
9
|
CxxUnistylesEventTypes["Layout"] = "layout";
|
@@ -22,5 +17,10 @@ let UnistylesError = exports.UnistylesError = /*#__PURE__*/function (UnistylesEr
|
|
22
17
|
UnistylesError["BreakpointsCannotBeEmpty"] = "UNISTYLES_ERROR_BREAKPOINTS_CANNOT_BE_EMPTY";
|
23
18
|
UnistylesError["BreakpointsMustStartFromZero"] = "UNISTYLES_ERROR_BREAKPOINTS_MUST_START_FROM_ZERO";
|
24
19
|
return UnistylesError;
|
20
|
+
}({}); // todo to string?
|
21
|
+
let ScreenOrientation = exports.ScreenOrientation = /*#__PURE__*/function (ScreenOrientation) {
|
22
|
+
ScreenOrientation[ScreenOrientation["Portrait"] = 1] = "Portrait";
|
23
|
+
ScreenOrientation[ScreenOrientation["Landscape"] = 2] = "Landscape";
|
24
|
+
return ScreenOrientation;
|
25
25
|
}({});
|
26
|
-
//# sourceMappingURL=
|
26
|
+
//# sourceMappingURL=common.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["CxxUnistylesEventTypes","exports","UnistylesError","ScreenOrientation"],"sourceRoot":"../../src","sources":["common.ts"],"mappings":";;;;;;IAAYA,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA;AAAA,IAKtBE,cAAc,GAAAD,OAAA,CAAAC,cAAA,0BAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAA,OAAdA,cAAc;AAAA,OAS1B;AAAA,IACYC,iBAAiB,GAAAF,OAAA,CAAAE,iBAAA,0BAAjBA,iBAAiB;EAAjBA,iBAAiB,CAAjBA,iBAAiB;EAAjBA,iBAAiB,CAAjBA,iBAAiB;EAAA,OAAjBA,iBAAiB;AAAA"}
|
@@ -21,6 +21,7 @@ class UnistyleRegistry {
|
|
21
21
|
return this;
|
22
22
|
};
|
23
23
|
addBreakpoints = breakpoints => {
|
24
|
+
this.breakpoints = breakpoints;
|
24
25
|
this.unistylesBridge.useBreakpoints(breakpoints);
|
25
26
|
this.sortedBreakpointPairs = this.unistylesBridge.sortedBreakpointPairs;
|
26
27
|
return this;
|
@@ -32,14 +33,6 @@ class UnistyleRegistry {
|
|
32
33
|
}
|
33
34
|
return this;
|
34
35
|
};
|
35
|
-
dangerouslyUnregister = () => {
|
36
|
-
this.config = {};
|
37
|
-
this.themeNames = [];
|
38
|
-
this.themes = {};
|
39
|
-
this.breakpoints = {};
|
40
|
-
this.sortedBreakpointPairs = [];
|
41
|
-
this.unistylesBridge.unregister();
|
42
|
-
};
|
43
36
|
}
|
44
37
|
exports.UnistyleRegistry = UnistyleRegistry;
|
45
38
|
//# sourceMappingURL=UnistyleRegistry.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["UnistyleRegistry","config","themeNames","themes","breakpoints","sortedBreakpointPairs","constructor","unistylesBridge","addThemes","keys","Object","addBreakpoints","useBreakpoints","addConfig","adaptiveThemes","useAdaptiveThemes","exports"],"sourceRoot":"../../../src","sources":["core/UnistyleRegistry.ts"],"mappings":";;;;;;AAGO,MAAMA,gBAAgB,CAAC;EACnBC,MAAM,GAAoB,CAAC,CAAC;EAC5BC,UAAU,GAAiC,EAAE;EAC7CC,MAAM,GAAoB,CAAC,CAAC;EAC5BC,WAAW,GAAyB,CAAC,CAAC;EACtCC,qBAAqB,GAA0F,EAAE;EAExHC,WAAWA,CAASC,eAAgC,EAAE;IAAA,KAAlCA,eAAgC,GAAhCA,eAAgC;EAAG;EAEhDC,SAAS,GAAIL,MAAuB,IAAK;IAC5C,IAAI,CAACA,MAAM,GAAGA,MAAM;IAEpB,MAAMM,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACN,MAAM,CAAiC;IAEhE,IAAI,CAACI,eAAe,CAACJ,MAAM,GAAGM,IAAI;IAClC,IAAI,CAACP,UAAU,GAAGO,IAAI;IAEtB,OAAO,IAAI;EACf,CAAC;EAEME,cAAc,GAAIP,WAAiC,IAAK;IAC3D,IAAI,CAACA,WAAW,GAAGA,WAAW;IAC9B,IAAI,CAACG,eAAe,CAACK,cAAc,CAACR,WAAW,CAAC;IAChD,IAAI,CAACC,qBAAqB,GAAG,IAAI,CAACE,eAAe,CAACF,qBAAqB;IAEvE,OAAO,IAAI;EACf,CAAC;EAEMQ,SAAS,GAAIZ,MAAuB,IAAK;IAC5C,IAAI,CAACA,MAAM,GAAGA,MAAM;IAEpB,IAAIA,MAAM,CAACa,cAAc,EAAE;MACvB,IAAI,CAACP,eAAe,CAACQ,iBAAiB,CAACd,MAAM,CAACa,cAAc,CAAC;IACjE;IAEA,OAAO,IAAI;EACf,CAAC;AACL;AAACE,OAAA,CAAAhB,gBAAA,GAAAA,gBAAA"}
|
@@ -6,21 +6,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.unistyles = void 0;
|
7
7
|
var _UnistylesModule = require("./UnistylesModule");
|
8
8
|
var _UnistylesRuntime = require("./UnistylesRuntime");
|
9
|
-
var _UnistylesEngine = require("./UnistylesEngine");
|
10
9
|
var _UnistyleRegistry = require("./UnistyleRegistry");
|
11
|
-
var
|
10
|
+
var _common = require("../common");
|
12
11
|
class Unistyles {
|
13
12
|
constructor() {
|
14
13
|
const isInstalled = _UnistylesModule.UnistylesModule?.install() ?? false;
|
15
14
|
if (!isInstalled) {
|
16
|
-
throw new Error(
|
15
|
+
throw new Error(_common.UnistylesError.RuntimeUnavailable);
|
17
16
|
}
|
18
17
|
|
19
18
|
// @ts-ignore
|
20
19
|
this._bridge = global.__UNISTYLES__;
|
21
20
|
this._registry = new _UnistyleRegistry.UnistyleRegistry(this._bridge);
|
22
21
|
this._runtime = new _UnistylesRuntime.UnistylesRuntime(this._bridge, this._registry);
|
23
|
-
this._engine = new _UnistylesEngine.UnistylesBuiltInEngine(this._registry, this._runtime);
|
24
22
|
}
|
25
23
|
get registry() {
|
26
24
|
return this._registry;
|
@@ -28,9 +26,6 @@ class Unistyles {
|
|
28
26
|
get runtime() {
|
29
27
|
return this._runtime;
|
30
28
|
}
|
31
|
-
get engine() {
|
32
|
-
return this._engine;
|
33
|
-
}
|
34
29
|
}
|
35
30
|
const unistyles = exports.unistyles = new Unistyles();
|
36
31
|
//# sourceMappingURL=Unistyles.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_UnistylesModule","require","_UnistylesRuntime","_UnistyleRegistry","_common","Unistyles","constructor","isInstalled","UnistylesModule","install","Error","UnistylesError","RuntimeUnavailable","_bridge","global","__UNISTYLES__","_registry","UnistyleRegistry","_runtime","UnistylesRuntime","registry","runtime","unistyles","exports"],"sourceRoot":"../../../src","sources":["core/Unistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAH,OAAA;AAEA,MAAMI,SAAS,CAAC;EAKZC,WAAWA,CAAA,EAAG;IACV,MAAMC,WAAW,GAAGC,gCAAe,EAAEC,OAAO,CAAC,CAAC,IAAI,KAAK;IAEvD,IAAI,CAACF,WAAW,EAAE;MACd,MAAM,IAAIG,KAAK,CAACC,sBAAc,CAACC,kBAAkB,CAAC;IACtD;;IAEA;IACA,IAAI,CAACC,OAAO,GAAGC,MAAM,CAACC,aAAgC;IACtD,IAAI,CAACC,SAAS,GAAG,IAAIC,kCAAgB,CAAC,IAAI,CAACJ,OAAO,CAAC;IACnD,IAAI,CAACK,QAAQ,GAAG,IAAIC,kCAAgB,CAAC,IAAI,CAACN,OAAO,EAAE,IAAI,CAACG,SAAS,CAAC;EACtE;EAEA,IAAWI,QAAQA,CAAA,EAAG;IAClB,OAAO,IAAI,CAACJ,SAAS;EACzB;EAEA,IAAWK,OAAOA,CAAA,EAAG;IACjB,OAAO,IAAI,CAACH,QAAQ;EACxB;AACJ;AAEO,MAAMI,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG,IAAIjB,SAAS,CAAC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_reactNative","require","UnistylesModule","exports","NativeModules","Unistyles"],"sourceRoot":"../../../src","sources":["core/UnistylesModule.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAMO,MAAMC,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAGE,0BAAa,EAAEC,SAAkC"}
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.UnistylesRuntime = void 0;
|
7
|
-
var
|
7
|
+
var _common = require("../common");
|
8
8
|
class UnistylesRuntime {
|
9
9
|
constructor(unistylesBridge, registry) {
|
10
10
|
this.unistylesBridge = unistylesBridge;
|
@@ -37,23 +37,23 @@ class UnistylesRuntime {
|
|
37
37
|
height
|
38
38
|
} = this.screen;
|
39
39
|
if (width > height) {
|
40
|
-
return
|
40
|
+
return _common.ScreenOrientation.Landscape;
|
41
41
|
}
|
42
|
-
return
|
42
|
+
return _common.ScreenOrientation.Portrait;
|
43
43
|
}
|
44
44
|
setTheme = name => {
|
45
|
-
if (
|
45
|
+
if (this.hasTheme(name)) {
|
46
46
|
this.unistylesBridge.useTheme(name);
|
47
47
|
return true;
|
48
48
|
}
|
49
|
-
throw new Error(
|
49
|
+
throw new Error(_common.UnistylesError.ThemeNotRegistered);
|
50
50
|
};
|
51
51
|
getTheme = forName => {
|
52
52
|
if (this.registry.themeNames.length === 0) {
|
53
53
|
return {};
|
54
54
|
}
|
55
55
|
if (!this.hasTheme(forName)) {
|
56
|
-
throw new Error(
|
56
|
+
throw new Error(_common.UnistylesError.ThemeNotFound);
|
57
57
|
}
|
58
58
|
return this.registry.themes[forName];
|
59
59
|
};
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_common","require","UnistylesRuntime","constructor","unistylesBridge","registry","colorScheme","hasAdaptiveThemes","sortedBreakpoints","sortedBreakpointPairs","themeName","breakpoint","screen","width","screenWidth","height","screenHeight","orientation","ScreenOrientation","Landscape","Portrait","setTheme","name","hasTheme","useTheme","Error","UnistylesError","ThemeNotRegistered","getTheme","forName","themeNames","length","ThemeNotFound","themes","setAdaptiveThemes","enable","useAdaptiveThemes","exports"],"sourceRoot":"../../../src","sources":["core/UnistylesRuntime.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAKO,MAAMC,gBAAgB,CAAC;EAC1BC,WAAWA,CAASC,eAAgC,EAAUC,QAA0B,EAAE;IAAA,KAAtED,eAAgC,GAAhCA,eAAgC;IAAA,KAAUC,QAA0B,GAA1BA,QAA0B;EAAG;EAE3F,IAAWC,WAAWA,CAAA,EAAG;IACrB,OAAO,IAAI,CAACF,eAAe,CAACE,WAAW;EAC3C;EAEA,IAAWC,iBAAiBA,CAAA,EAAG;IAC3B,OAAO,IAAI,CAACH,eAAe,CAACG,iBAAiB;EACjD;EAEA,IAAWC,iBAAiBA,CAAA,EAAG;IAC3B,OAAO,IAAI,CAACH,QAAQ,CAACI,qBAAqB;EAC9C;EAEA,IAAWC,SAASA,CAAA,EAAG;IACnB,OAAO,IAAI,CAACN,eAAe,CAACM,SAAS;EACzC;EAEA,IAAWC,UAAUA,CAAA,EAAG;IACpB,OAAO,IAAI,CAACP,eAAe,CAACO,UAAU;EAC1C;EAEA,IAAWC,MAAMA,CAAA,EAAG;IAChB,OAAO;MACHC,KAAK,EAAE,IAAI,CAACT,eAAe,CAACU,WAAW;MACvCC,MAAM,EAAE,IAAI,CAACX,eAAe,CAACY;IACjC,CAAC;EACL;EAEA,IAAWC,WAAWA,CAAA,EAAG;IACrB,MAAM;MAAEJ,KAAK;MAAEE;IAAO,CAAC,GAAG,IAAI,CAACH,MAAM;IAErC,IAAIC,KAAK,GAAGE,MAAM,EAAE;MAChB,OAAOG,yBAAiB,CAACC,SAAS;IACtC;IAEA,OAAOD,yBAAiB,CAACE,QAAQ;EACrC;EAEOC,QAAQ,GAAIC,IAA2B,IAAK;IAC/C,IAAI,IAAI,CAACC,QAAQ,CAACD,IAAI,CAAC,EAAE;MACrB,IAAI,CAAClB,eAAe,CAACoB,QAAQ,CAACF,IAAI,CAAC;MAEnC,OAAO,IAAI;IACf;IAEA,MAAM,IAAIG,KAAK,CAACC,sBAAc,CAACC,kBAAkB,CAAC;EACtD,CAAC;EAEMC,QAAQ,GAAIC,OAA8B,IAAK;IAClD,IAAI,IAAI,CAACxB,QAAQ,CAACyB,UAAU,CAACC,MAAM,KAAK,CAAC,EAAE;MACvC,OAAO,CAAC,CAAC;IACb;IAEA,IAAI,CAAC,IAAI,CAACR,QAAQ,CAACM,OAAO,CAAC,EAAE;MACzB,MAAM,IAAIJ,KAAK,CAACC,sBAAc,CAACM,aAAa,CAAC;IACjD;IAEA,OAAO,IAAI,CAAC3B,QAAQ,CAAC4B,MAAM,CAACJ,OAAO,CAAC;EACxC,CAAC;EAEMK,iBAAiB,GAAIC,MAAe,IAAK;IAC5C,IAAI,CAAC/B,eAAe,CAACgC,iBAAiB,CAACD,MAAM,CAAC;EAClD,CAAC;EAEOZ,QAAQ,GAAID,IAA2B,IAAKA,IAAI,IAAI,IAAI,CAACjB,QAAQ,CAAC4B,MAAM;AACpF;AAACI,OAAA,CAAAnC,gBAAA,GAAAA,gBAAA"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
Object.defineProperty(exports, "unistyles", {
|
7
|
+
enumerable: true,
|
8
|
+
get: function () {
|
9
|
+
return _Unistyles.unistyles;
|
10
|
+
}
|
11
|
+
});
|
12
|
+
var _Unistyles = require("./Unistyles");
|
13
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_Unistyles","require"],"sourceRoot":"../../../src","sources":["core/index.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA"}
|
@@ -3,11 +3,18 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
Object.defineProperty(exports, "
|
6
|
+
Object.defineProperty(exports, "useInitialTheme", {
|
7
7
|
enumerable: true,
|
8
8
|
get: function () {
|
9
|
-
return
|
9
|
+
return _useInitialTheme.useInitialTheme;
|
10
10
|
}
|
11
11
|
});
|
12
|
-
|
12
|
+
Object.defineProperty(exports, "useUnistyles", {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return _useUnistyles.useUnistyles;
|
16
|
+
}
|
17
|
+
});
|
18
|
+
var _useInitialTheme = require("./useInitialTheme");
|
19
|
+
var _useUnistyles = require("./useUnistyles");
|
13
20
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["_useInitialTheme","require","_useUnistyles"],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA"}
|
@@ -5,9 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.useInitialTheme = void 0;
|
7
7
|
var _react = require("react");
|
8
|
-
var
|
8
|
+
var _core = require("../core");
|
9
9
|
const useInitialTheme = forName => {
|
10
|
-
(0, _react.useMemo)(() =>
|
10
|
+
(0, _react.useMemo)(() => {
|
11
|
+
if (!_core.unistyles.runtime.themeName) {
|
12
|
+
_core.unistyles.runtime.setTheme(forName);
|
13
|
+
}
|
14
|
+
}, []);
|
11
15
|
};
|
12
16
|
exports.useInitialTheme = useInitialTheme;
|
13
17
|
//# sourceMappingURL=useInitialTheme.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_react","require","_core","useInitialTheme","forName","useMemo","unistyles","runtime","themeName","setTheme","exports"],"sourceRoot":"../../../src","sources":["hooks/useInitialTheme.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAGO,MAAME,eAAe,GAAIC,OAA8B,IAAK;EAC/D,IAAAC,cAAO,EAAC,MAAM;IACV,IAAI,CAACC,eAAS,CAACC,OAAO,CAACC,SAAS,EAAE;MAC9BF,eAAS,CAACC,OAAO,CAACE,QAAQ,CAACL,OAAO,CAAC;IACvC;EACJ,CAAC,EAAE,EAAE,CAAC;AACV,CAAC;AAAAM,OAAA,CAAAP,eAAA,GAAAA,eAAA"}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useUnistyles = void 0;
|
7
|
+
var _reactNative = require("react-native");
|
8
|
+
var _react = require("react");
|
9
|
+
var _core = require("../core");
|
10
|
+
var _common = require("../common");
|
11
|
+
const unistylesEvents = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.Unistyles);
|
12
|
+
const useUnistyles = () => {
|
13
|
+
const [theme, setTheme] = (0, _react.useState)(_core.unistyles.runtime.getTheme(_core.unistyles.runtime.themeName));
|
14
|
+
const [layout, setLayout] = (0, _react.useState)({
|
15
|
+
breakpoint: _core.unistyles.runtime.breakpoint,
|
16
|
+
orientation: _core.unistyles.runtime.orientation,
|
17
|
+
screenSize: {
|
18
|
+
width: _core.unistyles.runtime.screen.width,
|
19
|
+
height: _core.unistyles.runtime.screen.height
|
20
|
+
}
|
21
|
+
});
|
22
|
+
(0, _react.useEffect)(() => {
|
23
|
+
const subscription = unistylesEvents.addListener('onChange', event => {
|
24
|
+
switch (event.type) {
|
25
|
+
case _common.CxxUnistylesEventTypes.Theme:
|
26
|
+
{
|
27
|
+
const themeEvent = event;
|
28
|
+
return setTheme(_core.unistyles.runtime.getTheme(themeEvent.payload.themeName));
|
29
|
+
}
|
30
|
+
case _common.CxxUnistylesEventTypes.Layout:
|
31
|
+
{
|
32
|
+
const layoutEvent = event;
|
33
|
+
return setLayout({
|
34
|
+
breakpoint: layoutEvent.payload.breakpoint,
|
35
|
+
orientation: layoutEvent.payload.orientation,
|
36
|
+
screenSize: {
|
37
|
+
width: layoutEvent.payload.screen.width,
|
38
|
+
height: layoutEvent.payload.screen.height
|
39
|
+
}
|
40
|
+
});
|
41
|
+
}
|
42
|
+
default:
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
});
|
46
|
+
return subscription.remove;
|
47
|
+
}, []);
|
48
|
+
return {
|
49
|
+
theme,
|
50
|
+
layout
|
51
|
+
};
|
52
|
+
};
|
53
|
+
exports.useUnistyles = useUnistyles;
|
54
|
+
//# sourceMappingURL=useUnistyles.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_react","_core","_common","unistylesEvents","NativeEventEmitter","NativeModules","Unistyles","useUnistyles","theme","setTheme","useState","unistyles","runtime","getTheme","themeName","layout","setLayout","breakpoint","orientation","screenSize","width","screen","height","useEffect","subscription","addListener","event","type","CxxUnistylesEventTypes","Theme","themeEvent","payload","Layout","layoutEvent","remove","exports"],"sourceRoot":"../../../src","sources":["hooks/useUnistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAGA,MAAMI,eAAe,GAAG,IAAIC,+BAAkB,CAACC,0BAAa,CAACC,SAAS,CAAC;AAEhE,MAAMC,YAAY,GAAGA,CAAA,KAAM;EAC9B,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAACC,eAAS,CAACC,OAAO,CAACC,QAAQ,CAACF,eAAS,CAACC,OAAO,CAACE,SAAS,CAAC,CAAC;EAC3F,MAAM,CAACC,MAAM,EAAEC,SAAS,CAAC,GAAG,IAAAN,eAAQ,EAAC;IACjCO,UAAU,EAAEN,eAAS,CAACC,OAAO,CAACK,UAAU;IACxCC,WAAW,EAAEP,eAAS,CAACC,OAAO,CAACM,WAAW;IAC1CC,UAAU,EAAE;MACRC,KAAK,EAAET,eAAS,CAACC,OAAO,CAACS,MAAM,CAACD,KAAK;MACrCE,MAAM,EAAEX,eAAS,CAACC,OAAO,CAACS,MAAM,CAACC;IACrC;EACJ,CAAC,CAAC;EAEF,IAAAC,gBAAS,EAAC,MAAM;IACZ,MAAMC,YAAY,GAAGrB,eAAe,CAACsB,WAAW,CAC5C,UAAU,EACTC,KAAsB,IAAK;MACxB,QAAQA,KAAK,CAACC,IAAI;QACd,KAAKC,8BAAsB,CAACC,KAAK;UAAE;YAC/B,MAAMC,UAAU,GAAGJ,KAA4B;YAE/C,OAAOjB,QAAQ,CAACE,eAAS,CAACC,OAAO,CAACC,QAAQ,CAACiB,UAAU,CAACC,OAAO,CAACjB,SAAS,CAAC,CAAC;UAC7E;QACA,KAAKc,8BAAsB,CAACI,MAAM;UAAE;YAChC,MAAMC,WAAW,GAAGP,KAAmC;YAEvD,OAAOV,SAAS,CAAC;cACbC,UAAU,EAAEgB,WAAW,CAACF,OAAO,CAACd,UAAU;cAC1CC,WAAW,EAAEe,WAAW,CAACF,OAAO,CAACb,WAAW;cAC5CC,UAAU,EAAE;gBACRC,KAAK,EAAEa,WAAW,CAACF,OAAO,CAACV,MAAM,CAACD,KAAK;gBACvCE,MAAM,EAAEW,WAAW,CAACF,OAAO,CAACV,MAAM,CAACC;cACvC;YACJ,CAAC,CAAC;UACN;QACA;UACI;MACR;IACJ,CACJ,CAAC;IAED,OAAOE,YAAY,CAACU,MAAM;EAC9B,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IACH1B,KAAK;IACLO;EACJ,CAAC;AACL,CAAC;AAAAoB,OAAA,CAAA5B,YAAA,GAAAA,YAAA"}
|
package/lib/commonjs/index.js
CHANGED
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
Object.defineProperty(exports, "ScreenOrientation", {
|
7
7
|
enumerable: true,
|
8
8
|
get: function () {
|
9
|
-
return
|
9
|
+
return _common.ScreenOrientation;
|
10
10
|
}
|
11
11
|
});
|
12
|
-
exports.
|
12
|
+
exports.UnistylesRuntime = exports.UnistylesRegistry = void 0;
|
13
13
|
Object.defineProperty(exports, "createStyleSheet", {
|
14
14
|
enumerable: true,
|
15
15
|
get: function () {
|
@@ -25,7 +25,7 @@ Object.defineProperty(exports, "mq", {
|
|
25
25
|
Object.defineProperty(exports, "useInitialTheme", {
|
26
26
|
enumerable: true,
|
27
27
|
get: function () {
|
28
|
-
return
|
28
|
+
return _hooks.useInitialTheme;
|
29
29
|
}
|
30
30
|
});
|
31
31
|
Object.defineProperty(exports, "useStyles", {
|
@@ -34,22 +34,16 @@ Object.defineProperty(exports, "useStyles", {
|
|
34
34
|
return _useStyles.useStyles;
|
35
35
|
}
|
36
36
|
});
|
37
|
-
var
|
38
|
-
var _types = require("./types");
|
37
|
+
var _core = require("./core");
|
39
38
|
var _utils = require("./utils");
|
40
|
-
var
|
39
|
+
var _hooks = require("./hooks");
|
40
|
+
var _common = require("./common");
|
41
41
|
var _useStyles = require("./useStyles");
|
42
42
|
var _createStyleSheet = require("./createStyleSheet");
|
43
|
-
const {
|
44
|
-
addThemes,
|
45
|
-
addBreakpoints,
|
46
|
-
addConfig
|
47
|
-
} = _Unistyles.unistyles.registry;
|
48
|
-
const UnistylesRuntime = exports.UnistylesRuntime = _Unistyles.unistyles.runtime;
|
49
43
|
const UnistylesRegistry = exports.UnistylesRegistry = {
|
50
|
-
addThemes,
|
51
|
-
addBreakpoints,
|
52
|
-
addConfig
|
44
|
+
addThemes: _core.unistyles.registry.addThemes,
|
45
|
+
addBreakpoints: _core.unistyles.registry.addBreakpoints,
|
46
|
+
addConfig: _core.unistyles.registry.addConfig
|
53
47
|
};
|
54
|
-
const
|
48
|
+
const UnistylesRuntime = exports.UnistylesRuntime = _core.unistyles.runtime;
|
55
49
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["_core","require","_utils","_hooks","_common","_useStyles","_createStyleSheet","UnistylesRegistry","exports","addThemes","unistyles","registry","addBreakpoints","addConfig","UnistylesRuntime","runtime"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AAEA,MAAMM,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG;EACtBE,SAAS,EAAEC,eAAS,CAACC,QAAQ,CAACF,SAAS;EACvCG,cAAc,EAAEF,eAAS,CAACC,QAAQ,CAACC,cAAc;EACjDC,SAAS,EAAEH,eAAS,CAACC,QAAQ,CAACE;AAClC,CAAC;AAED,MAAMC,gBAAgB,GAAAN,OAAA,CAAAM,gBAAA,GAAGJ,eAAS,CAACK,OAAO"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/common.ts"],"mappings":""}
|
@@ -14,14 +14,14 @@ Object.keys(_normalizer).forEach(function (key) {
|
|
14
14
|
}
|
15
15
|
});
|
16
16
|
});
|
17
|
-
var
|
18
|
-
Object.keys(
|
17
|
+
var _unistyles = require("./unistyles");
|
18
|
+
Object.keys(_unistyles).forEach(function (key) {
|
19
19
|
if (key === "default" || key === "__esModule") return;
|
20
|
-
if (key in exports && exports[key] ===
|
20
|
+
if (key in exports && exports[key] === _unistyles[key]) return;
|
21
21
|
Object.defineProperty(exports, key, {
|
22
22
|
enumerable: true,
|
23
23
|
get: function () {
|
24
|
-
return
|
24
|
+
return _unistyles[key];
|
25
25
|
}
|
26
26
|
});
|
27
27
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_normalizer","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","
|
1
|
+
{"version":3,"names":["_normalizer","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_unistyles"],"sourceRoot":"../../../src","sources":["types/index.ts"],"mappings":";;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,WAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,WAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,WAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,UAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,UAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,UAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,UAAA,CAAAL,GAAA;IAAA;EAAA;AAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/mq.ts"],"mappings":""}
|