react-native-unistyles 3.0.0-nightly-20250129 → 3.0.0-nightly-20250131

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +14 -2
  2. package/components/native/NativeText/package.json +5 -0
  3. package/components/native/NativeView/package.json +5 -0
  4. package/cxx/core/Unistyle.h +4 -0
  5. package/cxx/core/UnistylesRegistry.h +2 -0
  6. package/cxx/hybridObjects/HybridStyleSheet.cpp +27 -2
  7. package/cxx/parser/Parser.cpp +10 -4
  8. package/ios/NativePlatform+ios.swift +16 -4
  9. package/lib/commonjs/components/native/NativeText.js +13 -0
  10. package/lib/commonjs/components/native/NativeText.js.map +1 -0
  11. package/lib/commonjs/components/native/NativeText.native.js +18 -0
  12. package/lib/commonjs/components/native/NativeText.native.js.map +1 -0
  13. package/lib/commonjs/components/native/NativeView.js +9 -0
  14. package/lib/commonjs/components/native/NativeView.js.map +1 -0
  15. package/lib/commonjs/components/native/NativeView.native.js +20 -0
  16. package/lib/commonjs/components/native/NativeView.native.js.map +1 -0
  17. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  18. package/lib/module/components/native/NativeText.js +4 -0
  19. package/lib/module/components/native/NativeText.js.map +1 -0
  20. package/lib/module/components/native/NativeText.native.js +15 -0
  21. package/lib/module/components/native/NativeText.native.js.map +1 -0
  22. package/lib/module/components/native/NativeView.js +5 -0
  23. package/lib/module/components/native/NativeView.js.map +1 -0
  24. package/lib/module/components/native/NativeView.native.js +17 -0
  25. package/lib/module/components/native/NativeView.native.js.map +1 -0
  26. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  27. package/lib/typescript/src/components/native/NativeText.d.ts +2 -0
  28. package/lib/typescript/src/components/native/NativeText.d.ts.map +1 -0
  29. package/lib/typescript/src/components/native/NativeText.native.d.ts +2 -0
  30. package/lib/typescript/src/components/native/NativeText.native.d.ts.map +1 -0
  31. package/lib/typescript/src/components/native/NativeView.d.ts +3 -0
  32. package/lib/typescript/src/components/native/NativeView.d.ts.map +1 -0
  33. package/lib/typescript/src/components/native/NativeView.native.d.ts +3 -0
  34. package/lib/typescript/src/components/native/NativeView.native.d.ts.map +1 -0
  35. package/lib/typescript/src/specs/StyleSheet/index.d.ts +1 -0
  36. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  37. package/package.json +7 -7
  38. package/plugin/consts.js +21 -1
  39. package/plugin/exotic.js +23 -11
  40. package/plugin/index.d.ts +79 -33
  41. package/plugin/index.js +14 -2
  42. package/plugin/stylesheet.js +12 -1
  43. package/src/components/native/NativeText.native.tsx +12 -0
  44. package/src/components/native/NativeText.tsx +1 -0
  45. package/src/components/native/NativeView.native.tsx +13 -0
  46. package/src/components/native/NativeView.tsx +3 -0
  47. package/src/specs/StyleSheet/index.ts +2 -1
package/README.md CHANGED
@@ -47,6 +47,9 @@ Then follow [installation guides](https://unistyl.es/v3/start/getting-started) f
47
47
  <a href="https://galaxies.dev">
48
48
  <img src="https://avatars.githubusercontent.com/u/118431096?s=200&v=4" height="70px" width="70px" alt="galaxies-dev" />
49
49
  </a>
50
+ <a href="https://github.com/FTCHD">
51
+ <img src="https://avatars.githubusercontent.com/u/144691102?v=4" height="70px" width="70px" alt="FTCHD" />
52
+ </a>
50
53
  <a href="https://github.com/mobily">
51
54
  <img src="https://avatars.githubusercontent.com/u/1467712?v=4" height="70px" width="70px" alt="mobily" />
52
55
  </a>
@@ -62,8 +65,14 @@ Then follow [installation guides](https://unistyl.es/v3/start/getting-started) f
62
65
  <a href="https://github.com/oscklm">
63
66
  <img src="https://avatars.githubusercontent.com/u/22825865?v=4" height="70px" width="70px" alt="oscklm" />
64
67
  </a>
65
- <a href="https://github.com/giovannilondero">
66
- <img src="https://avatars.githubusercontent.com/u/10998991?v=4" height="70px" width="70px" alt="giovannilondero" />
68
+ <a href="https://github.com/guillaumehcht">
69
+ <img src="https://avatars.githubusercontent.com/u/80776475?v=4" height="70px" width="70px" alt="guillaumehcht" />
70
+ </a>
71
+ <a href="https://github.com/FilipiRafael">
72
+ <img src="https://avatars.githubusercontent.com/u/61629642?v=4" height="70px" width="70px" alt="FilipiRafael" />
73
+ </a>
74
+ <a href="https://github.com/4cc3ssX">
75
+ <img src="https://avatars.githubusercontent.com/u/57473799?v=4" height="70px" width="70px" alt="4cc3ssX" />
67
76
  </a>
68
77
 
69
78
  ## Past sponsors
@@ -89,6 +98,9 @@ Then follow [installation guides](https://unistyl.es/v3/start/getting-started) f
89
98
  <a href="https://github.com/hyoban">
90
99
  <img src="https://avatars.githubusercontent.com/u/38493346?v=4" height="70px" width="70px" alt="hyoban" />
91
100
  </a>
101
+ <a href="https://github.com/giovannilondero">
102
+ <img src="https://avatars.githubusercontent.com/u/10998991?v=4" height="70px" width="70px" alt="giovannilondero" />
103
+ </a>
92
104
 
93
105
  ## Sponsor my work
94
106
 
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "../../../lib/commonjs/components/native/NativeText.js",
3
+ "module": "../../../lib/module/components/native/NativeText.js",
4
+ "react-native": "../../../src/components/native/NativeText.native.tsx"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "../../../lib/commonjs/components/native/NativeView.js",
3
+ "module": "../../../lib/module/components/native/NativeView.js",
4
+ "react-native": "../../../src/components/native/NativeView.native.tsx"
5
+ }
@@ -54,6 +54,10 @@ struct Unistyle {
54
54
  inline bool dependsOn(UnistyleDependency dependency) {
55
55
  return std::find(this->dependencies.begin(), this->dependencies.end(), dependency) != this->dependencies.end();
56
56
  }
57
+
58
+ inline bool isSealed() {
59
+ return this->_isSealed;
60
+ }
57
61
 
58
62
  inline void seal() {
59
63
  this->_isSealed = true;
@@ -27,6 +27,8 @@ struct UnistylesRegistry: public StyleSheetRegistry {
27
27
 
28
28
  UnistylesRegistry(const UnistylesRegistry&) = delete;
29
29
  UnistylesRegistry(const UnistylesRegistry&&) = delete;
30
+
31
+ bool shouldUsePointsForBreakpoints = false;
30
32
 
31
33
  void registerTheme(jsi::Runtime& rt, std::string name, jsi::Value& theme);
32
34
  void registerBreakpoints(jsi::Runtime& rt, std::vector<std::pair<std::string, double>>& sortedBreakpoints);
@@ -127,6 +127,20 @@ void HybridStyleSheet::parseSettings(jsi::Runtime &rt, jsi::Object settings) {
127
127
  if (propertyName == "CSSVars") {
128
128
  return;
129
129
  }
130
+
131
+ if (propertyName == "nativeBreakpointsMode") {
132
+ helpers::assertThat(rt, propertyValue.isString(), "StyleSheet.configure's nativeBreakpointsMode must be a string");
133
+
134
+ auto mode = propertyValue.asString(rt).utf8(rt);
135
+
136
+ helpers::assertThat(rt, mode == "pixels" || mode == "points", "StyleSheet.configure's nativeBreakpointsMode must be one of: pixels or points");
137
+
138
+ if (mode == "points") {
139
+ registry.shouldUsePointsForBreakpoints = true;
140
+ }
141
+
142
+ return;
143
+ }
130
144
 
131
145
  helpers::assertThat(rt, false, "StyleSheet.configure's settings received unexpected key: '" + std::string(propertyName) + "'");
132
146
  });
@@ -142,7 +156,13 @@ void HybridStyleSheet::parseBreakpoints(jsi::Runtime &rt, jsi::Object breakpoint
142
156
  auto& state = registry.getState(rt);
143
157
 
144
158
  registry.registerBreakpoints(rt, sortedBreakpoints);
145
- state.computeCurrentBreakpoint(this->_unistylesRuntime->getScreen().width);
159
+
160
+ auto rawWidth = this->_unistylesRuntime->getScreen().width;
161
+ auto width = registry.shouldUsePointsForBreakpoints
162
+ ? rawWidth / this->_unistylesRuntime->getPixelRatio()
163
+ : rawWidth;
164
+
165
+ state.computeCurrentBreakpoint(width);
146
166
  }
147
167
 
148
168
  void HybridStyleSheet::parseThemes(jsi::Runtime &rt, jsi::Object themes) {
@@ -293,7 +313,12 @@ void HybridStyleSheet::onPlatformNativeDependenciesChange(std::vector<UnistyleDe
293
313
  auto dimensionsIt = std::find(dependencies.begin(), dependencies.end(), UnistyleDependency::DIMENSIONS);
294
314
 
295
315
  if (dimensionsIt != dependencies.end()) {
296
- registry.getState(rt).computeCurrentBreakpoint(this->_unistylesRuntime->getScreen().width);
316
+ auto rawWidth = this->_unistylesRuntime->getScreen().width;
317
+ auto width = registry.shouldUsePointsForBreakpoints
318
+ ? rawWidth / this->_unistylesRuntime->getPixelRatio()
319
+ : rawWidth;
320
+
321
+ registry.getState(rt).computeCurrentBreakpoint(width);
297
322
  }
298
323
 
299
324
  // check if color scheme changed and then if Unistyles state depend on it (adaptive themes)
@@ -399,8 +399,10 @@ jsi::Object parser::Parser::parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared u
399
399
 
400
400
  helpers::enumerateJSIObject(rt, style, [&](const std::string& propertyName, jsi::Value& propertyValue){
401
401
  // parse dependencies only once
402
- if (propertyName == helpers::STYLE_DEPENDENCIES && unistyle->dependencies.empty()) {
403
- unistyle->dependencies = this->parseDependencies(rt, propertyValue.asObject(rt));
402
+ if (propertyName == helpers::STYLE_DEPENDENCIES && !unistyle->isSealed()) {
403
+ auto newDeps = this->parseDependencies(rt, propertyValue.asObject(rt));
404
+
405
+ unistyle->dependencies.insert(unistyle->dependencies.end(), newDeps.begin(), newDeps.end());
404
406
 
405
407
  return;
406
408
  }
@@ -524,7 +526,7 @@ jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unist
524
526
 
525
527
  Variants variants = helpers::variantsToPairs(rt, rawVariants.asObject(rt));
526
528
 
527
- unistyleFn->parsedStyle = this->parseFirstLevel(rt, unistyleFn, variants);
529
+ unistyleFn->parsedStyle = parser.parseFirstLevel(rt, unistyleFn, variants);
528
530
  unistyleFn->seal();
529
531
 
530
532
  // for compatibility purpose save last arguments to style instance. It will work ok, if user sees warning about multiple unistyles
@@ -651,7 +653,11 @@ jsi::Value parser::Parser::getValueFromBreakpoints(jsi::Runtime& rt, Unistyle::S
651
653
  auto sortedBreakpoints = state.getSortedBreakpointPairs();
652
654
  auto hasBreakpoints = !sortedBreakpoints.empty();
653
655
  auto currentBreakpoint = state.getCurrentBreakpointName();
654
- auto dimensions = this->_unistylesRuntime->getScreen();
656
+ auto rawDimensions = this->_unistylesRuntime->getScreen();
657
+ auto pixelRatio = this->_unistylesRuntime->getPixelRatio();
658
+ auto dimensions = registry.shouldUsePointsForBreakpoints
659
+ ? Dimensions(rawDimensions.width / pixelRatio, rawDimensions.height / pixelRatio)
660
+ : rawDimensions;
655
661
  auto currentOrientation = dimensions.width > dimensions.height
656
662
  ? "landscape"
657
663
  : "portrait";
@@ -114,6 +114,12 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
114
114
  func getScreenDimensionsFn() -> Dimensions {
115
115
  guard let presentedViewController = RCTPresentedViewController(),
116
116
  let windowFrame = presentedViewController.view.window?.frame else {
117
+
118
+ // when user goes to background RCTPresentedViewController is not available, try to get last known value
119
+ if let cachedRuntime = self.miniRuntime, UIApplication.shared.applicationState == .background {
120
+ return cachedRuntime.screen;
121
+ }
122
+
117
123
  // this should never happen, but it's better to return zeros
118
124
  return Dimensions(width: 0, height: 0)
119
125
  }
@@ -137,10 +143,10 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
137
143
  let screenDimensions = getScreenDimensions()
138
144
 
139
145
  if (screenDimensions.width > screenDimensions.height) {
140
- return Orientation.landscape;
146
+ return Orientation.landscape
141
147
  }
142
148
 
143
- return Orientation.portrait;
149
+ return Orientation.portrait
144
150
  }
145
151
 
146
152
  func getContentSizeCategory() -> String {
@@ -268,8 +274,14 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
268
274
  func getPixelRatioFn() -> Double {
269
275
  guard let presentedViewController = RCTPresentedViewController(),
270
276
  let window = presentedViewController.view.window else {
277
+
278
+ // when user goes to background RCTPresentedViewController is not available, try to get last known value
279
+ if let cachedRuntime = self.miniRuntime, UIApplication.shared.applicationState == .background {
280
+ return cachedRuntime.pixelRatio;
281
+ }
282
+
271
283
  // this should never happen, but it's better to return default
272
- return 1;
284
+ return 1
273
285
  }
274
286
 
275
287
  return window.screen.scale
@@ -297,7 +309,7 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
297
309
  }
298
310
 
299
311
  func getNavigationBarDimensions() -> Dimensions {
300
- return Dimensions(width: 0, height: 0);
312
+ return Dimensions(width: 0, height: 0)
301
313
  }
302
314
 
303
315
  func setStatusBarHidden(isHidden: Bool) throws {
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Text", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _Text.Text;
10
+ }
11
+ });
12
+ var _Text = require("./Text");
13
+ //# sourceMappingURL=NativeText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_Text","require"],"sourceRoot":"../../../../src","sources":["components/native/NativeText.tsx"],"mappings":";;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NativeText = void 0;
7
+ var _react = require("react");
8
+ var _core = require("../../core");
9
+ // credits to @hirbod
10
+ const LeanText = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
11
+ return /*#__PURE__*/(0, _react.createElement)('RCTText', {
12
+ ...props,
13
+ ref
14
+ });
15
+ });
16
+ LeanText.displayName = 'RCTText';
17
+ const NativeText = exports.NativeText = (0, _core.createUnistylesElement)(LeanText);
18
+ //# sourceMappingURL=NativeText.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_core","LeanText","forwardRef","props","ref","createElement","displayName","NativeText","exports","createUnistylesElement"],"sourceRoot":"../../../../src","sources":["components/native/NativeText.native.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA;AACA,MAAME,QAAQ,gBAAG,IAAAC,iBAAU,EAAC,CAACC,KAAK,EAAEC,GAAG,KAAK;EACxC,oBAAO,IAAAC,oBAAa,EAAC,SAAS,EAAE;IAAE,GAAGF,KAAK;IAAEC;EAAI,CAAC,CAAC;AACtD,CAAC,CAA6B;AAE9BH,QAAQ,CAACK,WAAW,GAAG,SAAS;AAEzB,MAAMC,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAG,IAAAE,4BAAsB,EAACR,QAAQ,CAAC","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _View = require("./View");
8
+ var _default = exports.default = _View.View;
9
+ //# sourceMappingURL=NativeView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_View","require","_default","exports","default","View"],"sourceRoot":"../../../../src","sources":["components/native/NativeView.tsx"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAA6B,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEdC,UAAI","ignoreList":[]}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = require("react");
8
+ var _core = require("../../core");
9
+ // credits to @hirbod
10
+ const LeanView = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
11
+ return /*#__PURE__*/(0, _react.createElement)('RCTView', {
12
+ ...props,
13
+ ref
14
+ });
15
+ });
16
+ LeanView.displayName = 'RCTView';
17
+
18
+ // this will match default export from react-native
19
+ var _default = exports.default = (0, _core.createUnistylesElement)(LeanView);
20
+ //# sourceMappingURL=NativeView.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_core","LeanView","forwardRef","props","ref","createElement","displayName","_default","exports","default","createUnistylesElement"],"sourceRoot":"../../../../src","sources":["components/native/NativeView.native.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA;AACA,MAAME,QAAQ,gBAAG,IAAAC,iBAAU,EAAC,CAACC,KAAK,EAAEC,GAAG,KAAK;EACxC,oBAAO,IAAAC,oBAAa,EAAC,SAAS,EAAE;IAAE,GAAGF,KAAK;IAAEC;EAAI,CAAC,CAAC;AACtD,CAAC,CAA6B;AAE9BH,QAAQ,CAACK,WAAW,GAAG,SAAS;;AAEhC;AAAA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GACe,IAAAC,4BAAsB,EAACT,QAAQ,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNativeNitroModules","require","_reactNative","HybridUnistylesStyleSheet","NitroModules","createHybridObject","absoluteFillObject","NativeStyleSheet","absoluteFill","flatten","compose","jsMethods","processColor","init","StyleSheet","exports"],"sourceRoot":"../../../../src","sources":["specs/StyleSheet/index.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAqCA,MAAME,yBAAyB,GAAGC,qCAAY,CACzCC,kBAAkB,CAAsB,qBAAqB,CAAC;AAEnEF,yBAAyB,CAACG,kBAAkB,GAAGC,uBAAgB,CAACD,kBAAkB;AAClFH,yBAAyB,CAACK,YAAY,GAAGD,uBAAgB,CAACC,YAAY;AACtEL,yBAAyB,CAACM,OAAO,GAAGF,uBAAgB,CAACE,OAAO;AAC5DN,yBAAyB,CAACO,OAAO,GAAGH,uBAAgB,CAACG,OAAO;AAC5DP,yBAAyB,CAACQ,SAAS,GAAG;EAClCC,YAAY,EAAZA;AACJ,CAAC;AAEDT,yBAAyB,CAACU,IAAI,CAAC,CAAC;AAIzB,MAAMC,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAGX,yBAAsE","ignoreList":[]}
1
+ {"version":3,"names":["_reactNativeNitroModules","require","_reactNative","HybridUnistylesStyleSheet","NitroModules","createHybridObject","absoluteFillObject","NativeStyleSheet","absoluteFill","flatten","compose","jsMethods","processColor","init","StyleSheet","exports"],"sourceRoot":"../../../../src","sources":["specs/StyleSheet/index.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAsCA,MAAME,yBAAyB,GAAGC,qCAAY,CACzCC,kBAAkB,CAAsB,qBAAqB,CAAC;AAEnEF,yBAAyB,CAACG,kBAAkB,GAAGC,uBAAgB,CAACD,kBAAkB;AAClFH,yBAAyB,CAACK,YAAY,GAAGD,uBAAgB,CAACC,YAAY;AACtEL,yBAAyB,CAACM,OAAO,GAAGF,uBAAgB,CAACE,OAAO;AAC5DN,yBAAyB,CAACO,OAAO,GAAGH,uBAAgB,CAACG,OAAO;AAC5DP,yBAAyB,CAACQ,SAAS,GAAG;EAClCC,YAAY,EAAZA;AACJ,CAAC;AAEDT,yBAAyB,CAACU,IAAI,CAAC,CAAC;AAIzB,MAAMC,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAGX,yBAAsE","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export { Text } from './Text';
4
+ //# sourceMappingURL=NativeText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Text"],"sourceRoot":"../../../../src","sources":["components/native/NativeText.tsx"],"mappings":";;AAAA,SAASA,IAAI,QAAQ,QAAQ","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ import { createElement, forwardRef } from 'react';
4
+ import { createUnistylesElement } from '../../core';
5
+
6
+ // credits to @hirbod
7
+ const LeanText = /*#__PURE__*/forwardRef((props, ref) => {
8
+ return /*#__PURE__*/createElement('RCTText', {
9
+ ...props,
10
+ ref
11
+ });
12
+ });
13
+ LeanText.displayName = 'RCTText';
14
+ export const NativeText = createUnistylesElement(LeanText);
15
+ //# sourceMappingURL=NativeText.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createElement","forwardRef","createUnistylesElement","LeanText","props","ref","displayName","NativeText"],"sourceRoot":"../../../../src","sources":["components/native/NativeText.native.tsx"],"mappings":";;AACA,SAA6BA,aAAa,EAAEC,UAAU,QAAQ,OAAO;AACrE,SAASC,sBAAsB,QAAQ,YAAY;;AAEnD;AACA,MAAMC,QAAQ,gBAAGF,UAAU,CAAC,CAACG,KAAK,EAAEC,GAAG,KAAK;EACxC,oBAAOL,aAAa,CAAC,SAAS,EAAE;IAAE,GAAGI,KAAK;IAAEC;EAAI,CAAC,CAAC;AACtD,CAAC,CAA6B;AAE9BF,QAAQ,CAACG,WAAW,GAAG,SAAS;AAEhC,OAAO,MAAMC,UAAU,GAAGL,sBAAsB,CAACC,QAAQ,CAAC","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ import { View } from './View';
4
+ export default View;
5
+ //# sourceMappingURL=NativeView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["View"],"sourceRoot":"../../../../src","sources":["components/native/NativeView.tsx"],"mappings":";;AAAA,SAASA,IAAI,QAAQ,QAAQ;AAE7B,eAAeA,IAAI","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ import { createElement, forwardRef } from 'react';
4
+ import { createUnistylesElement } from '../../core';
5
+
6
+ // credits to @hirbod
7
+ const LeanView = /*#__PURE__*/forwardRef((props, ref) => {
8
+ return /*#__PURE__*/createElement('RCTView', {
9
+ ...props,
10
+ ref
11
+ });
12
+ });
13
+ LeanView.displayName = 'RCTView';
14
+
15
+ // this will match default export from react-native
16
+ export default createUnistylesElement(LeanView);
17
+ //# sourceMappingURL=NativeView.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createElement","forwardRef","createUnistylesElement","LeanView","props","ref","displayName"],"sourceRoot":"../../../../src","sources":["components/native/NativeView.native.tsx"],"mappings":";;AACA,SAA6BA,aAAa,EAAEC,UAAU,QAAQ,OAAO;AACrE,SAASC,sBAAsB,QAAQ,YAAY;;AAEnD;AACA,MAAMC,QAAQ,gBAAGF,UAAU,CAAC,CAACG,KAAK,EAAEC,GAAG,KAAK;EACxC,oBAAOL,aAAa,CAAC,SAAS,EAAE;IAAE,GAAGI,KAAK;IAAEC;EAAI,CAAC,CAAC;AACtD,CAAC,CAA6B;AAE9BF,QAAQ,CAACG,WAAW,GAAG,SAAS;;AAEhC;AACA,eAAeJ,sBAAsB,CAACC,QAAQ,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["NitroModules","processColor","StyleSheet","NativeStyleSheet","HybridUnistylesStyleSheet","createHybridObject","absoluteFillObject","absoluteFill","flatten","compose","jsMethods","init"],"sourceRoot":"../../../../src","sources":["specs/StyleSheet/index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AACzD,SAASC,YAAY,EAAEC,UAAU,IAAIC,gBAAgB,QAAQ,cAAc;AAqC3E,MAAMC,yBAAyB,GAAGJ,YAAY,CACzCK,kBAAkB,CAAsB,qBAAqB,CAAC;AAEnED,yBAAyB,CAACE,kBAAkB,GAAGH,gBAAgB,CAACG,kBAAkB;AAClFF,yBAAyB,CAACG,YAAY,GAAGJ,gBAAgB,CAACI,YAAY;AACtEH,yBAAyB,CAACI,OAAO,GAAGL,gBAAgB,CAACK,OAAO;AAC5DJ,yBAAyB,CAACK,OAAO,GAAGN,gBAAgB,CAACM,OAAO;AAC5DL,yBAAyB,CAACM,SAAS,GAAG;EAClCT;AACJ,CAAC;AAEDG,yBAAyB,CAACO,IAAI,CAAC,CAAC;AAIhC,OAAO,MAAMT,UAAU,GAAGE,yBAAsE","ignoreList":[]}
1
+ {"version":3,"names":["NitroModules","processColor","StyleSheet","NativeStyleSheet","HybridUnistylesStyleSheet","createHybridObject","absoluteFillObject","absoluteFill","flatten","compose","jsMethods","init"],"sourceRoot":"../../../../src","sources":["specs/StyleSheet/index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AACzD,SAASC,YAAY,EAAEC,UAAU,IAAIC,gBAAgB,QAAQ,cAAc;AAsC3E,MAAMC,yBAAyB,GAAGJ,YAAY,CACzCK,kBAAkB,CAAsB,qBAAqB,CAAC;AAEnED,yBAAyB,CAACE,kBAAkB,GAAGH,gBAAgB,CAACG,kBAAkB;AAClFF,yBAAyB,CAACG,YAAY,GAAGJ,gBAAgB,CAACI,YAAY;AACtEH,yBAAyB,CAACI,OAAO,GAAGL,gBAAgB,CAACK,OAAO;AAC5DJ,yBAAyB,CAACK,OAAO,GAAGN,gBAAgB,CAACM,OAAO;AAC5DL,yBAAyB,CAACM,SAAS,GAAG;EAClCT;AACJ,CAAC;AAEDG,yBAAyB,CAACO,IAAI,CAAC,CAAC;AAIhC,OAAO,MAAMT,UAAU,GAAGE,yBAAsE","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export { Text } from './Text';
2
+ //# sourceMappingURL=NativeText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeText.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/NativeText.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const NativeText: any;
2
+ //# sourceMappingURL=NativeText.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeText.native.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/NativeText.native.tsx"],"names":[],"mappings":"AAWA,eAAO,MAAM,UAAU,KAAmC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { View } from './View';
2
+ export default View;
3
+ //# sourceMappingURL=NativeView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeView.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/NativeView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAE7B,eAAe,IAAI,CAAA"}
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+ export default _default;
3
+ //# sourceMappingURL=NativeView.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeView.native.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/NativeView.native.tsx"],"names":[],"mappings":";AAYA,wBAA+C"}
@@ -10,6 +10,7 @@ type UnistylesThemeSettings = {
10
10
  };
11
11
  type UnistylesSettings = UnistylesThemeSettings & {
12
12
  CSSVars?: boolean;
13
+ nativeBreakpointsMode?: 'pixels' | 'points';
13
14
  };
14
15
  export type UnistylesConfig = {
15
16
  settings?: UnistylesSettings;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/specs/StyleSheet/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAkC,MAAM,cAAc,CAAA;AAC3E,OAAO,KAAK,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACtE,OAAO,KAAK,EAAE,mBAAmB,IAAI,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AACjG,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAE5D,KAAK,sBAAsB,GAAG;IAC1B,YAAY,EAAE,CAAC,MAAM,MAAM,eAAe,CAAC,GAAG,MAAM,eAAe,CAAA;CACtE,GAAG;IACA,cAAc,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,KAAK,iBAAiB,GAAG,sBAAsB,GAAG;IAC9C,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC1B,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,WAAW,CAAC,EAAE,oBAAoB,CAAA;CACrC,CAAA;AAED,MAAM,WAAW,mBAAoB,SAAQ,uBAAuB;IAChE,kBAAkB,EAAE,OAAO,oBAAoB,CAAC,kBAAkB,CAAC;IACnE,YAAY,EAAE,OAAO,oBAAoB,CAAC,YAAY,CAAC;IACvD,OAAO,EAAE,OAAO,oBAAoB,CAAC,OAAO,CAAC;IAC7C,OAAO,EAAE,OAAO,oBAAoB,CAAC,OAAO,CAAC;IAG7C,IAAI,IAAI,IAAI,CAAC;IACb,MAAM,EAAE,yBAAyB,CAAC;IAClC,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IACzC,SAAS,EAAE;QACP,YAAY,EAAE,OAAO,YAAY,CAAA;KACpC,CAAA;CACJ;AAeD,KAAK,cAAc,GAAG,WAAW,GAAG,mBAAmB,GAAG,MAAM,CAAA;AAEhE,eAAO,MAAM,UAAU,EAAgC,IAAI,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/specs/StyleSheet/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAkC,MAAM,cAAc,CAAA;AAC3E,OAAO,KAAK,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACtE,OAAO,KAAK,EAAE,mBAAmB,IAAI,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AACjG,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAE5D,KAAK,sBAAsB,GAAG;IAC1B,YAAY,EAAE,CAAC,MAAM,MAAM,eAAe,CAAC,GAAG,MAAM,eAAe,CAAA;CACtE,GAAG;IACA,cAAc,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,KAAK,iBAAiB,GAAG,sBAAsB,GAAG;IAC9C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,qBAAqB,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAA;CAC9C,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC1B,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,WAAW,CAAC,EAAE,oBAAoB,CAAA;CACrC,CAAA;AAED,MAAM,WAAW,mBAAoB,SAAQ,uBAAuB;IAChE,kBAAkB,EAAE,OAAO,oBAAoB,CAAC,kBAAkB,CAAC;IACnE,YAAY,EAAE,OAAO,oBAAoB,CAAC,YAAY,CAAC;IACvD,OAAO,EAAE,OAAO,oBAAoB,CAAC,OAAO,CAAC;IAC7C,OAAO,EAAE,OAAO,oBAAoB,CAAC,OAAO,CAAC;IAG7C,IAAI,IAAI,IAAI,CAAC;IACb,MAAM,EAAE,yBAAyB,CAAC;IAClC,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IACzC,SAAS,EAAE;QACP,YAAY,EAAE,OAAO,YAAY,CAAA;KACpC,CAAA;CACJ;AAeD,KAAK,cAAc,GAAG,WAAW,GAAG,mBAAmB,GAAG,MAAM,CAAA;AAEhE,eAAO,MAAM,UAAU,EAAgC,IAAI,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.0.0-nightly-20250129",
3
+ "version": "3.0.0-nightly-20250131",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -11,15 +11,15 @@
11
11
  "precommit": "concurrently 'yarn tsc' 'yarn lint' 'yarn test'",
12
12
  "release": "release-it"
13
13
  },
14
- "main": "lib/commonjs/index",
15
- "module": "lib/module/index",
14
+ "main": "lib/commonjs/index.js",
15
+ "module": "lib/module/index.js",
16
16
  "types": "lib/typescript/src/index.d.ts",
17
17
  "source": "src/index",
18
18
  "exports": {
19
19
  ".": {
20
20
  "types": "./lib/typescript/src/index.d.ts",
21
- "module": "./lib/module/index",
22
- "default": "./lib/commonjs/index",
21
+ "module": "./lib/module/index.js",
22
+ "default": "./lib/commonjs/index.js",
23
23
  "react-native": "./src/index"
24
24
  },
25
25
  "./components/native/*": {
@@ -34,8 +34,8 @@
34
34
  "./package.json": "./package.json",
35
35
  "./server": {
36
36
  "types": "./lib/typescript/src/server/index.d.ts",
37
- "module": "./lib/module/server/index",
38
- "default": "./lib/commonjs/server/index",
37
+ "module": "./lib/module/server/index.js",
38
+ "default": "./lib/commonjs/server/index.js",
39
39
  "react-native": "./src/server"
40
40
  }
41
41
  },
package/plugin/consts.js CHANGED
@@ -30,13 +30,33 @@ const REPLACE_WITH_UNISTYLES_PATHS = [
30
30
 
31
31
  // this is more powerful API as it allows to convert unmatched imports to Unistyles
32
32
  // { path: string, imports: Array<{ name: string, isDefault: boolean, path: string, mapTo: string }> }
33
- // name <- target import name
33
+ // path => node_modules path
34
+ // imports:
35
+ // name? <- target import name if isDefault is false
34
36
  // isDefault <- is the import default?
35
37
  // path <- path to the target import
36
38
  // mapTo <- name of the Unistyles component
37
39
  const REPLACE_WITH_UNISTYLES_EXOTIC_PATHS = []
38
40
 
41
+ // this list will additionally detect React Native direct imports
42
+ const NATIVE_COMPONENTS_PATHS = {
43
+ imports: [
44
+ {
45
+ name: 'NativeText',
46
+ isDefault: false,
47
+ path: 'react-native/Libraries/Text/TextNativeComponent',
48
+ mapTo: 'NativeText'
49
+ },
50
+ {
51
+ isDefault: true,
52
+ path: 'react-native/Libraries/Components/View/ViewNativeComponent',
53
+ mapTo: 'NativeView'
54
+ }
55
+ ]
56
+ }
57
+
39
58
  module.exports = {
59
+ NATIVE_COMPONENTS_PATHS,
40
60
  REACT_NATIVE_COMPONENT_NAMES,
41
61
  REPLACE_WITH_UNISTYLES_PATHS,
42
62
  REPLACE_WITH_UNISTYLES_EXOTIC_PATHS
package/plugin/exotic.js CHANGED
@@ -8,28 +8,40 @@ function handleExoticImport(t, path, state, exoticImport) {
8
8
 
9
9
  specifiers.forEach(specifier => {
10
10
  for (const rule of exoticImport.imports) {
11
- const hasMatchingImportType = !rule.isDefault || t.isImportDefaultSpecifier(specifier)
12
- const hasMatchingImportName = rule.name === specifier.local.name
11
+ const hasMatchingImportType = (!rule.isDefault && t.isImportSpecifier(specifier)) || (rule.isDefault && t.isImportDefaultSpecifier(specifier))
12
+ const hasMatchingImportName = rule.isDefault || (!rule.isDefault && rule.name === specifier.local.name)
13
13
  const hasMatchingPath = rule.path === source.value
14
14
 
15
15
  if (!hasMatchingImportType || !hasMatchingImportName || !hasMatchingPath) {
16
16
  continue
17
17
  }
18
18
 
19
- const newImport = t.importDeclaration(
20
- [t.importSpecifier(t.identifier(rule.mapTo), t.identifier(rule.mapTo))],
21
- t.stringLiteral(state.opts.isLocal
22
- ? state.file.opts.filename.split('react-native-unistyles').at(0).concat(`react-native-unistyles/components/native/${rule.mapTo}`)
23
- : `react-native-unistyles/components/native/${rule.mapTo}`
19
+ if (t.isImportDefaultSpecifier(specifier)) {
20
+ const newImport = t.importDeclaration(
21
+ [t.importDefaultSpecifier(t.identifier(specifier.local.name))],
22
+ t.stringLiteral(state.opts.isLocal
23
+ ? state.file.opts.filename.split('react-native-unistyles').at(0).concat(`react-native-unistyles/components/native/${rule.mapTo}`)
24
+ : `react-native-unistyles/components/native/${rule.mapTo}`
25
+ )
24
26
  )
25
- )
26
27
 
27
- // remove old import
28
- if (t.isImportDefaultSpecifier(specifier)) {
29
28
  path.replaceWith(newImport)
30
29
  } else {
30
+ const newImport = t.importDeclaration(
31
+ [t.importSpecifier(t.identifier(rule.mapTo), t.identifier(rule.mapTo))],
32
+ t.stringLiteral(state.opts.isLocal
33
+ ? state.file.opts.filename.split('react-native-unistyles').at(0).concat(`react-native-unistyles/components/native/${rule.mapTo}`)
34
+ : `react-native-unistyles/components/native/${rule.mapTo}`
35
+ )
36
+ )
37
+
31
38
  path.node.specifiers = specifiers.filter(s => s !== specifier)
32
- path.unshift(newImport)
39
+
40
+ if (path.node.specifiers.length === 0) {
41
+ path.replaceWith(newImport)
42
+ } else {
43
+ path.insertBefore(newImport)
44
+ }
33
45
  }
34
46
 
35
47
  return
package/plugin/index.d.ts CHANGED
@@ -1,43 +1,89 @@
1
+ type RemapImport = {
2
+ name?: string,
3
+ isDefault: boolean,
4
+ path: string,
5
+ mapTo: string
6
+ }
7
+
8
+ type RemapConfig = {
9
+ path: string,
10
+ imports: Array<RemapImport>
11
+ }
12
+
1
13
  export interface UnistylesPluginOptions {
2
14
  /**
3
15
  * Example: "src" or "apps/mobile"
4
16
  * Add this option if some of your components don't have `react-native-unistyles` import.
5
17
  * Babel plugin will automatically process all files under this root.
6
18
  */
7
- autoProcessRoot?: string
8
-
9
- /**
10
- * Example: ['@codemask/styles']
11
- * Enable this option if you want to process only files containing specific imports.
12
- */
13
- autoProcessImports?: string[]
14
-
15
- /**
16
- * Example: ['external-library/components']
17
- * Enable this option to process some 3rd party components under `node_modules`.
18
- * Under these paths we will replace `react-native` imports with `react-native-unistyles` factories that will borrow components refs [read more](https://www.unistyl.es/v3/other/babel-plugin#3-component-factory-borrowing-ref).
19
- *
20
- * Defaults to:
21
- *
22
- * ```ts
23
- * ['react-native-reanimated/src/component', 'react-native-gesture-handler/src/components']
24
- * ```
25
- */
26
- autoProcessPaths?: string[];
27
-
28
- /**
29
- * In order to list detected dependencies by the Babel plugin you can enable the `debug` flag.
30
- * It will `console.log` name of the file and component with Unistyles dependencies.
31
- */
32
- debug?: boolean;
33
-
34
- /**
35
- * Only applicable for Unistyles monorepo for
36
- * path resolution, don't use it!
37
- */
38
- isLocal?: boolean;
19
+ autoProcessRoot?: string,
20
+
21
+ /**
22
+ * Example: ['@codemask/styles']
23
+ * Enable this option if you want to process only files containing specific imports.
24
+ */
25
+ autoProcessImports?: Array<string>,
26
+
27
+ /**
28
+ * Example: [{
29
+ * path: "node_modules/custom-library/components",
30
+ * imports: [
31
+ * {
32
+ * name: "NativeText",
33
+ * isDefault: false,
34
+ * path: "react-native/Libraries/Text/TextNativeComponent",
35
+ * mapTo: "NativeText"
36
+ * },
37
+ * {
38
+ * isDefault: true,
39
+ * path: "react-native/Libraries/Components/View/ViewNativeComponent",
40
+ * mapTo: "NativeView"
41
+ * }
42
+ * ]
43
+ * }]
44
+ *
45
+ * Will map:
46
+ * import { NativeText } from "react-native/Libraries/Text/TextNativeComponent"
47
+ * to Unistyles "NativeText"
48
+ *
49
+ * import View from "react-native/Libraries/Components/View/ViewNativeComponent"
50
+ * to Unistyles "NativeView"
51
+ *
52
+ * This is the most powerful way of remapping imports. If 3rd party library uses imports different from `react-native` we can remap them to `react-native-unistyles` factories.
53
+ * Internally we do that for raw RCTView and RCTText components.
54
+ *
55
+ * path -> must be within node_modules folder
56
+ * imports.name is Optional if library used export default
57
+ * imports.mapTo - name of the component from react-native-unistyles/src/components/native
58
+ */
59
+ autoRemapImports?: Array<RemapConfig>,
60
+
61
+ /**
62
+ * Example: ['external-library/components']
63
+ * Enable this option to process some 3rd party components under `node_modules`.
64
+ * Under these paths we will replace `react-native` imports with `react-native-unistyles` factories that will borrow components refs [read more](https://www.unistyl.es/v3/other/babel-plugin#3-component-factory-borrowing-ref).
65
+ *
66
+ * Defaults to:
67
+ *
68
+ * ```ts
69
+ * ['react-native-reanimated/src/component', 'react-native-gesture-handler/src/components']
70
+ * ```
71
+ */
72
+ autoProcessPaths?: Array<string>,
73
+
74
+ /**
75
+ * In order to list detected dependencies by the Babel plugin you can enable the `debug` flag.
76
+ * It will `console.log` name of the file and component with Unistyles dependencies.
77
+ */
78
+ debug?: boolean,
79
+
80
+ /**
81
+ * Only applicable for Unistyles monorepo for
82
+ * path resolution, don't use it!
83
+ */
84
+ isLocal?: boolean
39
85
  }
40
86
 
41
87
  export interface UnistylesPluginPass {
42
- opts: UnistylesPluginOptions;
88
+ opts: UnistylesPluginOptions
43
89
  }
package/plugin/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  const { addUnistylesImport, isInsideNodeModules } = require('./import')
2
2
  const { hasStringRef } = require('./ref')
3
- const { isUnistylesStyleSheet, analyzeDependencies, addStyleSheetTag, getUnistyles, isKindOfStyleSheet } = require('./stylesheet')
3
+ const { isUnistylesStyleSheet, analyzeDependencies, addStyleSheetTag, getUnistyles, isKindOfStyleSheet, addThemeDependencyToMemberExpression } = require('./stylesheet')
4
4
  const { extractVariants } = require('./variants')
5
- const { REACT_NATIVE_COMPONENT_NAMES, REPLACE_WITH_UNISTYLES_PATHS, REPLACE_WITH_UNISTYLES_EXOTIC_PATHS } = require('./consts')
5
+ const { REACT_NATIVE_COMPONENT_NAMES, REPLACE_WITH_UNISTYLES_PATHS, REPLACE_WITH_UNISTYLES_EXOTIC_PATHS, NATIVE_COMPONENTS_PATHS } = require('./consts')
6
6
  const { handleExoticImport } = require('./exotic')
7
7
 
8
8
  module.exports = function ({ types: t }) {
@@ -81,6 +81,7 @@ module.exports = function ({ types: t }) {
81
81
  /** @param {import('./index').UnistylesPluginPass} state */
82
82
  ImportDeclaration(path, state) {
83
83
  const exoticImport = REPLACE_WITH_UNISTYLES_EXOTIC_PATHS
84
+ .concat(state.opts.autoRemapImports ?? [])
84
85
  .find(exotic => state.filename.includes(exotic.path))
85
86
 
86
87
  if (exoticImport) {
@@ -109,6 +110,10 @@ module.exports = function ({ types: t }) {
109
110
  })
110
111
  }
111
112
 
113
+ if (importSource.includes('react-native/Libraries')) {
114
+ handleExoticImport(t, path, state, NATIVE_COMPONENTS_PATHS)
115
+ }
116
+
112
117
  if (!state.file.forceProcessing && Array.isArray(state.opts.autoProcessImports)) {
113
118
  state.file.forceProcessing = state.opts.autoProcessImports.includes(importSource)
114
119
  }
@@ -178,6 +183,13 @@ module.exports = function ({ types: t }) {
178
183
  if (t.isObjectProperty(property)) {
179
184
  const propertyValues = getUnistyles(t, property)
180
185
 
186
+ // maybe user used inlined theme? ({ container: theme.components.container })
187
+ if (propertyValues.length === 0 && t.isMemberExpression(property.value)) {
188
+ if (property.value.object.object.name === themeLocalName) {
189
+ addThemeDependencyToMemberExpression(t, property)
190
+ }
191
+ }
192
+
181
193
  propertyValues.forEach(propertyValue => {
182
194
  analyzeDependencies(t, state, property.key.name, propertyValue, themeLocalName, miniRuntimeLocalName)
183
195
  })
@@ -219,10 +219,21 @@ function getUnistyles(t, property) {
219
219
  return []
220
220
  }
221
221
 
222
+ function addThemeDependencyToMemberExpression(t, path) {
223
+ path.value = t.objectExpression([
224
+ t.spreadElement(path.value),
225
+ t.objectProperty(
226
+ t.identifier('uni__dependencies'),
227
+ t.arrayExpression([t.numericLiteral(UnistyleDependency.Theme)])
228
+ )
229
+ ])
230
+ }
231
+
222
232
  module.exports = {
223
233
  isUnistylesStyleSheet,
224
234
  analyzeDependencies,
225
235
  addStyleSheetTag,
226
236
  getUnistyles,
227
- isKindOfStyleSheet
237
+ isKindOfStyleSheet,
238
+ addThemeDependencyToMemberExpression
228
239
  }
@@ -0,0 +1,12 @@
1
+ import type { TextProps } from 'react-native'
2
+ import { type ComponentType, createElement, forwardRef } from 'react'
3
+ import { createUnistylesElement } from '../../core'
4
+
5
+ // credits to @hirbod
6
+ const LeanText = forwardRef((props, ref) => {
7
+ return createElement('RCTText', { ...props, ref })
8
+ }) as ComponentType<TextProps>
9
+
10
+ LeanText.displayName = 'RCTText'
11
+
12
+ export const NativeText = createUnistylesElement(LeanText)
@@ -0,0 +1 @@
1
+ export { Text } from './Text'
@@ -0,0 +1,13 @@
1
+ import type { ViewProps } from 'react-native'
2
+ import { type ComponentType, createElement, forwardRef } from 'react'
3
+ import { createUnistylesElement } from '../../core'
4
+
5
+ // credits to @hirbod
6
+ const LeanView = forwardRef((props, ref) => {
7
+ return createElement('RCTView', { ...props, ref })
8
+ }) as ComponentType<ViewProps>
9
+
10
+ LeanView.displayName = 'RCTView'
11
+
12
+ // this will match default export from react-native
13
+ export default createUnistylesElement(LeanView)
@@ -0,0 +1,3 @@
1
+ import { View } from './View'
2
+
3
+ export default View
@@ -12,7 +12,8 @@ type UnistylesThemeSettings = {
12
12
  }
13
13
 
14
14
  type UnistylesSettings = UnistylesThemeSettings & {
15
- CSSVars?: boolean
15
+ CSSVars?: boolean,
16
+ nativeBreakpointsMode?: 'pixels' | 'points'
16
17
  }
17
18
 
18
19
  export type UnistylesConfig = {