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

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 (98) hide show
  1. package/android/src/main/cxx/NativeUnistylesModule.cpp +1 -1
  2. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +1 -2
  3. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +4 -0
  4. package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +2 -1
  5. package/android/src/main/java/com/unistyles/UnistylesModule.kt +0 -4
  6. package/components/native/Animated/package.json +5 -0
  7. package/cxx/core/UnistylesRegistry.cpp +24 -3
  8. package/cxx/core/UnistylesRegistry.h +1 -0
  9. package/cxx/hybridObjects/HybridShadowRegistry.cpp +7 -0
  10. package/lib/commonjs/components/native/Animated.js +23 -0
  11. package/lib/commonjs/components/native/Animated.js.map +1 -0
  12. package/lib/commonjs/components/native/ImageBackground.js +3 -1
  13. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  14. package/lib/commonjs/components/native/Pressable.native.js +15 -2
  15. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  16. package/lib/commonjs/core/createUnistylesElement.js +26 -22
  17. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  18. package/lib/commonjs/core/createUnistylesElement.native.js +25 -21
  19. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  20. package/lib/commonjs/core/createUnistylesImageBackground.js +34 -30
  21. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  22. package/lib/commonjs/utils.js +16 -1
  23. package/lib/commonjs/utils.js.map +1 -1
  24. package/lib/commonjs/web/utils/unistyle.js +5 -1
  25. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  26. package/lib/module/components/native/Animated.js +19 -0
  27. package/lib/module/components/native/Animated.js.map +1 -0
  28. package/lib/module/components/native/ImageBackground.js +3 -1
  29. package/lib/module/components/native/ImageBackground.js.map +1 -1
  30. package/lib/module/components/native/Pressable.native.js +15 -2
  31. package/lib/module/components/native/Pressable.native.js.map +1 -1
  32. package/lib/module/core/createUnistylesElement.js +26 -22
  33. package/lib/module/core/createUnistylesElement.js.map +1 -1
  34. package/lib/module/core/createUnistylesElement.native.js +25 -21
  35. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  36. package/lib/module/core/createUnistylesImageBackground.js +34 -30
  37. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  38. package/lib/module/utils.js +14 -0
  39. package/lib/module/utils.js.map +1 -1
  40. package/lib/module/web/utils/unistyle.js +5 -1
  41. package/lib/module/web/utils/unistyle.js.map +1 -1
  42. package/lib/typescript/src/components/native/ActivityIndicator.d.ts +1 -3
  43. package/lib/typescript/src/components/native/ActivityIndicator.d.ts.map +1 -1
  44. package/lib/typescript/src/components/native/Animated.d.ts +39 -0
  45. package/lib/typescript/src/components/native/Animated.d.ts.map +1 -0
  46. package/lib/typescript/src/components/native/FlatList.d.ts +1 -3
  47. package/lib/typescript/src/components/native/FlatList.d.ts.map +1 -1
  48. package/lib/typescript/src/components/native/Image.d.ts +1 -3
  49. package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
  50. package/lib/typescript/src/components/native/ImageBackground.d.ts +1 -8
  51. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
  52. package/lib/typescript/src/components/native/ImageBackground.native.d.ts +1 -2
  53. package/lib/typescript/src/components/native/ImageBackground.native.d.ts.map +1 -1
  54. package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts +1 -3
  55. package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts.map +1 -1
  56. package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
  57. package/lib/typescript/src/components/native/RefreshControl.d.ts +1 -3
  58. package/lib/typescript/src/components/native/RefreshControl.d.ts.map +1 -1
  59. package/lib/typescript/src/components/native/ScrollView.d.ts +1 -3
  60. package/lib/typescript/src/components/native/ScrollView.d.ts.map +1 -1
  61. package/lib/typescript/src/components/native/SectionList.d.ts +1 -3
  62. package/lib/typescript/src/components/native/SectionList.d.ts.map +1 -1
  63. package/lib/typescript/src/components/native/Switch.d.ts +1 -3
  64. package/lib/typescript/src/components/native/Switch.d.ts.map +1 -1
  65. package/lib/typescript/src/components/native/Text.d.ts +1 -3
  66. package/lib/typescript/src/components/native/Text.d.ts.map +1 -1
  67. package/lib/typescript/src/components/native/TextInput.d.ts +1 -3
  68. package/lib/typescript/src/components/native/TextInput.d.ts.map +1 -1
  69. package/lib/typescript/src/components/native/TouchableHighlight.d.ts +1 -3
  70. package/lib/typescript/src/components/native/TouchableHighlight.d.ts.map +1 -1
  71. package/lib/typescript/src/components/native/TouchableOpacity.d.ts +1 -3
  72. package/lib/typescript/src/components/native/TouchableOpacity.d.ts.map +1 -1
  73. package/lib/typescript/src/components/native/View.d.ts +1 -3
  74. package/lib/typescript/src/components/native/View.d.ts.map +1 -1
  75. package/lib/typescript/src/components/native/VirtualizedList.d.ts +1 -3
  76. package/lib/typescript/src/components/native/VirtualizedList.d.ts.map +1 -1
  77. package/lib/typescript/src/core/createUnistylesElement.d.ts +1 -7
  78. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  79. package/lib/typescript/src/core/createUnistylesElement.native.d.ts +1 -2
  80. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  81. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts +2 -3
  82. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  83. package/lib/typescript/src/utils.d.ts +1 -0
  84. package/lib/typescript/src/utils.d.ts.map +1 -1
  85. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  86. package/package.json +3 -1
  87. package/plugin/consts.js +43 -0
  88. package/plugin/exotic.js +42 -0
  89. package/plugin/index.js +10 -30
  90. package/plugin/variants.js +1 -1
  91. package/src/components/native/Animated.tsx +17 -0
  92. package/src/components/native/ImageBackground.tsx +4 -1
  93. package/src/components/native/Pressable.native.tsx +20 -2
  94. package/src/core/createUnistylesElement.native.tsx +28 -23
  95. package/src/core/createUnistylesElement.tsx +34 -29
  96. package/src/core/createUnistylesImageBackground.tsx +38 -33
  97. package/src/utils.ts +17 -0
  98. package/src/web/utils/unistyle.ts +7 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Text.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/Text.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,IAAI;;2CAAqC,CAAA"}
1
+ {"version":3,"file":"Text.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/Text.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,IAAI,KAAqC,CAAA"}
@@ -1,4 +1,2 @@
1
- export declare const TextInput: import("react").ForwardRefExoticComponent<{
2
- style?: import("../../types").UnistylesValues | Array<import("../../types").UnistylesValues>;
3
- } & import("react").RefAttributes<unknown>>;
1
+ export declare const TextInput: any;
4
2
  //# sourceMappingURL=TextInput.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TextInput.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/TextInput.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS;;2CAA0C,CAAA"}
1
+ {"version":3,"file":"TextInput.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/TextInput.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,KAA0C,CAAA"}
@@ -1,4 +1,2 @@
1
- export declare const TouchableHighlight: import("react").ForwardRefExoticComponent<{
2
- style?: import("../../types").UnistylesValues | Array<import("../../types").UnistylesValues>;
3
- } & import("react").RefAttributes<unknown>>;
1
+ export declare const TouchableHighlight: any;
4
2
  //# sourceMappingURL=TouchableHighlight.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TouchableHighlight.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/TouchableHighlight.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB;;2CAAmD,CAAA"}
1
+ {"version":3,"file":"TouchableHighlight.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/TouchableHighlight.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,KAAmD,CAAA"}
@@ -1,4 +1,2 @@
1
- export declare const TouchableOpacity: import("react").ForwardRefExoticComponent<{
2
- style?: import("../../types").UnistylesValues | Array<import("../../types").UnistylesValues>;
3
- } & import("react").RefAttributes<unknown>>;
1
+ export declare const TouchableOpacity: any;
4
2
  //# sourceMappingURL=TouchableOpacity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TouchableOpacity.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/TouchableOpacity.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,gBAAgB;;2CAAiD,CAAA"}
1
+ {"version":3,"file":"TouchableOpacity.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/TouchableOpacity.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,gBAAgB,KAAiD,CAAA"}
@@ -1,4 +1,2 @@
1
- export declare const View: import("react").ForwardRefExoticComponent<{
2
- style?: import("../../types").UnistylesValues | Array<import("../../types").UnistylesValues>;
3
- } & import("react").RefAttributes<unknown>>;
1
+ export declare const View: any;
4
2
  //# sourceMappingURL=View.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"View.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/View.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,IAAI;;2CAAqC,CAAA"}
1
+ {"version":3,"file":"View.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/View.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,IAAI,KAAqC,CAAA"}
@@ -1,4 +1,2 @@
1
- export declare const VirtualizedList: import("react").ForwardRefExoticComponent<{
2
- style?: import("../../types").UnistylesValues | Array<import("../../types").UnistylesValues>;
3
- } & import("react").RefAttributes<unknown>>;
1
+ export declare const VirtualizedList: any;
4
2
  //# sourceMappingURL=VirtualizedList.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"VirtualizedList.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/VirtualizedList.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe;;2CAAgD,CAAA"}
1
+ {"version":3,"file":"VirtualizedList.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/VirtualizedList.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,KAAgD,CAAA"}
@@ -1,8 +1,2 @@
1
- import React from 'react';
2
- import type { UnistylesValues } from '../types';
3
- type ComponentProps = {
4
- style?: UnistylesValues | Array<UnistylesValues>;
5
- };
6
- export declare const createUnistylesElement: (Component: any) => React.ForwardRefExoticComponent<ComponentProps & React.RefAttributes<unknown>>;
7
- export {};
1
+ export declare const createUnistylesElement: (Component: any) => any;
8
2
  //# sourceMappingURL=createUnistylesElement.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createUnistylesElement.d.ts","sourceRoot":"","sources":["../../../../src/core/createUnistylesElement.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAM/C,KAAK,cAAc,GAAG;IAClB,KAAK,CAAC,EAAE,eAAe,GAAG,KAAK,CAAC,eAAe,CAAC,CAAA;CACnD,CAAA;AAED,eAAO,MAAM,sBAAsB,cAAe,GAAG,mFA+BnD,CAAA"}
1
+ {"version":3,"file":"createUnistylesElement.d.ts","sourceRoot":"","sources":["../../../../src/core/createUnistylesElement.tsx"],"names":[],"mappings":"AAYA,eAAO,MAAM,sBAAsB,cAAe,GAAG,QAmCpD,CAAA"}
@@ -1,3 +1,2 @@
1
- import React from 'react';
2
- export declare const createUnistylesElement: (Component: any) => React.ForwardRefExoticComponent<React.RefAttributes<unknown>>;
1
+ export declare const createUnistylesElement: (Component: any) => any;
3
2
  //# sourceMappingURL=createUnistylesElement.native.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createUnistylesElement.native.d.ts","sourceRoot":"","sources":["../../../../src/core/createUnistylesElement.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkC,MAAM,OAAO,CAAA;AAkBtD,eAAO,MAAM,sBAAsB,cAAe,GAAG,kEA2BnD,CAAA"}
1
+ {"version":3,"file":"createUnistylesElement.native.d.ts","sourceRoot":"","sources":["../../../../src/core/createUnistylesElement.native.tsx"],"names":[],"mappings":"AAmBA,eAAO,MAAM,sBAAsB,cAAe,GAAG,QA+BpD,CAAA"}
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
- import type { ImageBackground, ImageBackgroundProps } from 'react-native';
3
- export declare const createUnistylesImageBackground: (Component: typeof ImageBackground) => React.ForwardRefExoticComponent<ImageBackgroundProps & React.RefAttributes<ImageBackground>>;
1
+ import type { ImageBackground } from 'react-native';
2
+ export declare const createUnistylesImageBackground: (Component: typeof ImageBackground) => any;
4
3
  //# sourceMappingURL=createUnistylesImageBackground.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createUnistylesImageBackground.d.ts","sourceRoot":"","sources":["../../../../src/core/createUnistylesImageBackground.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkC,MAAM,OAAO,CAAA;AACtD,OAAO,KAAK,EAAS,eAAe,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAKhF,eAAO,MAAM,8BAA8B,cAAe,OAAO,eAAe,iGAsC9E,CAAA"}
1
+ {"version":3,"file":"createUnistylesImageBackground.d.ts","sourceRoot":"","sources":["../../../../src/core/createUnistylesImageBackground.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAS,eAAe,EAAwB,MAAM,cAAc,CAAA;AAMhF,eAAO,MAAM,8BAA8B,cAAe,OAAO,eAAe,QA0C/E,CAAA"}
@@ -1,3 +1,4 @@
1
1
  export declare const isDefined: <T>(value: T) => value is NonNullable<T>;
2
2
  export declare const deepMergeObjects: <T extends Record<PropertyKey, any>>(...sources: Array<T>) => T;
3
+ export declare const copyComponentProperties: (Component: any, UnistylesComponent: any) => any;
3
4
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,CAAC,KAAG,KAAK,IAAI,WAAW,CAAC,CAAC,CAA0C,CAAA;AAExG,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,cAAc,KAAK,CAAC,CAAC,CAAC,MAuBxF,CAAA"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,CAAC,KAAG,KAAK,IAAI,WAAW,CAAC,CAAC,CAA0C,CAAA;AAExG,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,cAAc,KAAK,CAAC,CAAC,CAAC,MAuBxF,CAAA;AAED,eAAO,MAAM,uBAAuB,cAAe,GAAG,sBAAsB,GAAG,QAe9E,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"unistyle.d.ts","sourceRoot":"","sources":["../../../../../src/web/utils/unistyle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AACpE,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAA;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAMpG,eAAO,MAAM,aAAa,WAAY,WAAW,qBAQhD,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC1B,iBAAiB,EAAE,yBAAyB,CAAC,UAAU,CAAC,CAAC;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAA;CAC/D,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,CAAC,UAAU,CAAC,WAAW,eAAe,MAanE,CAAA;AAED,eAAO,MAAM,cAAc,WAAY,GAAG;;aAYzC,CAAA;AAED,eAAO,MAAM,kBAAkB,WAAY,eAAe,OAUzD,CAAA;AAED,eAAO,MAAM,YAAY,YAAa,WAAW,YAAoC,CAAA;AAErF,eAAO,MAAM,aAAa,UAAW,MAAM,kBAAkB,KAAK,CAAC,MAAM,CAAC,WA6BzE,CAAA;AAED,eAAO,MAAM,2BAA2B,UAAW,GAAG,yBAQrD,CAAA"}
1
+ {"version":3,"file":"unistyle.d.ts","sourceRoot":"","sources":["../../../../../src/web/utils/unistyle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AACpE,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAA;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAMpG,eAAO,MAAM,aAAa,WAAY,WAAW,qBAQhD,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC1B,iBAAiB,EAAE,yBAAyB,CAAC,UAAU,CAAC,CAAC;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAA;CAC/D,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,CAAC,UAAU,CAAC,WAAW,eAAe,MAanE,CAAA;AAED,eAAO,MAAM,cAAc,WAAY,GAAG;;aAkBzC,CAAA;AAED,eAAO,MAAM,kBAAkB,WAAY,eAAe,OAUzD,CAAA;AAED,eAAO,MAAM,YAAY,YAAa,WAAW,YAAoC,CAAA;AAErF,eAAO,MAAM,aAAa,UAAW,MAAM,kBAAkB,KAAK,CAAC,MAAM,CAAC,WA6BzE,CAAA;AAED,eAAO,MAAM,2BAA2B,UAAW,GAAG,yBAQrD,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.0.0-nightly-20250127",
3
+ "version": "3.0.0-nightly-20250129",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -82,6 +82,8 @@
82
82
  },
83
83
  "devDependencies": {
84
84
  "@babel/plugin-syntax-jsx": "7.25.9",
85
+ "@babel/preset-flow": "7.25.9",
86
+ "@babel/preset-typescript": "7.26.0",
85
87
  "@biomejs/biome": "1.9.4",
86
88
  "@commitlint/config-conventional": "19.6.0",
87
89
  "@react-native/normalize-colors": "0.77.0",
@@ -0,0 +1,43 @@
1
+ const REACT_NATIVE_COMPONENT_NAMES = [
2
+ 'ActivityIndicator',
3
+ 'View',
4
+ 'Text',
5
+ 'Image',
6
+ 'ImageBackground',
7
+ 'KeyboardAvoidingView',
8
+ 'Pressable',
9
+ 'ScrollView',
10
+ 'FlatList',
11
+ 'SectionList',
12
+ 'Switch',
13
+ 'TextInput',
14
+ 'RefreshControl',
15
+ 'TouchableHighlight',
16
+ 'TouchableOpacity',
17
+ 'VirtualizedList',
18
+ 'Animated'
19
+ // Modal - there is no exposed native handle
20
+ // TouchableWithoutFeedback - can't accept a ref
21
+ ]
22
+
23
+ // auto replace RN imports to Unistyles imports under these paths
24
+ // our implementation simply borrows 'ref' to register it in ShadowRegistry
25
+ // so we won't affect anyone's implementation
26
+ const REPLACE_WITH_UNISTYLES_PATHS = [
27
+ 'react-native-reanimated/src/component',
28
+ 'react-native-gesture-handler/src/components'
29
+ ]
30
+
31
+ // this is more powerful API as it allows to convert unmatched imports to Unistyles
32
+ // { path: string, imports: Array<{ name: string, isDefault: boolean, path: string, mapTo: string }> }
33
+ // name <- target import name
34
+ // isDefault <- is the import default?
35
+ // path <- path to the target import
36
+ // mapTo <- name of the Unistyles component
37
+ const REPLACE_WITH_UNISTYLES_EXOTIC_PATHS = []
38
+
39
+ module.exports = {
40
+ REACT_NATIVE_COMPONENT_NAMES,
41
+ REPLACE_WITH_UNISTYLES_PATHS,
42
+ REPLACE_WITH_UNISTYLES_EXOTIC_PATHS
43
+ }
@@ -0,0 +1,42 @@
1
+ function handleExoticImport(t, path, state, exoticImport) {
2
+ const specifiers = path.node.specifiers
3
+ const source = path.node.source
4
+
5
+ if (path.node.importKind !== 'value') {
6
+ return
7
+ }
8
+
9
+ specifiers.forEach(specifier => {
10
+ for (const rule of exoticImport.imports) {
11
+ const hasMatchingImportType = !rule.isDefault || t.isImportDefaultSpecifier(specifier)
12
+ const hasMatchingImportName = rule.name === specifier.local.name
13
+ const hasMatchingPath = rule.path === source.value
14
+
15
+ if (!hasMatchingImportType || !hasMatchingImportName || !hasMatchingPath) {
16
+ continue
17
+ }
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}`
24
+ )
25
+ )
26
+
27
+ // remove old import
28
+ if (t.isImportDefaultSpecifier(specifier)) {
29
+ path.replaceWith(newImport)
30
+ } else {
31
+ path.node.specifiers = specifiers.filter(s => s !== specifier)
32
+ path.unshift(newImport)
33
+ }
34
+
35
+ return
36
+ }
37
+ })
38
+ }
39
+
40
+ module.exports = {
41
+ handleExoticImport
42
+ }
package/plugin/index.js CHANGED
@@ -2,35 +2,8 @@ const { addUnistylesImport, isInsideNodeModules } = require('./import')
2
2
  const { hasStringRef } = require('./ref')
3
3
  const { isUnistylesStyleSheet, analyzeDependencies, addStyleSheetTag, getUnistyles, isKindOfStyleSheet } = require('./stylesheet')
4
4
  const { extractVariants } = require('./variants')
5
-
6
- const reactNativeComponentNames = [
7
- 'ActivityIndicator',
8
- 'View',
9
- 'Text',
10
- 'Image',
11
- 'ImageBackground',
12
- 'KeyboardAvoidingView',
13
- 'Pressable',
14
- 'ScrollView',
15
- 'FlatList',
16
- 'SectionList',
17
- 'Switch',
18
- 'TextInput',
19
- 'RefreshControl',
20
- 'TouchableHighlight',
21
- 'TouchableOpacity',
22
- 'VirtualizedList',
23
- // Modal - there is no exposed native handle
24
- // TouchableWithoutFeedback - can't accept a ref
25
- ]
26
-
27
- // auto replace RN imports to Unistyles imports under these paths
28
- // our implementation simply borrows 'ref' to register it in ShadowRegistry
29
- // so we won't affect anyone's implementation
30
- const REPLACE_WITH_UNISTYLES_PATHS = [
31
- 'react-native-reanimated/src/component',
32
- 'react-native-gesture-handler/src/components'
33
- ]
5
+ const { REACT_NATIVE_COMPONENT_NAMES, REPLACE_WITH_UNISTYLES_PATHS, REPLACE_WITH_UNISTYLES_EXOTIC_PATHS } = require('./consts')
6
+ const { handleExoticImport } = require('./exotic')
34
7
 
35
8
  module.exports = function ({ types: t }) {
36
9
  return {
@@ -107,6 +80,13 @@ module.exports = function ({ types: t }) {
107
80
  },
108
81
  /** @param {import('./index').UnistylesPluginPass} state */
109
82
  ImportDeclaration(path, state) {
83
+ const exoticImport = REPLACE_WITH_UNISTYLES_EXOTIC_PATHS
84
+ .find(exotic => state.filename.includes(exotic.path))
85
+
86
+ if (exoticImport) {
87
+ return handleExoticImport(t, path, state, exoticImport)
88
+ }
89
+
110
90
  if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
111
91
  return
112
92
  }
@@ -123,7 +103,7 @@ module.exports = function ({ types: t }) {
123
103
 
124
104
  if (importSource === 'react-native') {
125
105
  path.node.specifiers.forEach(specifier => {
126
- if (specifier.imported && reactNativeComponentNames.includes(specifier.imported.name)) {
106
+ if (specifier.imported && REACT_NATIVE_COMPONENT_NAMES.includes(specifier.imported.name)) {
127
107
  state.reactNativeImports[specifier.local.name] = specifier.imported.name
128
108
  }
129
109
  })
@@ -15,7 +15,7 @@ function extractVariants(t, path, state) {
15
15
  return (
16
16
  t.isIdentifier(variant.expression.callee.object, { name: calleeName }) &&
17
17
  t.isIdentifier(variant.expression.callee.property, { name: 'useVariants' }) &&
18
- t.isObjectExpression(variant.expression.arguments[0])
18
+ variant.expression.arguments.length === 1
19
19
  )
20
20
  })
21
21
 
@@ -0,0 +1,17 @@
1
+ import { Animated as RNAnimated } from 'react-native'
2
+ import { View } from './View'
3
+ import { Text } from './Text'
4
+ import { FlatList } from './FlatList'
5
+ import { Image } from './Image'
6
+ import { ScrollView } from './ScrollView'
7
+ import { SectionList } from './SectionList'
8
+
9
+ export const Animated = {
10
+ ...RNAnimated,
11
+ View: RNAnimated.createAnimatedComponent(View),
12
+ Text: RNAnimated.createAnimatedComponent(Text),
13
+ FlatList: RNAnimated.createAnimatedComponent(FlatList),
14
+ Image: RNAnimated.createAnimatedComponent(Image),
15
+ ScrollView: RNAnimated.createAnimatedComponent(ScrollView),
16
+ SectionList: RNAnimated.createAnimatedComponent(SectionList)
17
+ }
@@ -5,13 +5,14 @@ import type { UnistylesValues } from '../../types'
5
5
  import { getClassName } from '../../core'
6
6
  import { isServer } from '../../web/utils'
7
7
  import { UnistylesShadowRegistry } from '../../web'
8
+ import { copyComponentProperties } from '../../utils'
8
9
 
9
10
  type Props = {
10
11
  style?: UnistylesValues
11
12
  imageStyle?: UnistylesValues
12
13
  }
13
14
 
14
- export const ImageBackground = forwardRef<unknown, Props>((props, forwardedRef) => {
15
+ const UnistylesImageBackground = forwardRef<unknown, Props>((props, forwardedRef) => {
15
16
  let storedRef: NativeImageBackground | null = null
16
17
  let storedImageRef: NativeImageBackground | null = null
17
18
  const styleClassNames = getClassName(props.style)
@@ -54,3 +55,5 @@ export const ImageBackground = forwardRef<unknown, Props>((props, forwardedRef)
54
55
  />
55
56
  )
56
57
  })
58
+
59
+ export const ImageBackground = copyComponentProperties(NativeImageBackground, UnistylesImageBackground)
@@ -8,6 +8,22 @@ type PressableProps = Props & {
8
8
  variants?: Record<string, string | boolean>
9
9
  }
10
10
 
11
+ const getStyles = (styleProps: Record<string, any> = {}) => {
12
+ const unistyleKey = Object
13
+ .keys(styleProps)
14
+ .find(key => key.startsWith('unistyles-'))
15
+
16
+ if (!unistyleKey) {
17
+ return styleProps
18
+ }
19
+
20
+ return {
21
+ // styles without C++ state
22
+ ...styleProps[unistyleKey].uni__getStyles(),
23
+ [unistyleKey]: styleProps[unistyleKey].uni__getStyles()
24
+ }
25
+ }
26
+
11
27
  export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ...props }, forwardedRef) => {
12
28
  const storedRef = useRef<View | null>()
13
29
 
@@ -28,7 +44,7 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
28
44
  ? style({ pressed: false })
29
45
  : style
30
46
 
31
- // @ts-expect-error web types are not compatible with RN styles
47
+ // @ts-expect-error - this is hidden from TS
32
48
  UnistylesShadowRegistry.add(ref, unistyles)
33
49
 
34
50
  if (ref) {
@@ -40,12 +56,14 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
40
56
  style={state => {
41
57
  const unistyles = typeof style === 'function'
42
58
  ? style(state)
43
- : style
59
+ : getStyles(style as unknown as Record<string, any>)
44
60
 
45
61
  if (!storedRef.current) {
46
62
  return unistyles
47
63
  }
48
64
 
65
+ // @ts-expect-error - this is hidden from TS
66
+ UnistylesShadowRegistry.remove(storedRef.current)
49
67
  // @ts-expect-error - this is hidden from TS
50
68
  UnistylesShadowRegistry.add(storedRef.current, unistyles)
51
69
 
@@ -2,6 +2,7 @@ import React, { useLayoutEffect, useRef } from 'react'
2
2
  import { UnistylesShadowRegistry } from '../specs'
3
3
  import { passForwardedRef } from './passForwardRef'
4
4
  import { maybeWarnAboutMultipleUnistyles } from './warn'
5
+ import { copyComponentProperties } from '../utils'
5
6
 
6
7
  const getNativeRef = (Component: any, ref: any) => {
7
8
  switch (Component.name) {
@@ -16,31 +17,35 @@ const getNativeRef = (Component: any, ref: any) => {
16
17
  }
17
18
  }
18
19
 
19
- export const createUnistylesElement = (Component: any) => React.forwardRef((props, forwardedRef) => {
20
- const storedRef = useRef<unknown>(null)
20
+ export const createUnistylesElement = (Component: any) => {
21
+ const UnistylesComponent = React.forwardRef((props, forwardedRef) => {
22
+ const storedRef = useRef<unknown>(null)
21
23
 
22
- useLayoutEffect(() => {
23
- return () => {
24
- if (storedRef.current) {
25
- // @ts-ignore
26
- UnistylesShadowRegistry.remove(storedRef.current)
24
+ useLayoutEffect(() => {
25
+ return () => {
26
+ if (storedRef.current) {
27
+ // @ts-ignore
28
+ UnistylesShadowRegistry.remove(storedRef.current)
29
+ }
27
30
  }
28
- }
29
- }, [])
31
+ }, [])
30
32
 
31
- return (
32
- <Component
33
- {...props}
34
- ref={(ref: unknown) => {
35
- if (ref) {
36
- storedRef.current = getNativeRef(Component, ref)
37
- }
33
+ return (
34
+ <Component
35
+ {...props}
36
+ ref={(ref: unknown) => {
37
+ if (ref) {
38
+ storedRef.current = getNativeRef(Component, ref)
39
+ }
38
40
 
39
- passForwardedRef(props, ref, forwardedRef)
41
+ passForwardedRef(props, ref, forwardedRef)
40
42
 
41
- // @ts-ignore we don't know the type of the component
42
- maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
43
- }}
44
- />
45
- )
46
- })
43
+ // @ts-ignore we don't know the type of the component
44
+ maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
45
+ }}
46
+ />
47
+ )
48
+ })
49
+
50
+ return copyComponentProperties(Component, UnistylesComponent)
51
+ }
@@ -4,40 +4,45 @@ import { getClassName } from './getClassname'
4
4
  import { isServer } from '../web/utils'
5
5
  import { UnistylesShadowRegistry } from '../web'
6
6
  import { maybeWarnAboutMultipleUnistyles } from './warn'
7
+ import { copyComponentProperties } from '../utils'
7
8
 
8
9
  type ComponentProps = {
9
10
  style?: UnistylesValues | Array<UnistylesValues>
10
11
  }
11
12
 
12
- export const createUnistylesElement = (Component: any) => React.forwardRef<unknown, ComponentProps>((props, forwardedRef) => {
13
- let storedRef: HTMLElement | null = null
14
- const classNames = getClassName(props.style)
13
+ export const createUnistylesElement = (Component: any) => {
14
+ const UnistylesComponent = React.forwardRef<unknown, ComponentProps>((props, forwardedRef) => {
15
+ let storedRef: HTMLElement | null = null
16
+ const classNames = getClassName(props.style)
15
17
 
16
- return (
17
- <Component
18
- {...props}
19
- style={classNames}
20
- ref={isServer() ? undefined : (ref: HTMLElement | null) => {
21
- // @ts-ignore we don't know the type of the component
22
- maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
18
+ return (
19
+ <Component
20
+ {...props}
21
+ style={classNames}
22
+ ref={isServer() ? undefined : (ref: HTMLElement | null) => {
23
+ // @ts-ignore we don't know the type of the component
24
+ maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
23
25
 
24
- if (!ref) {
26
+ if (!ref) {
27
+ // @ts-expect-error hidden from TS
28
+ UnistylesShadowRegistry.remove(storedRef, classNames?.hash)
29
+ }
30
+
31
+ storedRef = ref
25
32
  // @ts-expect-error hidden from TS
26
- UnistylesShadowRegistry.remove(storedRef, classNames?.hash)
27
- }
28
-
29
- storedRef = ref
30
- // @ts-expect-error hidden from TS
31
- UnistylesShadowRegistry.add(ref, classNames?.hash)
32
-
33
- if (typeof forwardedRef === 'function') {
34
- return forwardedRef(ref)
35
- }
36
-
37
- if (forwardedRef) {
38
- forwardedRef.current = ref
39
- }
40
- }}
41
- />
42
- )
43
- })
33
+ UnistylesShadowRegistry.add(ref, classNames?.hash)
34
+
35
+ if (typeof forwardedRef === 'function') {
36
+ return forwardedRef(ref)
37
+ }
38
+
39
+ if (forwardedRef) {
40
+ forwardedRef.current = ref
41
+ }
42
+ }}
43
+ />
44
+ )
45
+ })
46
+
47
+ return copyComponentProperties(Component, UnistylesComponent)
48
+ }
@@ -3,43 +3,48 @@ import type { Image, ImageBackground, ImageBackgroundProps } from 'react-native'
3
3
  import { UnistylesShadowRegistry } from '../specs'
4
4
  import { passForwardedRef } from './passForwardRef'
5
5
  import { maybeWarnAboutMultipleUnistyles } from './warn'
6
+ import { copyComponentProperties } from '../utils'
6
7
 
7
- export const createUnistylesImageBackground = (Component: typeof ImageBackground) => React.forwardRef<ImageBackground, ImageBackgroundProps>((props, forwardedRef) => {
8
- const storedImageRef = useRef<Image | null>(null)
8
+ export const createUnistylesImageBackground = (Component: typeof ImageBackground) => {
9
+ const UnistylesImageBackground = React.forwardRef<ImageBackground, ImageBackgroundProps>((props, forwardedRef) => {
10
+ const storedImageRef = useRef<Image | null>(null)
9
11
 
10
- useLayoutEffect(() => {
11
- return () => {
12
- if (storedImageRef.current) {
13
- // @ts-ignore
14
- UnistylesShadowRegistry.remove(storedImageRef.current)
12
+ useLayoutEffect(() => {
13
+ return () => {
14
+ if (storedImageRef.current) {
15
+ // @ts-ignore
16
+ UnistylesShadowRegistry.remove(storedImageRef.current)
17
+ }
15
18
  }
16
- }
17
- }, [])
19
+ }, [])
18
20
 
19
- // @ts-expect-error we don't know the type of the component
20
- maybeWarnAboutMultipleUnistyles(props.style, 'ImageBackground')
21
- // @ts-ignore we don't know the type of the component
22
- maybeWarnAboutMultipleUnistyles(props.imageStyle, 'ImageBackground')
21
+ // @ts-expect-error we don't know the type of the component
22
+ maybeWarnAboutMultipleUnistyles(props.style, 'ImageBackground')
23
+ // @ts-ignore we don't know the type of the component
24
+ maybeWarnAboutMultipleUnistyles(props.imageStyle, 'ImageBackground')
23
25
 
24
- return (
25
- <Component
26
- {...props}
27
- ref={ref => {
28
- passForwardedRef(props, ref, forwardedRef)
26
+ return (
27
+ <Component
28
+ {...props}
29
+ ref={ref => {
30
+ passForwardedRef(props, ref, forwardedRef)
29
31
 
30
- return () => {
31
- // @ts-ignore
32
- UnistylesShadowRegistry.remove(ref)
33
- }
34
- }}
35
- imageRef={ref => {
36
- if (ref) {
37
- storedImageRef.current = ref
38
- }
32
+ return () => {
33
+ // @ts-ignore
34
+ UnistylesShadowRegistry.remove(ref)
35
+ }
36
+ }}
37
+ imageRef={ref => {
38
+ if (ref) {
39
+ storedImageRef.current = ref
40
+ }
41
+
42
+ // @ts-expect-error web types are not compatible with RN styles
43
+ UnistylesShadowRegistry.add(ref, props.imageStyle)
44
+ }}
45
+ />
46
+ )
47
+ })
39
48
 
40
- // @ts-expect-error web types are not compatible with RN styles
41
- UnistylesShadowRegistry.add(ref, props.imageStyle)
42
- }}
43
- />
44
- )
45
- })
49
+ return copyComponentProperties(Component, UnistylesImageBackground)
50
+ }