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.
Files changed (208) hide show
  1. package/cxx/UnistylesRuntime.cpp +24 -31
  2. package/cxx/UnistylesRuntime.h +11 -12
  3. package/ios/UnistylesModule.mm +20 -20
  4. package/lib/commonjs/{types/cxx.js → common.js} +6 -6
  5. package/lib/commonjs/common.js.map +1 -0
  6. package/lib/commonjs/{UnistyleRegistry.js → core/UnistyleRegistry.js} +1 -8
  7. package/lib/commonjs/core/UnistyleRegistry.js.map +1 -0
  8. package/lib/commonjs/{Unistyles.js → core/Unistyles.js} +2 -7
  9. package/lib/commonjs/core/Unistyles.js.map +1 -0
  10. package/lib/commonjs/core/UnistylesModule.js.map +1 -0
  11. package/lib/commonjs/{UnistylesRuntime.js → core/UnistylesRuntime.js} +6 -6
  12. package/lib/commonjs/core/UnistylesRuntime.js.map +1 -0
  13. package/lib/commonjs/core/index.js +13 -0
  14. package/lib/commonjs/core/index.js.map +1 -0
  15. package/lib/commonjs/hooks/index.js +10 -3
  16. package/lib/commonjs/hooks/index.js.map +1 -1
  17. package/lib/commonjs/{useInitialTheme.js → hooks/useInitialTheme.js} +6 -2
  18. package/lib/commonjs/hooks/useInitialTheme.js.map +1 -0
  19. package/lib/commonjs/hooks/useUnistyles.js +54 -0
  20. package/lib/commonjs/hooks/useUnistyles.js.map +1 -0
  21. package/lib/commonjs/index.js +10 -16
  22. package/lib/commonjs/index.js.map +1 -1
  23. package/lib/commonjs/types/common.js +2 -0
  24. package/lib/commonjs/types/{mediaQueries.js.map → common.js.map} +1 -1
  25. package/lib/commonjs/types/index.js +4 -4
  26. package/lib/commonjs/types/index.js.map +1 -1
  27. package/lib/commonjs/types/mq.js +6 -0
  28. package/lib/{module/types/mediaQueries.js.map → commonjs/types/mq.js.map} +1 -1
  29. package/lib/commonjs/types/unistyles.js +6 -0
  30. package/lib/commonjs/types/unistyles.js.map +1 -0
  31. package/lib/commonjs/useStyles.js +7 -4
  32. package/lib/commonjs/useStyles.js.map +1 -1
  33. package/lib/commonjs/utils/breakpoints.js +18 -20
  34. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  35. package/lib/commonjs/utils/index.js +10 -38
  36. package/lib/commonjs/utils/index.js.map +1 -1
  37. package/lib/commonjs/utils/mq.js +67 -53
  38. package/lib/commonjs/utils/mq.js.map +1 -1
  39. package/lib/commonjs/utils/mqParser.js +86 -0
  40. package/lib/commonjs/utils/mqParser.js.map +1 -0
  41. package/lib/commonjs/utils/styles.js.map +1 -1
  42. package/lib/module/{types/cxx.js → common.js} +8 -6
  43. package/lib/module/common.js.map +1 -0
  44. package/lib/module/{UnistyleRegistry.js → core/UnistyleRegistry.js} +1 -8
  45. package/lib/module/core/UnistyleRegistry.js.map +1 -0
  46. package/lib/module/{Unistyles.js → core/Unistyles.js} +1 -6
  47. package/lib/module/core/Unistyles.js.map +1 -0
  48. package/lib/module/core/UnistylesModule.js.map +1 -0
  49. package/lib/module/{UnistylesRuntime.js → core/UnistylesRuntime.js} +2 -2
  50. package/lib/module/core/UnistylesRuntime.js.map +1 -0
  51. package/lib/module/core/index.js +2 -0
  52. package/lib/module/core/index.js.map +1 -0
  53. package/lib/module/hooks/index.js +2 -1
  54. package/lib/module/hooks/index.js.map +1 -1
  55. package/lib/module/hooks/useInitialTheme.js +10 -0
  56. package/lib/module/hooks/useInitialTheme.js.map +1 -0
  57. package/lib/module/hooks/useUnistyles.js +47 -0
  58. package/lib/module/hooks/useUnistyles.js.map +1 -0
  59. package/lib/module/index.js +11 -18
  60. package/lib/module/index.js.map +1 -1
  61. package/lib/module/types/common.js +2 -0
  62. package/lib/module/types/common.js.map +1 -0
  63. package/lib/module/types/index.js +1 -1
  64. package/lib/module/types/index.js.map +1 -1
  65. package/lib/module/types/mq.js +2 -0
  66. package/lib/module/types/mq.js.map +1 -0
  67. package/lib/module/types/unistyles.js +2 -0
  68. package/lib/module/types/unistyles.js.map +1 -0
  69. package/lib/module/useStyles.js +6 -3
  70. package/lib/module/useStyles.js.map +1 -1
  71. package/lib/module/utils/breakpoints.js +14 -16
  72. package/lib/module/utils/breakpoints.js.map +1 -1
  73. package/lib/module/utils/index.js +2 -2
  74. package/lib/module/utils/index.js.map +1 -1
  75. package/lib/module/utils/mq.js +65 -51
  76. package/lib/module/utils/mq.js.map +1 -1
  77. package/lib/module/utils/mqParser.js +79 -0
  78. package/lib/module/utils/mqParser.js.map +1 -0
  79. package/lib/module/utils/styles.js.map +1 -1
  80. package/lib/typescript/src/common.d.ts +17 -0
  81. package/lib/typescript/src/common.d.ts.map +1 -0
  82. package/lib/typescript/src/{UnistyleRegistry.d.ts → core/UnistyleRegistry.d.ts} +2 -3
  83. package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -0
  84. package/lib/typescript/src/{Unistyles.d.ts → core/Unistyles.d.ts} +0 -3
  85. package/lib/typescript/src/core/Unistyles.d.ts.map +1 -0
  86. package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -0
  87. package/lib/typescript/src/{UnistylesRuntime.d.ts → core/UnistylesRuntime.d.ts} +6 -6
  88. package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -0
  89. package/lib/typescript/src/core/index.d.ts +2 -0
  90. package/lib/typescript/src/core/index.d.ts.map +1 -0
  91. package/lib/typescript/src/hooks/index.d.ts +2 -1
  92. package/lib/typescript/src/hooks/index.d.ts.map +1 -1
  93. package/lib/typescript/src/hooks/useInitialTheme.d.ts +3 -0
  94. package/lib/typescript/src/hooks/useInitialTheme.d.ts.map +1 -0
  95. package/lib/typescript/src/hooks/useUnistyles.d.ts +12 -0
  96. package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -0
  97. package/lib/typescript/src/index.d.ts +10 -12
  98. package/lib/typescript/src/index.d.ts.map +1 -1
  99. package/lib/typescript/src/types/breakpoints.d.ts +5 -9
  100. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  101. package/lib/typescript/src/types/common.d.ts +3 -0
  102. package/lib/typescript/src/types/common.d.ts.map +1 -0
  103. package/lib/typescript/src/types/core.d.ts +9 -4
  104. package/lib/typescript/src/types/core.d.ts.map +1 -1
  105. package/lib/typescript/src/types/index.d.ts +5 -4
  106. package/lib/typescript/src/types/index.d.ts.map +1 -1
  107. package/lib/typescript/src/types/mq.d.ts +3 -0
  108. package/lib/typescript/src/types/mq.d.ts.map +1 -0
  109. package/lib/typescript/src/types/{cxx.d.ts → unistyles.d.ts} +4 -23
  110. package/lib/typescript/src/types/unistyles.d.ts.map +1 -0
  111. package/lib/typescript/src/useStyles.d.ts +8 -6
  112. package/lib/typescript/src/useStyles.d.ts.map +1 -1
  113. package/lib/typescript/src/utils/breakpoints.d.ts +2 -2
  114. package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
  115. package/lib/typescript/src/utils/index.d.ts +2 -2
  116. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  117. package/lib/typescript/src/utils/mq.d.ts +15 -9
  118. package/lib/typescript/src/utils/mq.d.ts.map +1 -1
  119. package/lib/typescript/src/utils/mqParser.d.ts +3 -0
  120. package/lib/typescript/src/utils/mqParser.d.ts.map +1 -0
  121. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  122. package/package.json +1 -1
  123. package/src/common.ts +19 -0
  124. package/src/{UnistyleRegistry.ts → core/UnistyleRegistry.ts} +3 -12
  125. package/src/{Unistyles.ts → core/Unistyles.ts} +2 -9
  126. package/src/{UnistylesRuntime.ts → core/UnistylesRuntime.ts} +4 -4
  127. package/src/core/index.ts +1 -0
  128. package/src/hooks/index.ts +2 -1
  129. package/src/hooks/useInitialTheme.ts +11 -0
  130. package/src/hooks/useUnistyles.ts +55 -0
  131. package/src/index.ts +17 -20
  132. package/src/types/breakpoints.ts +6 -11
  133. package/src/types/common.ts +2 -0
  134. package/src/types/core.ts +10 -4
  135. package/src/types/index.ts +5 -9
  136. package/src/types/mq.ts +3 -0
  137. package/src/types/{cxx.ts → unistyles.ts} +4 -28
  138. package/src/useStyles.ts +15 -8
  139. package/src/utils/breakpoints.ts +13 -12
  140. package/src/utils/index.ts +2 -9
  141. package/src/utils/mq.ts +75 -46
  142. package/src/utils/mqParser.ts +99 -0
  143. package/src/utils/styles.ts +2 -2
  144. package/lib/commonjs/UnistyleRegistry.js.map +0 -1
  145. package/lib/commonjs/Unistyles.js.map +0 -1
  146. package/lib/commonjs/UnistylesEngine.js +0 -26
  147. package/lib/commonjs/UnistylesEngine.js.map +0 -1
  148. package/lib/commonjs/UnistylesModule.js.map +0 -1
  149. package/lib/commonjs/UnistylesRuntime.js.map +0 -1
  150. package/lib/commonjs/hooks/useDimensions.js +0 -10
  151. package/lib/commonjs/hooks/useDimensions.js.map +0 -1
  152. package/lib/commonjs/hooks/useDimensions.web.js +0 -34
  153. package/lib/commonjs/hooks/useDimensions.web.js.map +0 -1
  154. package/lib/commonjs/types/cxx.js.map +0 -1
  155. package/lib/commonjs/types/mediaQueries.js +0 -2
  156. package/lib/commonjs/useInitialTheme.js.map +0 -1
  157. package/lib/commonjs/useUnistyles.js +0 -51
  158. package/lib/commonjs/useUnistyles.js.map +0 -1
  159. package/lib/commonjs/utils/mediaQueries.js +0 -98
  160. package/lib/commonjs/utils/mediaQueries.js.map +0 -1
  161. package/lib/module/UnistyleRegistry.js.map +0 -1
  162. package/lib/module/Unistyles.js.map +0 -1
  163. package/lib/module/UnistylesEngine.js +0 -19
  164. package/lib/module/UnistylesEngine.js.map +0 -1
  165. package/lib/module/UnistylesModule.js.map +0 -1
  166. package/lib/module/UnistylesRuntime.js.map +0 -1
  167. package/lib/module/hooks/useDimensions.js +0 -3
  168. package/lib/module/hooks/useDimensions.js.map +0 -1
  169. package/lib/module/hooks/useDimensions.web.js +0 -27
  170. package/lib/module/hooks/useDimensions.web.js.map +0 -1
  171. package/lib/module/types/cxx.js.map +0 -1
  172. package/lib/module/types/mediaQueries.js +0 -2
  173. package/lib/module/useInitialTheme.js +0 -6
  174. package/lib/module/useInitialTheme.js.map +0 -1
  175. package/lib/module/useUnistyles.js +0 -44
  176. package/lib/module/useUnistyles.js.map +0 -1
  177. package/lib/module/utils/mediaQueries.js +0 -85
  178. package/lib/module/utils/mediaQueries.js.map +0 -1
  179. package/lib/typescript/src/UnistyleRegistry.d.ts.map +0 -1
  180. package/lib/typescript/src/Unistyles.d.ts.map +0 -1
  181. package/lib/typescript/src/UnistylesEngine.d.ts +0 -11
  182. package/lib/typescript/src/UnistylesEngine.d.ts.map +0 -1
  183. package/lib/typescript/src/UnistylesModule.d.ts.map +0 -1
  184. package/lib/typescript/src/UnistylesRuntime.d.ts.map +0 -1
  185. package/lib/typescript/src/hooks/useDimensions.d.ts +0 -3
  186. package/lib/typescript/src/hooks/useDimensions.d.ts.map +0 -1
  187. package/lib/typescript/src/hooks/useDimensions.web.d.ts +0 -3
  188. package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +0 -1
  189. package/lib/typescript/src/types/cxx.d.ts.map +0 -1
  190. package/lib/typescript/src/types/mediaQueries.d.ts +0 -10
  191. package/lib/typescript/src/types/mediaQueries.d.ts.map +0 -1
  192. package/lib/typescript/src/useInitialTheme.d.ts +0 -3
  193. package/lib/typescript/src/useInitialTheme.d.ts.map +0 -1
  194. package/lib/typescript/src/useUnistyles.d.ts +0 -10
  195. package/lib/typescript/src/useUnistyles.d.ts.map +0 -1
  196. package/lib/typescript/src/utils/mediaQueries.d.ts +0 -11
  197. package/lib/typescript/src/utils/mediaQueries.d.ts.map +0 -1
  198. package/src/UnistylesEngine.ts +0 -24
  199. package/src/hooks/useDimensions.ts +0 -4
  200. package/src/hooks/useDimensions.web.ts +0 -34
  201. package/src/types/mediaQueries.ts +0 -15
  202. package/src/useInitialTheme.ts +0 -7
  203. package/src/useUnistyles.ts +0 -61
  204. package/src/utils/mediaQueries.ts +0 -152
  205. /package/lib/commonjs/{UnistylesModule.js → core/UnistylesModule.js} +0 -0
  206. /package/lib/module/{UnistylesModule.js → core/UnistylesModule.js} +0 -0
  207. /package/lib/typescript/src/{UnistylesModule.d.ts → core/UnistylesModule.d.ts} +0 -0
  208. /package/src/{UnistylesModule.ts → core/UnistylesModule.ts} +0 -0
@@ -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 = themeName;
129
- this->onThemeChange(themeName);
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 = this->colorScheme;
150
- this->onThemeChange(this->themeName);
151
-
152
- return jsi::Value::undefined();
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
- this->onBreakpointChange(breakpoint, orientation, width, height);
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 = this->colorScheme;
247
- this->onThemeChange(this->themeName);
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) {
@@ -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
- UnistylesThemeChangeEvent onThemeChange;
25
- UnistylesBreakpointChangeEvent onBreakpointChange;
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
- ): onThemeChange(onThemeChange),
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;
@@ -31,7 +31,7 @@ RCT_EXPORT_MODULE(Unistyles)
31
31
 
32
32
  - (void)dealloc {
33
33
  if (self.unistylesRuntime != nullptr) {
34
- delete (UnistylesRuntime*)self.unistylesRuntime;
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
- ((UnistylesRuntime*)self.unistylesRuntime)->handleScreenSizeChange((int)screenWidth, (int)screenHeight);
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
- ((UnistylesRuntime*)self.unistylesRuntime)->handleAppearanceChange(colorScheme);
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
- UnistylesThemeChangeEvent onThemeChange = ^(std::string theme) {
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
- UnistylesBreakpointChangeEvent onBreakpointChange = ^(std::string breakpoint, int orientation, int width, int height) {
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=cxx.js.map
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 _types = require("./types");
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(_types.UnistylesError.RuntimeUnavailable);
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 _types = require("./types");
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 _types.ScreenOrientation.Landscape;
40
+ return _common.ScreenOrientation.Landscape;
41
41
  }
42
- return _types.ScreenOrientation.Portrait;
42
+ return _common.ScreenOrientation.Portrait;
43
43
  }
44
44
  setTheme = name => {
45
- if (name !== this.themeName && this.hasTheme(name)) {
45
+ if (this.hasTheme(name)) {
46
46
  this.unistylesBridge.useTheme(name);
47
47
  return true;
48
48
  }
49
- throw new Error(_types.UnistylesError.ThemeNotRegistered);
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(_types.UnistylesError.ThemeNotFound);
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, "useDimensions", {
6
+ Object.defineProperty(exports, "useInitialTheme", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _useDimensions.useDimensions;
9
+ return _useInitialTheme.useInitialTheme;
10
10
  }
11
11
  });
12
- var _useDimensions = require("./useDimensions");
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":["_useDimensions","require"],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA"}
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 _Unistyles = require("./Unistyles");
8
+ var _core = require("../core");
9
9
  const useInitialTheme = forName => {
10
- (0, _react.useMemo)(() => _Unistyles.unistyles.runtime.setTheme(forName), []);
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"}
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "ScreenOrientation", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _types.ScreenOrientation;
9
+ return _common.ScreenOrientation;
10
10
  }
11
11
  });
12
- exports.__dangerouslyUnregister = exports.UnistylesRuntime = exports.UnistylesRegistry = void 0;
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 _useInitialTheme.useInitialTheme;
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 _Unistyles = require("./Unistyles");
38
- var _types = require("./types");
37
+ var _core = require("./core");
39
38
  var _utils = require("./utils");
40
- var _useInitialTheme = require("./useInitialTheme");
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 __dangerouslyUnregister = exports.__dangerouslyUnregister = _Unistyles.unistyles.registry.dangerouslyUnregister;
48
+ const UnistylesRuntime = exports.UnistylesRuntime = _core.unistyles.runtime;
55
49
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_Unistyles","require","_types","_utils","_useInitialTheme","_useStyles","_createStyleSheet","addThemes","addBreakpoints","addConfig","unistyles","registry","UnistylesRuntime","exports","runtime","UnistylesRegistry","__dangerouslyUnregister","dangerouslyUnregister"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AAEA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AAEA,MAAM;EAAEM,SAAS;EAAEC,cAAc;EAAEC;AAAW,CAAC,GAAGC,oBAAS,CAACC,QAAQ;AACpE,MAAMC,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,GAAGF,oBAAS,CAACI,OAAO;AAC1C,MAAMC,iBAAiB,GAAAF,OAAA,CAAAE,iBAAA,GAAG;EACtBR,SAAS;EACTC,cAAc;EACdC;AACJ,CAAC;AAEM,MAAMO,uBAAuB,GAAAH,OAAA,CAAAG,uBAAA,GAAGN,oBAAS,CAACC,QAAQ,CAACM,qBAAqB"}
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"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=common.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/mediaQueries.ts"],"mappings":""}
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 _cxx = require("./cxx");
18
- Object.keys(_cxx).forEach(function (key) {
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] === _cxx[key]) return;
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 _cxx[key];
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","_cxx"],"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,IAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,IAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,IAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,IAAA,CAAAL,GAAA;IAAA;EAAA;AAAA"}
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"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=mq.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/mediaQueries.ts"],"mappings":""}
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/mq.ts"],"mappings":""}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=unistyles.js.map