react-native-unistyles 3.0.0-alpha.43 → 3.0.0-alpha.45

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 (38) hide show
  1. package/lib/commonjs/components/Pressable.js +6 -14
  2. package/lib/commonjs/components/Pressable.js.map +1 -1
  3. package/lib/commonjs/components/Pressable.web.js +35 -17
  4. package/lib/commonjs/components/Pressable.web.js.map +1 -1
  5. package/lib/commonjs/web/shadowRegistry.js +18 -17
  6. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  7. package/lib/commonjs/web/utils/unistyle.js +2 -8
  8. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  9. package/lib/module/components/Pressable.js +6 -14
  10. package/lib/module/components/Pressable.js.map +1 -1
  11. package/lib/module/components/Pressable.web.js +35 -17
  12. package/lib/module/components/Pressable.web.js.map +1 -1
  13. package/lib/module/web/shadowRegistry.js +18 -17
  14. package/lib/module/web/shadowRegistry.js.map +1 -1
  15. package/lib/module/web/utils/unistyle.js +2 -8
  16. package/lib/module/web/utils/unistyle.js.map +1 -1
  17. package/lib/typescript/src/components/Pressable.d.ts +2 -1
  18. package/lib/typescript/src/components/Pressable.d.ts.map +1 -1
  19. package/lib/typescript/src/components/Pressable.web.d.ts +2 -1
  20. package/lib/typescript/src/components/Pressable.web.d.ts.map +1 -1
  21. package/lib/typescript/src/web/shadowRegistry.d.ts +1 -1
  22. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  23. package/lib/typescript/src/web/utils/unistyle.d.ts +1 -1
  24. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  25. package/nitrogen/generated/android/c++/JColorScheme.hpp +1 -1
  26. package/nitrogen/generated/android/c++/JOrientation.hpp +1 -1
  27. package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +1 -1
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/ColorScheme.kt +5 -1
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Orientation.kt +5 -1
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +5 -1
  31. package/package.json +3 -3
  32. package/plugin/index.js +1 -1
  33. package/plugin/style.js +94 -20
  34. package/plugin/stylesheet.js +1 -1
  35. package/src/components/Pressable.tsx +10 -22
  36. package/src/components/Pressable.web.tsx +54 -28
  37. package/src/web/shadowRegistry.ts +51 -47
  38. package/src/web/utils/unistyle.ts +2 -10
@@ -15,17 +15,11 @@ export const schemeToTheme = scheme => {
15
15
  };
16
16
  export const assignSecrets = (object, secrets) => {
17
17
  // @ts-expect-error - assign secrets to object
18
- object[`__uni__secrets__${Math.random().toString(16).slice(2)}`] = secrets;
18
+ object.__uni__secrets__ = secrets;
19
19
  return object;
20
20
  };
21
21
  export const extractSecrets = object => {
22
- const secrets = Object.entries(object).reduce((acc, [key, value]) => {
23
- if (key.startsWith('__uni__secrets__')) {
24
- acc.push(value);
25
- }
26
- return acc;
27
- }, []);
28
- return secrets;
22
+ return keyInObject(object, '__uni__secrets__') ? object.__uni__secrets__ : undefined;
29
23
  };
30
24
  export const getStyles = values => {
31
25
  const returnValue = {};
@@ -1 +1 @@
1
- {"version":3,"names":["ColorScheme","Orientation","isUnistylesMq","parseMq","UnistylesState","keyInObject","reduceObject","schemeToTheme","scheme","Dark","Light","assignSecrets","object","secrets","Math","random","toString","slice","extractSecrets","Object","entries","reduce","acc","key","value","startsWith","push","getStyles","values","returnValue","defineProperties","enumerable","configurable","isInDocument","element","document","body","contains","extractMediaQueryValue","query","_","px","match","undefined","Number","isNaN","getMediaQuery","includes","minWidth","maxWidth","minHeight","maxHeight","filter","Boolean","join","breakpoints","extractUnistyleDependencies","dependencies","uni__dependencies","Array","isArray"],"sourceRoot":"../../../../src","sources":["web/utils/unistyle.ts"],"mappings":";;AACA,SAASA,WAAW,EAAEC,WAAW,QAAQ,mBAAmB;AAE5D,SAASC,aAAa,EAAEC,OAAO,QAAQ,UAAU;AACjD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AC;AAED,OAAO,MAAMQ,2BAA2B,GAAIhC,KAAU,IAAK;EACvD,IAAI,CAACA,KAAK,EAAE;IACR,OAAO,EAAE;EACb;EAEA,MAAMiC,YAAuC,GAAGpD,WAAW,CAACmB,KAAK,EAAE,mBAAmB,CAAC,GAAGA,KAAK,CAACkC,iBAAiB,GAAG,EAAE;EAEtH,OAAOC,KAAK,CAACC,OAAO,CAACH,YAAY,CAAC,GAAGA,YAAY,GAAG,EAAE;AAC1D,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["ColorScheme","Orientation","isUnistylesMq","parseMq","UnistylesState","keyInObject","reduceObject","schemeToTheme","scheme","Dark","Light","assignSecrets","object","secrets","__uni__secrets__","extractSecrets","undefined","getStyles","values","returnValue","Object","defineProperties","value","enumerable","configurable","isInDocument","element","document","body","contains","extractMediaQueryValue","query","_","px","match","Number","isNaN","getMediaQuery","includes","minWidth","maxWidth","minHeight","maxHeight","filter","Boolean","join","breakpoints","extractUnistyleDependencies","dependencies","uni__dependencies","Array","isArray"],"sourceRoot":"../../../../src","sources":["web/utils/unistyle.ts"],"mappings":";;AACA,SAASA,WAAW,EAAEC,WAAW,QAAQ,mBAAmB;AAE5D,SAASC,aAAa,EAAEC,OAAO,QAAQ,UAAU;AACjD,SAASC,cAAc,QAAQ,UAAU;AACzC,SAASC,WAAW,EAAEC,YAAY,QAAQ,UAAU;AAEpD,OAAO,MAAMC,aAAa,GAAIC,MAAmB,IAAK;EAClD,QAAQA,MAAM;IACV,KAAKR,WAAW,CAACS,IAAI;MACjB,OAAO,MAAM;IACjB,KAAKT,WAAW,CAACU,KAAK;IACtB;MACI,OAAO,OAAO;EACtB;AACJ,CAAC;AAUD,OAAO,MAAMC,aAAa,GAAGA,CAAIC,MAAS,EAAEC,OAAwB,KAAK;EACrE;EACAD,MAAM,CAACE,gBAAgB,GAAGD,OAAO;EAEjC,OAAOD,MAAM;AACjB,CAAC;AAED,OAAO,MAAMG,cAAc,GAAIH,MAAW,IAAK;EAC3C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QAAQ,GAAG,eAAeA,QAAQ,KAAK,GAAGxB,SAAS,EACnDyB,SAAS,GAAG,gBAAgBA,SAAS,KAAK,GAAGzB,SAAS,EACtD0B,SAAS,GAAG,gBAAgBA,SAAS,KAAK,GAAG1B,SAAS,CACzD,CAAC2B,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,OAAO,CAAC;EACnC;EAEA,MAAMN,QAAQ,GAAGnC,cAAc,CAAC0C,WAAW,IAAIzC,WAAW,CAACD,cAAc,CAAC0C,WAAW,EAAEf,KAAK,CAAC,GAAG3B,cAAc,CAAC0C,WAAW,CAACf,KAAK,CAAC,GAAGf,SAAS;EAE7I,OAAO,eAAeuB,QAAQ,IAAI,CAAC,KAAK;AAC5C,CAAC;AAED,OAAO,MAAMQ,2BAA2B,GAAIzB,KAAU,IAAK;EACvD,IAAI,CAACA,KAAK,EAAE;IACR,OAAO,EAAE;EACb;EAEA,MAAM0B,YAAuC,GAAG3C,WAAW,CAACiB,KAAK,EAAE,mBAAmB,CAAC,GAAGA,KAAK,CAAC2B,iBAAiB,GAAG,EAAE;EAEtH,OAAOC,KAAK,CAACC,OAAO,CAACH,YAAY,CAAC,GAAGA,YAAY,GAAG,EAAE;AAC1D,CAAC","ignoreList":[]}
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
+ import { type PressableStateCallbackType } from 'react-native';
2
3
  import type { PressableProps as Props, View } from 'react-native';
3
4
  export declare const Pressable: React.ForwardRefExoticComponent<Props & {
4
- rawStyle?: Array<any>;
5
+ rawStyle?: Array<any> | ((event: PressableStateCallbackType) => Array<any>);
5
6
  variants?: Record<string, string | boolean>;
6
7
  } & React.RefAttributes<View>>;
7
8
  //# sourceMappingURL=Pressable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Pressable.d.ts","sourceRoot":"","sources":["../../../../src/components/Pressable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAA;AAEjD,OAAO,KAAK,EAAE,cAAc,IAAI,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AASjE,eAAO,MAAM,SAAS;eAJP,KAAK,CAAC,GAAG,CAAC;eACV,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;8BA4F7C,CAAA"}
1
+ {"version":3,"file":"Pressable.d.ts","sourceRoot":"","sources":["../../../../src/components/Pressable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAA;AACjD,OAAO,EAA2C,KAAK,0BAA0B,EAAE,MAAM,cAAc,CAAA;AACvG,OAAO,KAAK,EAAE,cAAc,IAAI,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AASjE,eAAO,MAAM,SAAS;eAJP,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,0BAA0B,KAAK,KAAK,CAAC,GAAG,CAAC,CAAC;eAChE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;8BAgF7C,CAAA"}
@@ -5,9 +5,10 @@ type WebPressableState = {
5
5
  hovered: boolean;
6
6
  focused: boolean;
7
7
  };
8
+ type WebPressableStyle = ((state: WebPressableState) => ViewStyle) | ViewStyle;
8
9
  export declare const Pressable: React.ForwardRefExoticComponent<Props & {
9
10
  variants?: Record<string, string | boolean>;
10
- style?: ((state: WebPressableState) => ViewStyle) | ViewStyle;
11
+ style?: WebPressableStyle;
11
12
  } & React.RefAttributes<View>>;
12
13
  export {};
13
14
  //# sourceMappingURL=Pressable.web.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Pressable.web.d.ts","sourceRoot":"","sources":["../../../../src/components/Pressable.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwC,MAAM,OAAO,CAAA;AAE5D,OAAO,KAAK,EAAE,cAAc,IAAI,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAG5E,KAAK,iBAAiB,GAAG;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAA;CACnB,CAAA;AAsBD,eAAO,MAAM,SAAS;eAnBP,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;YACnC,CAAC,CAAC,KAAK,EAAE,iBAAiB,KAAK,SAAS,CAAC,GAAG,SAAS;8BAyF/D,CAAA"}
1
+ {"version":3,"file":"Pressable.web.d.ts","sourceRoot":"","sources":["../../../../src/components/Pressable.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwC,MAAM,OAAO,CAAA;AAE5D,OAAO,KAAK,EAAE,cAAc,IAAI,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAG5E,KAAK,iBAAiB,GAAG;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,KAAK,iBAAiB,GAAG,CAAC,CAAC,KAAK,EAAE,iBAAiB,KAAK,SAAS,CAAC,GAAG,SAAS,CAAA;AA4D9E,eAAO,MAAM,SAAS;eAzDP,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;YACnC,iBAAiB;8BAiH3B,CAAA"}
@@ -9,7 +9,7 @@ declare class UnistylesShadowRegistryBuilder {
9
9
  private resultsMap;
10
10
  private hashMap;
11
11
  private classNamesMap;
12
- add: (ref: any, _style: Array<Style>, _variants: Record<string, any> | undefined, _args: Array<Array<any>>) => string[] | undefined;
12
+ add: (ref: any, styles: Array<Style>, _variants: Record<string, any> | undefined, _args: Array<Array<any>>) => string[] | undefined;
13
13
  remove: () => void;
14
14
  }
15
15
  export declare const UnistylesShadowRegistry: UnistylesShadowRegistryBuilder;
@@ -1 +1 @@
1
- {"version":3,"file":"shadowRegistry.d.ts","sourceRoot":"","sources":["../../../../src/web/shadowRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,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MAAM,aAAW;CACpB;AAED,eAAO,MAAM,uBAAuB,gCAAuC,CAAA"}
@@ -10,7 +10,7 @@ export type UnistyleSecrets = {
10
10
  __uni__args?: Array<any>;
11
11
  };
12
12
  export declare const assignSecrets: <T>(object: T, secrets: UnistyleSecrets) => T;
13
- export declare const extractSecrets: (object: any) => UnistyleSecrets[];
13
+ export declare const extractSecrets: (object: any) => UnistyleSecrets | undefined;
14
14
  export declare const getStyles: (values: UnistylesValues) => {};
15
15
  export declare const isInDocument: (element: HTMLElement) => boolean;
16
16
  export declare const extractMediaQueryValue: (query: string) => number | undefined;
@@ -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;AAKpG,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,EAAE,GAAG,CAAC,WAAW,CAAC,CAAA;IAC7B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACpC,WAAW,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,CAAC,UAAU,CAAC,WAAW,eAAe,MAKnE,CAAA;AAED,eAAO,MAAM,cAAc,WAAY,GAAG,sBAUzC,CAAA;AAED,eAAO,MAAM,SAAS,WAAY,eAAe,OAUhD,CAAA;AAED,eAAO,MAAM,YAAY,YAAa,WAAW,YAAoC,CAAA;AAErF,eAAO,MAAM,sBAAsB,UAAW,MAAM,uBAYnD,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAmB1C,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;AAKpG,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,EAAE,GAAG,CAAC,WAAW,CAAC,CAAA;IAC7B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACpC,WAAW,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,CAAC,UAAU,CAAC,WAAW,eAAe,MAKnE,CAAA;AAED,eAAO,MAAM,cAAc,WAAY,GAAG,gCAEzC,CAAA;AAED,eAAO,MAAM,SAAS,WAAY,eAAe,OAUhD,CAAA;AAED,eAAO,MAAM,YAAY,YAAa,WAAW,YAAoC,CAAA;AAErF,eAAO,MAAM,sBAAsB,UAAW,MAAM,uBAYnD,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAmB1C,CAAA;AAED,eAAO,MAAM,2BAA2B,UAAW,GAAG,yBAQrD,CAAA"}
@@ -28,7 +28,7 @@ namespace margelo::nitro::unistyles {
28
28
  [[maybe_unused]]
29
29
  ColorScheme toCpp() const {
30
30
  static const auto clazz = javaClassStatic();
31
- static const auto fieldOrdinal = clazz->getField<int>("ordinal");
31
+ static const auto fieldOrdinal = clazz->getField<int>("_ordinal");
32
32
  int ordinal = this->getFieldValue(fieldOrdinal);
33
33
  return static_cast<ColorScheme>(ordinal);
34
34
  }
@@ -28,7 +28,7 @@ namespace margelo::nitro::unistyles {
28
28
  [[maybe_unused]]
29
29
  Orientation toCpp() const {
30
30
  static const auto clazz = javaClassStatic();
31
- static const auto fieldOrdinal = clazz->getField<int>("ordinal");
31
+ static const auto fieldOrdinal = clazz->getField<int>("_ordinal");
32
32
  int ordinal = this->getFieldValue(fieldOrdinal);
33
33
  return static_cast<Orientation>(ordinal);
34
34
  }
@@ -28,7 +28,7 @@ namespace margelo::nitro::unistyles {
28
28
  [[maybe_unused]]
29
29
  UnistyleDependency toCpp() const {
30
30
  static const auto clazz = javaClassStatic();
31
- static const auto fieldOrdinal = clazz->getField<int>("ordinal");
31
+ static const auto fieldOrdinal = clazz->getField<int>("_ordinal");
32
32
  int ordinal = this->getFieldValue(fieldOrdinal);
33
33
  return static_cast<UnistyleDependency>(ordinal);
34
34
  }
@@ -18,5 +18,9 @@ import com.facebook.proguard.annotations.DoNotStrip
18
18
  enum class ColorScheme {
19
19
  DARK,
20
20
  LIGHT,
21
- UNSPECIFIED
21
+ UNSPECIFIED;
22
+
23
+ @DoNotStrip
24
+ @Keep
25
+ private val _ordinal = ordinal
22
26
  }
@@ -17,5 +17,9 @@ import com.facebook.proguard.annotations.DoNotStrip
17
17
  @Keep
18
18
  enum class Orientation {
19
19
  PORTRAIT,
20
- LANDSCAPE
20
+ LANDSCAPE;
21
+
22
+ @DoNotStrip
23
+ @Keep
24
+ private val _ordinal = ordinal
21
25
  }
@@ -30,5 +30,9 @@ enum class UnistyleDependency {
30
30
  FONTSCALE,
31
31
  STATUSBAR,
32
32
  NAVIGATIONBAR,
33
- IME
33
+ IME;
34
+
35
+ @DoNotStrip
36
+ @Keep
37
+ private val _ordinal = ordinal
34
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.0.0-alpha.43",
3
+ "version": "3.0.0-alpha.45",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -69,11 +69,11 @@
69
69
  "husky": "9.1.7",
70
70
  "jest": "29.7.0",
71
71
  "metro-react-native-babel-preset": "0.77.0",
72
- "nitro-codegen": "0.17.0",
72
+ "nitro-codegen": "0.18.0",
73
73
  "react": "18.3.1",
74
74
  "react-native": "0.76.3",
75
75
  "react-native-builder-bob": "0.33.1",
76
- "react-native-nitro-modules": "0.17.0",
76
+ "react-native-nitro-modules": "0.18.0",
77
77
  "react-native-web": "0.19.13",
78
78
  "react-test-renderer": "18.3.1",
79
79
  "release-it": "17.6.0",
package/plugin/index.js CHANGED
@@ -131,7 +131,7 @@ module.exports = function ({ types: t }) {
131
131
  return
132
132
  }
133
133
 
134
- const metadata = getStyleMetadata(t, styleAttr.value.expression)
134
+ const metadata = getStyleMetadata(t, styleAttr.value.expression, null, state)
135
135
 
136
136
  if (openingElementName === 'Pressable') {
137
137
  return handlePressable(t, path, styleAttr, metadata, state)
package/plugin/style.js CHANGED
@@ -1,4 +1,4 @@
1
- function getStyleMetadata(t, node, dynamicFunction = null) {
1
+ function getStyleMetadata(t, node, dynamicFunction = null, state) {
2
2
  // {styles.container}
3
3
  if (t.isMemberExpression(node)) {
4
4
  const members = t.isMemberExpression(node.object)
@@ -18,12 +18,12 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
18
18
 
19
19
  // [styles.container]
20
20
  if (t.isArrayExpression(node)) {
21
- return node.elements.flatMap(element => getStyleMetadata(t, element))
21
+ return node.elements.flatMap(element => getStyleMetadata(t, element, null, state))
22
22
  }
23
23
 
24
24
  // [...styles.container]
25
25
  if (t.isSpreadElement(node)) {
26
- return getStyleMetadata(t, node.argument)
26
+ return getStyleMetadata(t, node.argument, null, state)
27
27
  }
28
28
 
29
29
  // {{ ...styles.container }}
@@ -42,14 +42,14 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
42
42
  }]
43
43
  }
44
44
 
45
- return getStyleMetadata(t, prop.argument)
45
+ return getStyleMetadata(t, prop.argument, null, state)
46
46
  })
47
47
  .filter(Boolean)
48
48
  }
49
49
 
50
50
  // {styles.container(arg1, arg2)}
51
51
  if (t.isCallExpression(node)) {
52
- return getStyleMetadata(t, node.callee, node)
52
+ return getStyleMetadata(t, node.callee, node, state)
53
53
  }
54
54
 
55
55
  if (t.isIdentifier(node)) {
@@ -73,7 +73,7 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
73
73
  }
74
74
 
75
75
  if (t.isArrowFunctionExpression(node)) {
76
- return getStyleMetadata(t, node.body, node)
76
+ return getStyleMetadata(t, node.body, node, state)
77
77
  }
78
78
 
79
79
  // {condition && styles.container}
@@ -87,6 +87,15 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
87
87
  }]
88
88
  }
89
89
 
90
+ // only when pressable is used
91
+ if (t.isBlockStatement(node) && state.file.shouldIncludePressable) {
92
+ const returnStatement = node.body.find(t.isReturnStatement)
93
+
94
+ return returnStatement
95
+ ? getStyleMetadata(t, returnStatement.argument, null, state)
96
+ : []
97
+ }
98
+
90
99
  return []
91
100
  }
92
101
 
@@ -132,7 +141,7 @@ function styleAttributeToArray(t, path) {
132
141
  styleAttribute.value.expression = t.arrayExpression([styleAttribute.value.expression])
133
142
  }
134
143
 
135
- function metadataToRawStyle(t, metadata) {
144
+ function metadataToRawStyle(t, metadata, styleExpression) {
136
145
  const expressions = []
137
146
 
138
147
  metadata.forEach(meta => {
@@ -149,16 +158,43 @@ function metadataToRawStyle(t, metadata) {
149
158
  }
150
159
 
151
160
  if (meta.logicalExpression) {
152
- if (t.isIdentifier(meta.logicalExpression.left)) {
153
- if (t.isMemberExpression(meta.logicalExpression.right)) {
154
- return expressions.push(meta.logicalExpression.right)
161
+ const expression = t.cloneNode(meta.logicalExpression)
162
+
163
+ if (t.isIdentifier(expression.left)) {
164
+ if (t.isCallExpression(expression.right)) {
165
+ expression.right = expression.right.callee
155
166
  }
156
167
 
157
- expressions.push(meta.logicalExpression.right.callee)
168
+ expressions.push(expression)
169
+ }
170
+ }
171
+
172
+ if (meta.conditionalExpression) {
173
+ const expression = t.cloneNode(meta.conditionalExpression)
174
+
175
+ if (t.isCallExpression(expression.alternate)) {
176
+ expression.alternate = expression.alternate.callee
177
+ }
178
+
179
+ if (t.isCallExpression(expression.consequent)) {
180
+ expression.consequent = expression.consequent.callee
158
181
  }
182
+
183
+ expressions.push(expression)
159
184
  }
160
185
  })
161
186
 
187
+ if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length === 1) {
188
+ return t.jsxAttribute(
189
+ t.jsxIdentifier('rawStyle'),
190
+ t.jsxExpressionContainer(
191
+ t.arrowFunctionExpression(styleExpression.params, t.arrayExpression([
192
+ ...expressions
193
+ ])
194
+ ))
195
+ )
196
+ }
197
+
162
198
  return t.jsxAttribute(
163
199
  t.jsxIdentifier('rawStyle'),
164
200
  t.jsxExpressionContainer(t.arrayExpression([
@@ -181,6 +217,7 @@ function wrapInGetBoundArgs(t, toWrap, extraArgs) {
181
217
 
182
218
  function handlePressableFromMemberExpression(t, path, metadata, wrapInArrowFunction) {
183
219
  let expression = undefined
220
+ let args = []
184
221
 
185
222
  const members = metadata.at(0).members
186
223
 
@@ -194,11 +231,20 @@ function handlePressableFromMemberExpression(t, path, metadata, wrapInArrowFunct
194
231
  expression = metadata.at(0)
195
232
  }
196
233
 
234
+ if (t.isCallExpression(metadata.at(0))) {
235
+ expression = metadata.at(0).callee
236
+ args = metadata.at(0).arguments
237
+ }
238
+
197
239
  if (!expression) {
198
240
  return
199
241
  }
200
242
 
201
- const bindCall = wrapInGetBoundArgs(t , expression, wrapInArrowFunction ? [t.identifier("state")] : [])
243
+ const bindCall = wrapInGetBoundArgs(t , expression, wrapInArrowFunction ? [t.identifier("state")] : args)
244
+
245
+ if (t.isCallExpression(metadata.at(0))) {
246
+ return bindCall
247
+ }
202
248
 
203
249
  if (!wrapInArrowFunction) {
204
250
  return t.conditionalExpression(
@@ -240,12 +286,18 @@ function handlePressableArgs(t, path, styleExpression, metadata, parentWrapper,
240
286
  return
241
287
  }
242
288
 
243
- if (t.isMemberExpression(wrapper)) {
289
+ if (t.isMemberExpression(wrapper) && t.isArrayExpression(parentWrapper)) {
244
290
  parentWrapper.elements[index] = handlePressableFromMemberExpression(t, path, [metadata[index]])
245
291
 
246
292
  return
247
293
  }
248
294
 
295
+ if (t.isMemberExpression(wrapper) && !t.isArrayExpression(parentWrapper)) {
296
+ parentWrapper = handlePressableFromMemberExpression(t, path, metadata)
297
+
298
+ return
299
+ }
300
+
249
301
  if (t.isLogicalExpression(wrapper)) {
250
302
  if (t.isIdentifier(wrapper.left) && t.isMemberExpression(wrapper.right)) {
251
303
  parentWrapper.elements[index].right = handlePressableFromMemberExpression(t, path, [parentWrapper.elements[index].right])
@@ -256,18 +308,30 @@ function handlePressableArgs(t, path, styleExpression, metadata, parentWrapper,
256
308
  return
257
309
  }
258
310
 
259
- if (t.isConditionalExpression(wrapper)) {
260
- if (t.isMemberExpression(wrapper.alternate)) {
311
+ if (t.isConditionalExpression(wrapper) && t.isArrayExpression(parentWrapper)) {
312
+ if (t.isMemberExpression(wrapper.alternate) || t.isCallExpression(wrapper.alternate)) {
261
313
  parentWrapper.elements[index].alternate = handlePressableFromMemberExpression(t, path, [parentWrapper.elements[index].alternate])
262
314
  }
263
315
 
264
- if (t.isMemberExpression(wrapper.consequent)) {
316
+ if (t.isMemberExpression(wrapper.consequent) || t.isCallExpression(wrapper.consequent)) {
265
317
  parentWrapper.elements[index].consequent = handlePressableFromMemberExpression(t, path, [parentWrapper.elements[index].consequent])
266
318
  }
267
319
 
268
320
  return
269
321
  }
270
322
 
323
+ if (t.isConditionalExpression(wrapper) && !t.isArrayExpression(parentWrapper)) {
324
+ if (t.isMemberExpression(wrapper.alternate) || t.isCallExpression(wrapper.alternate)) {
325
+ parentWrapper.alternate = handlePressableFromMemberExpression(t, path, [parentWrapper.alternate])
326
+ }
327
+
328
+ if (t.isMemberExpression(wrapper.consequent) || t.isCallExpression(wrapper.consequent)) {
329
+ parentWrapper.consequent = handlePressableFromMemberExpression(t, path, [parentWrapper.consequent])
330
+ }
331
+
332
+ return
333
+ }
334
+
271
335
  const pressableArgs = t.isCallExpression(wrapper)
272
336
  ? wrapper.arguments
273
337
  : wrapper.argument.arguments
@@ -307,7 +371,7 @@ function handlePressable(t, path, styleAttr, metadata, state) {
307
371
  }
308
372
 
309
373
  // add raw C++ style as prop to be bound
310
- path.node.openingElement.attributes.push(metadataToRawStyle(t, metadata))
374
+ path.node.openingElement.attributes.push(metadataToRawStyle(t, metadata, styleAttr.value.expression))
311
375
 
312
376
  const styleExpression = styleAttr.value.expression
313
377
 
@@ -343,7 +407,7 @@ function handlePressable(t, path, styleAttr, metadata, state) {
343
407
 
344
408
  // {() => style.pressable(1, 2)}
345
409
  if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length === 0) {
346
- const parentWrapper = t.isBlockStatement(styleExpression.body)
410
+ let parentWrapper = t.isBlockStatement(styleExpression.body)
347
411
  ? styleExpression.body.body.find(node => t.isReturnStatement(node))
348
412
  : styleExpression.body
349
413
 
@@ -355,6 +419,12 @@ function handlePressable(t, path, styleAttr, metadata, state) {
355
419
  return parentWrapper.elements.forEach((wrapper, index) => handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, wrapper, index))
356
420
  }
357
421
 
422
+ if (t.isReturnStatement(parentWrapper)) {
423
+ parentWrapper = parentWrapper.argument
424
+
425
+ return handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, parentWrapper)
426
+ }
427
+
358
428
  const pressableArgs = t.isCallExpression(parentWrapper)
359
429
  ? parentWrapper.arguments
360
430
  : parentWrapper.argument.arguments
@@ -387,12 +457,16 @@ function handlePressable(t, path, styleAttr, metadata, state) {
387
457
  if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length > 0) {
388
458
  // user used state with custom args we need to getBoundArgs
389
459
  // detect between arrow function with body and arrow function
390
- const parentWrapper = t.isBlockStatement(styleExpression.body)
460
+ let parentWrapper = t.isBlockStatement(styleExpression.body)
391
461
  ? styleExpression.body.body.find(node => t.isReturnStatement(node))
392
462
  : styleExpression.body
393
463
 
394
464
  if (t.isArrayExpression(parentWrapper)) {
395
- return parentWrapper.elements.forEach((wrapper, index) =>handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, wrapper, index))
465
+ return parentWrapper.elements.forEach((wrapper, index) => handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, wrapper, index))
466
+ }
467
+
468
+ if (t.isReturnStatement(parentWrapper)) {
469
+ parentWrapper = parentWrapper.argument
396
470
  }
397
471
 
398
472
  handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, parentWrapper)
@@ -44,7 +44,7 @@ function isUnistylesStyleSheet(t, path, state) {
44
44
 
45
45
  function addStyleSheetTag(t, path, state) {
46
46
  const callee = path.get('callee')
47
- const uniqueId = stringToUniqueId(state.filename) + ++state.file.tagNumber
47
+ const uniqueId = stringToUniqueId(state.filename.replace(state.cwd, '')) + ++state.file.tagNumber
48
48
 
49
49
  callee.container.arguments.push(t.numericLiteral(uniqueId))
50
50
  }
@@ -1,11 +1,11 @@
1
1
  import React, { forwardRef, useRef } from 'react'
2
- import { Pressable as NativePressableReactNative } from 'react-native'
2
+ import { Pressable as NativePressableReactNative, type PressableStateCallbackType } from 'react-native'
3
3
  import type { PressableProps as Props, View } from 'react-native'
4
4
  import { UnistylesShadowRegistry } from '../specs'
5
5
  import { getId } from '../core'
6
6
 
7
7
  type PressableProps = Props & {
8
- rawStyle?: Array<any>
8
+ rawStyle?: Array<any> | ((event: PressableStateCallbackType) => Array<any>)
9
9
  variants?: Record<string, string | boolean>
10
10
  }
11
11
 
@@ -36,18 +36,12 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ra
36
36
  const returnFn = typeof passedRef === 'function'
37
37
  ? passedRef(ref)
38
38
  : () => {}
39
- const unistyles = (rawStyle ?? [])
40
- .map((style, index) => {
41
- if (fnArgs[index]) {
42
- return style
43
- }
44
-
45
- return undefined
46
- })
47
- .filter(Boolean)
39
+ const unistyles = typeof rawStyle === 'function'
40
+ ? rawStyle({ pressed: false })
41
+ : (rawStyle ?? [])
48
42
 
49
43
  // @ts-expect-error - this is hidden from TS
50
- UnistylesShadowRegistry.add(ref, unistyles, variants, [...fnArgs])
44
+ UnistylesShadowRegistry.add(ref, unistyles, variants, Array.isArray(styleResult) ? fnArgs : [fnArgs])
51
45
 
52
46
  return () => {
53
47
  // @ts-expect-error - this is hidden from TS
@@ -71,21 +65,15 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ra
71
65
  .map(style => typeof style === 'function' ? style.getBoundArgs() : [])
72
66
  : []
73
67
  const pressId = getId()
74
- const unistyles = (rawStyle ?? [])
75
- .map((style, index) => {
76
- if (fnArgs[index]) {
77
- return style
78
- }
79
-
80
- return undefined
81
- })
82
- .filter(Boolean)
68
+ const unistyles = typeof rawStyle === 'function'
69
+ ? rawStyle(state)
70
+ : (rawStyle ?? [])
83
71
 
84
72
  if (storedRef.current) {
85
73
  // @ts-expect-error - this is hidden from TS
86
74
  UnistylesShadowRegistry.remove(storedRef.current)
87
75
  // @ts-expect-error - this is hidden from TS
88
- UnistylesShadowRegistry.add(storedRef.current, unistyles, variants, [...fnArgs], pressId)
76
+ UnistylesShadowRegistry.add(storedRef.current, unistyles, variants, Array.isArray(styleResult) ? fnArgs : [fnArgs], pressId)
89
77
  }
90
78
 
91
79
  return typeof styleResult === 'function'
@@ -9,9 +9,11 @@ type WebPressableState = {
9
9
  focused: boolean
10
10
  }
11
11
 
12
+ type WebPressableStyle = ((state: WebPressableState) => ViewStyle) | ViewStyle
13
+
12
14
  type PressableProps = Props & {
13
15
  variants?: Record<string, string | boolean>
14
- style?: ((state: WebPressableState) => ViewStyle) | ViewStyle,
16
+ style?: WebPressableStyle,
15
17
  }
16
18
 
17
19
  const initialState: WebPressableState = {
@@ -29,8 +31,46 @@ const events = {
29
31
  'blur': { focused: false }
30
32
  } satisfies Partial<Record<keyof HTMLElementEventMap, Partial<WebPressableState>>>
31
33
 
34
+ type UpdateStylesProps = {
35
+ ref: View | null,
36
+ style: WebPressableStyle,
37
+ variants?: Record<string, string | boolean>,
38
+ state: WebPressableState
39
+ }
40
+
41
+ const isFunctionWithBoundArgs = (fn: any): fn is Function & { getBoundArgs: Function } => {
42
+ return typeof fn === 'function' && 'getBoundArgs' in fn
43
+ }
44
+
45
+ const extractFunctionArgs = (styleResult: any) => {
46
+ return isFunctionWithBoundArgs(styleResult)
47
+ ? [styleResult.getBoundArgs()]
48
+ : Array.isArray(styleResult)
49
+ ? styleResult.map(style => isFunctionWithBoundArgs(style) ? style.getBoundArgs() : [])
50
+ : []
51
+ }
52
+
53
+ const extractStyleResult = (style: any) => {
54
+ return typeof style === 'function'
55
+ ? [style()]
56
+ : Array.isArray(style)
57
+ ? style.map(style => typeof style === 'function' ? style() : style)
58
+ : [style]
59
+ }
60
+
61
+ const updateStyles = ({ ref, style, variants, state }: UpdateStylesProps) => {
62
+ const styleResult = typeof style === 'function'
63
+ ? style(state)
64
+ : style
65
+ const fnArgs = extractFunctionArgs(styleResult)
66
+ const extractedResult = extractStyleResult(styleResult)
67
+
68
+ // @ts-expect-error - this is hidden from TS
69
+ UnistylesShadowRegistry.add(ref, extractedResult, variants, fnArgs)
70
+ }
71
+
32
72
  export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ...props }, passedRef) => {
33
- const storedRef = useRef<View | null>()
73
+ const storedRef = useRef<View | null>(null)
34
74
  const state = useRef<WebPressableState>(initialState)
35
75
  const styleRef = useRef(style)
36
76
 
@@ -42,19 +82,12 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
42
82
  const handler = (newState: Partial<WebPressableState>) => () => {
43
83
  state.current = { ...state.current, ...newState }
44
84
 
45
- const styleResult = typeof styleRef.current === 'function'
46
- ? styleRef.current(state.current)
47
- : styleRef.current
48
- const fnArgs = typeof styleResult === 'function'
49
- // @ts-expect-error - this is hidden from TS
50
- ? styleResult.getBoundArgs()
51
- : []
52
- const extractedResult = typeof styleResult === 'function'
53
- ? (styleResult as Function)()
54
- : styleResult
55
-
56
- // @ts-expect-error - this is hidden from TS
57
- UnistylesShadowRegistry.add(storedRef.current, [extractedResult], variants, [fnArgs])
85
+ updateStyles({
86
+ ref: storedRef.current,
87
+ style: styleRef.current as WebPressableStyle,
88
+ variants,
89
+ state: state.current
90
+ })
58
91
  }
59
92
 
60
93
  if (!storedRef.current) {
@@ -80,23 +113,16 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
80
113
  {...props}
81
114
  ref={ref => {
82
115
  storedRef.current = ref
83
- const styleResult = typeof style === 'function'
84
- ? style(initialState)
85
- : style
86
- const fnArgs = typeof styleResult === 'function'
87
- // @ts-expect-error - this is hidden from TS
88
- ? styleResult.getBoundArgs()
89
- : []
90
- const extractedResult = typeof styleResult === 'function'
91
- ? (styleResult as Function)()
92
- : styleResult
116
+ updateStyles({
117
+ ref,
118
+ style: style as WebPressableStyle,
119
+ variants,
120
+ state: initialState
121
+ })
93
122
 
94
123
  if (typeof passedRef === 'object' && passedRef !== null) {
95
124
  passedRef.current = ref
96
125
  }
97
-
98
- // @ts-expect-error - this is hidden from TS
99
- UnistylesShadowRegistry.add(ref, [extractedResult], variants, [fnArgs])
100
126
  }}
101
127
  />
102
128
  )