react-native-unistyles 3.0.0-alpha.43 → 3.0.0-alpha.44
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/commonjs/components/Pressable.js +6 -14
- package/lib/commonjs/components/Pressable.js.map +1 -1
- package/lib/commonjs/components/Pressable.web.js +35 -17
- package/lib/commonjs/components/Pressable.web.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js +49 -48
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/module/components/Pressable.js +6 -14
- package/lib/module/components/Pressable.js.map +1 -1
- package/lib/module/components/Pressable.web.js +35 -17
- package/lib/module/components/Pressable.web.js.map +1 -1
- package/lib/module/web/shadowRegistry.js +49 -48
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/typescript/src/components/Pressable.d.ts +2 -1
- package/lib/typescript/src/components/Pressable.d.ts.map +1 -1
- package/lib/typescript/src/components/Pressable.web.d.ts +2 -1
- package/lib/typescript/src/components/Pressable.web.d.ts.map +1 -1
- package/lib/typescript/src/web/shadowRegistry.d.ts +1 -1
- package/package.json +1 -1
- package/plugin/index.js +1 -1
- package/plugin/style.js +94 -20
- package/plugin/stylesheet.js +1 -1
- package/src/components/Pressable.tsx +10 -22
- package/src/components/Pressable.web.tsx +54 -28
- package/src/web/shadowRegistry.ts +47 -47
@@ -34,15 +34,12 @@ const Pressable = exports.Pressable = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
34
34
|
passedRef.current = ref;
|
35
35
|
}
|
36
36
|
const returnFn = typeof passedRef === 'function' ? passedRef(ref) : () => {};
|
37
|
-
const unistyles =
|
38
|
-
|
39
|
-
|
40
|
-
}
|
41
|
-
return undefined;
|
42
|
-
}).filter(Boolean);
|
37
|
+
const unistyles = typeof rawStyle === 'function' ? rawStyle({
|
38
|
+
pressed: false
|
39
|
+
}) : rawStyle ?? [];
|
43
40
|
|
44
41
|
// @ts-expect-error - this is hidden from TS
|
45
|
-
_specs.UnistylesShadowRegistry.add(ref, unistyles, variants, [
|
42
|
+
_specs.UnistylesShadowRegistry.add(ref, unistyles, variants, Array.isArray(styleResult) ? fnArgs : [fnArgs]);
|
46
43
|
return () => {
|
47
44
|
// @ts-expect-error - this is hidden from TS
|
48
45
|
_specs.UnistylesShadowRegistry.remove(ref);
|
@@ -59,17 +56,12 @@ const Pressable = exports.Pressable = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
59
56
|
// @ts-expect-error - this is hidden from TS
|
60
57
|
.map(style => typeof style === 'function' ? style.getBoundArgs() : []) : [];
|
61
58
|
const pressId = (0, _core.getId)();
|
62
|
-
const unistyles = (rawStyle ?? []
|
63
|
-
if (fnArgs[index]) {
|
64
|
-
return style;
|
65
|
-
}
|
66
|
-
return undefined;
|
67
|
-
}).filter(Boolean);
|
59
|
+
const unistyles = typeof rawStyle === 'function' ? rawStyle(state) : rawStyle ?? [];
|
68
60
|
if (storedRef.current) {
|
69
61
|
// @ts-expect-error - this is hidden from TS
|
70
62
|
_specs.UnistylesShadowRegistry.remove(storedRef.current);
|
71
63
|
// @ts-expect-error - this is hidden from TS
|
72
|
-
_specs.UnistylesShadowRegistry.add(storedRef.current, unistyles, variants, [
|
64
|
+
_specs.UnistylesShadowRegistry.add(storedRef.current, unistyles, variants, Array.isArray(styleResult) ? fnArgs : [fnArgs], pressId);
|
73
65
|
}
|
74
66
|
return typeof styleResult === 'function'
|
75
67
|
// @ts-expect-error - this is hidden from TS
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_specs","_core","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","Pressable","exports","forwardRef","variants","style","rawStyle","props","passedRef","storedRef","useRef","jsx","ref","current","styleResult","pressed","fnArgs","getBoundArgs","Array","isArray","map","returnFn","unistyles","
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_specs","_core","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","Pressable","exports","forwardRef","variants","style","rawStyle","props","passedRef","storedRef","useRef","jsx","ref","current","styleResult","pressed","fnArgs","getBoundArgs","Array","isArray","map","returnFn","unistyles","UnistylesShadowRegistry","add","remove","state","pressId","getId"],"sourceRoot":"../../../src","sources":["components/Pressable.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAA+B,IAAAI,WAAA,GAAAJ,OAAA;AAAA,SAAAK,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAP,wBAAAO,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAA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,CAACC,GAAG,CAACf,SAAS,CAACI,OAAO,EAAES,SAAS,EAAElB,QAAQ,EAAEc,KAAK,CAACC,OAAO,CAACL,WAAW,CAAC,GAAGE,MAAM,GAAG,CAACA,MAAM,CAAC,EAAEW,OAAO,CAAC;MAChI;MAEA,OAAO,OAAOb,WAAW,KAAK;MAC1B;MAAA,EACEA,WAAW,CAACa,OAAO,CAAC,GACpBT,KAAK,CAACC,OAAO,CAACL,WAAW;MACvB;MAAA,EACEA,WAAW,CAACM,GAAG,CAACf,KAAK,IAAI,OAAOA,KAAK,KAAK,UAAU,GAAGA,KAAK,CAACsB,OAAO,CAAC,GAAGtB,KAAK,CAAC,GAC9ES,WAAW;IACzB;EAAE,CACL,CAAC;AAEV,CAAC,CAAC","ignoreList":[]}
|
@@ -35,12 +35,34 @@ const events = {
|
|
35
35
|
focused: false
|
36
36
|
}
|
37
37
|
};
|
38
|
+
const isFunctionWithBoundArgs = fn => {
|
39
|
+
return typeof fn === 'function' && 'getBoundArgs' in fn;
|
40
|
+
};
|
41
|
+
const extractFunctionArgs = styleResult => {
|
42
|
+
return isFunctionWithBoundArgs(styleResult) ? [styleResult.getBoundArgs()] : Array.isArray(styleResult) ? styleResult.map(style => isFunctionWithBoundArgs(style) ? style.getBoundArgs() : []) : [];
|
43
|
+
};
|
44
|
+
const extractStyleResult = style => {
|
45
|
+
return typeof style === 'function' ? [style()] : Array.isArray(style) ? style.map(style => typeof style === 'function' ? style() : style) : [style];
|
46
|
+
};
|
47
|
+
const updateStyles = ({
|
48
|
+
ref,
|
49
|
+
style,
|
50
|
+
variants,
|
51
|
+
state
|
52
|
+
}) => {
|
53
|
+
const styleResult = typeof style === 'function' ? style(state) : style;
|
54
|
+
const fnArgs = extractFunctionArgs(styleResult);
|
55
|
+
const extractedResult = extractStyleResult(styleResult);
|
56
|
+
|
57
|
+
// @ts-expect-error - this is hidden from TS
|
58
|
+
_specs.UnistylesShadowRegistry.add(ref, extractedResult, variants, fnArgs);
|
59
|
+
};
|
38
60
|
const Pressable = exports.Pressable = /*#__PURE__*/(0, _react.forwardRef)(({
|
39
61
|
variants,
|
40
62
|
style,
|
41
63
|
...props
|
42
64
|
}, passedRef) => {
|
43
|
-
const storedRef = (0, _react.useRef)();
|
65
|
+
const storedRef = (0, _react.useRef)(null);
|
44
66
|
const state = (0, _react.useRef)(initialState);
|
45
67
|
const styleRef = (0, _react.useRef)(style);
|
46
68
|
(0, _react.useEffect)(() => {
|
@@ -52,14 +74,12 @@ const Pressable = exports.Pressable = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
52
74
|
...state.current,
|
53
75
|
...newState
|
54
76
|
};
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
// @ts-expect-error - this is hidden from TS
|
62
|
-
_specs.UnistylesShadowRegistry.add(storedRef.current, [extractedResult], variants, [fnArgs]);
|
77
|
+
updateStyles({
|
78
|
+
ref: storedRef.current,
|
79
|
+
style: styleRef.current,
|
80
|
+
variants,
|
81
|
+
state: state.current
|
82
|
+
});
|
63
83
|
};
|
64
84
|
if (!storedRef.current) {
|
65
85
|
return;
|
@@ -80,17 +100,15 @@ const Pressable = exports.Pressable = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
80
100
|
...props,
|
81
101
|
ref: ref => {
|
82
102
|
storedRef.current = ref;
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
103
|
+
updateStyles({
|
104
|
+
ref,
|
105
|
+
style: style,
|
106
|
+
variants,
|
107
|
+
state: initialState
|
108
|
+
});
|
88
109
|
if (typeof passedRef === 'object' && passedRef !== null) {
|
89
110
|
passedRef.current = ref;
|
90
111
|
}
|
91
|
-
|
92
|
-
// @ts-expect-error - this is hidden from TS
|
93
|
-
_specs.UnistylesShadowRegistry.add(ref, [extractedResult], variants, [fnArgs]);
|
94
112
|
}
|
95
113
|
});
|
96
114
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_specs","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","initialState","pressed","hovered","focused","events","
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_specs","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","initialState","pressed","hovered","focused","events","isFunctionWithBoundArgs","fn","extractFunctionArgs","styleResult","getBoundArgs","Array","isArray","map","style","extractStyleResult","updateStyles","ref","variants","state","fnArgs","extractedResult","UnistylesShadowRegistry","add","Pressable","exports","forwardRef","props","passedRef","storedRef","useRef","styleRef","useEffect","current","handler","newState","entries","forEach","event","addEventListener","removeEventListener","jsx"],"sourceRoot":"../../../src","sources":["components/Pressable.web.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AAAkD,IAAAG,WAAA,GAAAH,OAAA;AAAA,SAAAI,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAN,wBAAAM,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,C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,CAACI,OAAO,GAAGhB,GAAG;MACvBD,YAAY,CAAC;QACTC,GAAG;QACHH,KAAK,EAAEA,KAA0B;QACjCI,QAAQ;QACRC,KAAK,EAAElB;MACX,CAAC,CAAC;MAEF,IAAI,OAAO2B,SAAS,KAAK,QAAQ,IAAIA,SAAS,KAAK,IAAI,EAAE;QACrDA,SAAS,CAACK,OAAO,GAAGhB,GAAG;MAC3B;IACJ;EAAE,CACL,CAAC;AAEV,CAAC,CAAC","ignoreList":[]}
|
@@ -22,16 +22,15 @@ class UnistylesShadowRegistryBuilder {
|
|
22
22
|
resultsMap = new Map();
|
23
23
|
hashMap = new Map();
|
24
24
|
classNamesMap = new Map();
|
25
|
-
add = (ref,
|
26
|
-
//
|
27
|
-
if (!
|
25
|
+
add = (ref, styles, _variants, _args) => {
|
26
|
+
// Styles are not provided
|
27
|
+
if (!styles) {
|
28
28
|
return;
|
29
29
|
}
|
30
30
|
|
31
31
|
// Ref is unmounted, remove style tags from the document
|
32
32
|
if (ref === null) {
|
33
|
-
|
34
|
-
secrets.forEach(({
|
33
|
+
(0, _utils2.extractSecrets)(styles).forEach(({
|
35
34
|
__uni__refs
|
36
35
|
}) => {
|
37
36
|
__uni__refs.forEach(ref => {
|
@@ -53,58 +52,60 @@ class UnistylesShadowRegistryBuilder {
|
|
53
52
|
if (!(ref instanceof HTMLElement)) {
|
54
53
|
return;
|
55
54
|
}
|
56
|
-
const
|
55
|
+
const parsedStyles = styles.flatMap((style, styleIndex) => {
|
56
|
+
const secrets = (0, _utils2.extractSecrets)(style);
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
}
|
62
|
-
const parsedStyles = styles.flatMap((style, styleIndex) => (0, _utils2.extractSecrets)(style).map(secret => {
|
63
|
-
const {
|
64
|
-
__uni__key,
|
65
|
-
__uni__stylesheet,
|
66
|
-
__uni__variants,
|
67
|
-
__uni__args = [],
|
68
|
-
__uni__refs
|
69
|
-
} = secret;
|
70
|
-
const newComputedStylesheet = _registry.UnistylesRegistry.getComputedStylesheet(__uni__stylesheet);
|
71
|
-
const style = newComputedStylesheet[__uni__key];
|
72
|
-
const variants = _variants && Object.keys(_variants).length > 0 ? _variants : __uni__variants;
|
73
|
-
const args = _args[styleIndex] && _args[styleIndex].length > 0 ? _args[styleIndex] : __uni__args;
|
74
|
-
const result = typeof style === 'function' ? style(...args) : style;
|
75
|
-
const {
|
76
|
-
variantsResult
|
77
|
-
} = Object.fromEntries((0, _variants2.getVariants)({
|
78
|
-
variantsResult: result
|
79
|
-
}, variants));
|
80
|
-
const resultWithVariants = (0, _utils.deepMergeObjects)(result, variantsResult ?? {});
|
81
|
-
const dependencies = (0, _utils2.extractUnistyleDependencies)(resultWithVariants);
|
82
|
-
if (typeof __uni__stylesheet === 'function') {
|
83
|
-
// Add dependencies from dynamic styles to stylesheet
|
84
|
-
_registry.UnistylesRegistry.addDependenciesToStylesheet(__uni__stylesheet, dependencies);
|
58
|
+
// Regular style
|
59
|
+
if (secrets.length === 0) {
|
60
|
+
return style;
|
85
61
|
}
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
const
|
96
|
-
const
|
97
|
-
const
|
62
|
+
return secrets.map(secret => {
|
63
|
+
const {
|
64
|
+
__uni__key,
|
65
|
+
__uni__stylesheet,
|
66
|
+
__uni__variants,
|
67
|
+
__uni__args = [],
|
68
|
+
__uni__refs
|
69
|
+
} = secret;
|
70
|
+
const newComputedStylesheet = _registry.UnistylesRegistry.getComputedStylesheet(__uni__stylesheet);
|
71
|
+
const style = newComputedStylesheet[__uni__key];
|
72
|
+
const variants = _variants && Object.keys(_variants).length > 0 ? _variants : __uni__variants;
|
73
|
+
const args = _args[styleIndex] && _args[styleIndex].length > 0 ? _args[styleIndex] : __uni__args;
|
74
|
+
const result = typeof style === 'function' ? style(...args) : style;
|
98
75
|
const {
|
99
76
|
variantsResult
|
100
77
|
} = Object.fromEntries((0, _variants2.getVariants)({
|
101
78
|
variantsResult: result
|
102
79
|
}, variants));
|
103
80
|
const resultWithVariants = (0, _utils.deepMergeObjects)(result, variantsResult ?? {});
|
104
|
-
|
81
|
+
const dependencies = (0, _utils2.extractUnistyleDependencies)(resultWithVariants);
|
82
|
+
if (typeof __uni__stylesheet === 'function') {
|
83
|
+
// Add dependencies from dynamic styles to stylesheet
|
84
|
+
_registry.UnistylesRegistry.addDependenciesToStylesheet(__uni__stylesheet, dependencies);
|
85
|
+
}
|
86
|
+
__uni__refs.add(ref);
|
87
|
+
const dispose = _listener.UnistylesListener.addListeners((0, _utils2.extractUnistyleDependencies)(resultWithVariants), () => {
|
88
|
+
const hash = this.hashMap.get(ref);
|
89
|
+
|
90
|
+
// Dispose listener if there is no hash
|
91
|
+
if (!hash) {
|
92
|
+
dispose();
|
93
|
+
return;
|
94
|
+
}
|
95
|
+
const newComputedStyleSheet = _registry.UnistylesRegistry.getComputedStylesheet(__uni__stylesheet);
|
96
|
+
const newValue = newComputedStyleSheet[__uni__key];
|
97
|
+
const result = typeof newValue === 'function' ? newValue(...args) : newValue;
|
98
|
+
const {
|
99
|
+
variantsResult
|
100
|
+
} = Object.fromEntries((0, _variants2.getVariants)({
|
101
|
+
variantsResult: result
|
102
|
+
}, variants));
|
103
|
+
const resultWithVariants = (0, _utils.deepMergeObjects)(result, variantsResult ?? {});
|
104
|
+
_registry.UnistylesRegistry.applyStyles(hash, (0, _convert.convertUnistyles)(resultWithVariants));
|
105
|
+
});
|
106
|
+
return resultWithVariants;
|
105
107
|
});
|
106
|
-
|
107
|
-
}));
|
108
|
+
});
|
108
109
|
const combinedStyles = (0, _utils.deepMergeObjects)(...parsedStyles);
|
109
110
|
const oldStyles = this.resultsMap.get(ref);
|
110
111
|
if ((0, _utils2.equal)(combinedStyles, oldStyles)) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_convert","require","_listener","_registry","_utils","_utils2","_variants2","UnistylesShadowRegistryBuilder","name","__type","equals","toString","dispose","resultsMap","Map","hashMap","classNamesMap","add","ref","
|
1
|
+
{"version":3,"names":["_convert","require","_listener","_registry","_utils","_utils2","_variants2","UnistylesShadowRegistryBuilder","name","__type","equals","toString","dispose","resultsMap","Map","hashMap","classNamesMap","add","ref","styles","_variants","_args","extractSecrets","forEach","__uni__refs","isInDocument","oldResult","get","delete","UnistylesRegistry","remove","HTMLElement","parsedStyles","flatMap","style","styleIndex","secrets","length","map","secret","__uni__key","__uni__stylesheet","__uni__variants","__uni__args","newComputedStylesheet","getComputedStylesheet","variants","Object","keys","args","result","variantsResult","fromEntries","getVariants","resultWithVariants","deepMergeObjects","dependencies","extractUnistyleDependencies","addDependenciesToStylesheet","UnistylesListener","addListeners","hash","newComputedStyleSheet","newValue","applyStyles","convertUnistyles","combinedStyles","oldStyles","equal","oldClassNames","className","classList","set","existingHash","injectedClassNames","_web","_classNames","newClassNames","Array","isArray","concat","UnistylesShadowRegistry","exports"],"sourceRoot":"../../../src","sources":["web/shadowRegistry.ts"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAIA,MAAMM,8BAA8B,CAAC;EACjC;EACAC,IAAI,GAAG,yBAAyB;EAChCC,MAAM,GAAG,KAAK;EACdC,MAAM,GAAGA,CAAA,KAAM,IAAI;EACnBC,QAAQ,GAAGA,CAAA,KAAM,yBAAyB;EAC1CC,OAAO,GAAGA,CAAA,KAAM,CAAC,CAAC;EAClB;;EAEQC,UAAU,GAAG,IAAIC,GAAG,CAA+B,CAAC;EACpDC,OAAO,GAAG,IAAID,GAAG,CAAsB,CAAC;EACxCE,aAAa,GAAG,IAAIF,GAAG,CAA6B,CAAC;EAE7DG,GAAG,GAAGA,CAACC,GAAQ,EAAEC,MAAoB,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AAI,EAAE;IAClE,MAAMC,aAAa,GAAG,CAACC,KAAK,CAACC,OAAO,CAACL,kBAAkB,CAAC,GAAGA,kBAAkB,GAAG,CAACA,kBAAkB,CAAC,EAAEM,MAAM,CAACnB,IAAI,CAAC;IAElH,IAAI,CAAC7C,aAAa,CAACwD,GAAG,CAACtD,GAAG,EAAE2D,aAAa,CAAC;IAC1C;IACA3D,GAAG,CAACqD,SAAS,CAACtD,GAAG,CAAC,GAAG4D,aAAa,CAAC;;IAEnC;IACA,IAAI,CAACJ,YAAY,EAAE;MACf,IAAI,CAAC1D,OAAO,CAACyD,GAAG,CAACtD,GAAG,EAAE2C,IAAI,CAAC;IAC/B;IAEA,OAAOgB,aAAa;EACxB,CAAC;EAED/C,MAAM,GAAGA,CAAA,KAAM,CAAC,CAAC;AACrB;AAEO,MAAMmD,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAG,IAAI1E,8BAA8B,CAAC,CAAC","ignoreList":[]}
|
@@ -28,15 +28,12 @@ export const Pressable = /*#__PURE__*/forwardRef(({
|
|
28
28
|
passedRef.current = ref;
|
29
29
|
}
|
30
30
|
const returnFn = typeof passedRef === 'function' ? passedRef(ref) : () => {};
|
31
|
-
const unistyles =
|
32
|
-
|
33
|
-
|
34
|
-
}
|
35
|
-
return undefined;
|
36
|
-
}).filter(Boolean);
|
31
|
+
const unistyles = typeof rawStyle === 'function' ? rawStyle({
|
32
|
+
pressed: false
|
33
|
+
}) : rawStyle ?? [];
|
37
34
|
|
38
35
|
// @ts-expect-error - this is hidden from TS
|
39
|
-
UnistylesShadowRegistry.add(ref, unistyles, variants, [
|
36
|
+
UnistylesShadowRegistry.add(ref, unistyles, variants, Array.isArray(styleResult) ? fnArgs : [fnArgs]);
|
40
37
|
return () => {
|
41
38
|
// @ts-expect-error - this is hidden from TS
|
42
39
|
UnistylesShadowRegistry.remove(ref);
|
@@ -53,17 +50,12 @@ export const Pressable = /*#__PURE__*/forwardRef(({
|
|
53
50
|
// @ts-expect-error - this is hidden from TS
|
54
51
|
.map(style => typeof style === 'function' ? style.getBoundArgs() : []) : [];
|
55
52
|
const pressId = getId();
|
56
|
-
const unistyles = (rawStyle ?? []
|
57
|
-
if (fnArgs[index]) {
|
58
|
-
return style;
|
59
|
-
}
|
60
|
-
return undefined;
|
61
|
-
}).filter(Boolean);
|
53
|
+
const unistyles = typeof rawStyle === 'function' ? rawStyle(state) : rawStyle ?? [];
|
62
54
|
if (storedRef.current) {
|
63
55
|
// @ts-expect-error - this is hidden from TS
|
64
56
|
UnistylesShadowRegistry.remove(storedRef.current);
|
65
57
|
// @ts-expect-error - this is hidden from TS
|
66
|
-
UnistylesShadowRegistry.add(storedRef.current, unistyles, variants, [
|
58
|
+
UnistylesShadowRegistry.add(storedRef.current, unistyles, variants, Array.isArray(styleResult) ? fnArgs : [fnArgs], pressId);
|
67
59
|
}
|
68
60
|
return typeof styleResult === 'function'
|
69
61
|
// @ts-expect-error - this is hidden from TS
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","forwardRef","useRef","Pressable","NativePressableReactNative","UnistylesShadowRegistry","getId","jsx","_jsx","variants","style","rawStyle","props","passedRef","storedRef","ref","current","styleResult","pressed","fnArgs","getBoundArgs","Array","isArray","map","returnFn","unistyles","
|
1
|
+
{"version":3,"names":["React","forwardRef","useRef","Pressable","NativePressableReactNative","UnistylesShadowRegistry","getId","jsx","_jsx","variants","style","rawStyle","props","passedRef","storedRef","ref","current","styleResult","pressed","fnArgs","getBoundArgs","Array","isArray","map","returnFn","unistyles","add","remove","state","pressId"],"sourceRoot":"../../../src","sources":["components/Pressable.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,MAAM,QAAQ,OAAO;AACjD,SAASC,SAAS,IAAIC,0BAA0B,QAAyC,cAAc;AAEvG,SAASC,uBAAuB,QAAQ,UAAU;AAClD,SAASC,KAAK,QAAQ,SAAS;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAO/B,OAAO,MAAML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,CAAC,GAAGnB,KAAK,CAAC,GAC9EO,WAAW;IACzB;EAAE,CACL,CAAC;AAEV,CAAC,CAAC","ignoreList":[]}
|
@@ -29,12 +29,34 @@ const events = {
|
|
29
29
|
focused: false
|
30
30
|
}
|
31
31
|
};
|
32
|
+
const isFunctionWithBoundArgs = fn => {
|
33
|
+
return typeof fn === 'function' && 'getBoundArgs' in fn;
|
34
|
+
};
|
35
|
+
const extractFunctionArgs = styleResult => {
|
36
|
+
return isFunctionWithBoundArgs(styleResult) ? [styleResult.getBoundArgs()] : Array.isArray(styleResult) ? styleResult.map(style => isFunctionWithBoundArgs(style) ? style.getBoundArgs() : []) : [];
|
37
|
+
};
|
38
|
+
const extractStyleResult = style => {
|
39
|
+
return typeof style === 'function' ? [style()] : Array.isArray(style) ? style.map(style => typeof style === 'function' ? style() : style) : [style];
|
40
|
+
};
|
41
|
+
const updateStyles = ({
|
42
|
+
ref,
|
43
|
+
style,
|
44
|
+
variants,
|
45
|
+
state
|
46
|
+
}) => {
|
47
|
+
const styleResult = typeof style === 'function' ? style(state) : style;
|
48
|
+
const fnArgs = extractFunctionArgs(styleResult);
|
49
|
+
const extractedResult = extractStyleResult(styleResult);
|
50
|
+
|
51
|
+
// @ts-expect-error - this is hidden from TS
|
52
|
+
UnistylesShadowRegistry.add(ref, extractedResult, variants, fnArgs);
|
53
|
+
};
|
32
54
|
export const Pressable = /*#__PURE__*/forwardRef(({
|
33
55
|
variants,
|
34
56
|
style,
|
35
57
|
...props
|
36
58
|
}, passedRef) => {
|
37
|
-
const storedRef = useRef();
|
59
|
+
const storedRef = useRef(null);
|
38
60
|
const state = useRef(initialState);
|
39
61
|
const styleRef = useRef(style);
|
40
62
|
useEffect(() => {
|
@@ -46,14 +68,12 @@ export const Pressable = /*#__PURE__*/forwardRef(({
|
|
46
68
|
...state.current,
|
47
69
|
...newState
|
48
70
|
};
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
// @ts-expect-error - this is hidden from TS
|
56
|
-
UnistylesShadowRegistry.add(storedRef.current, [extractedResult], variants, [fnArgs]);
|
71
|
+
updateStyles({
|
72
|
+
ref: storedRef.current,
|
73
|
+
style: styleRef.current,
|
74
|
+
variants,
|
75
|
+
state: state.current
|
76
|
+
});
|
57
77
|
};
|
58
78
|
if (!storedRef.current) {
|
59
79
|
return;
|
@@ -74,17 +94,15 @@ export const Pressable = /*#__PURE__*/forwardRef(({
|
|
74
94
|
...props,
|
75
95
|
ref: ref => {
|
76
96
|
storedRef.current = ref;
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
97
|
+
updateStyles({
|
98
|
+
ref,
|
99
|
+
style: style,
|
100
|
+
variants,
|
101
|
+
state: initialState
|
102
|
+
});
|
82
103
|
if (typeof passedRef === 'object' && passedRef !== null) {
|
83
104
|
passedRef.current = ref;
|
84
105
|
}
|
85
|
-
|
86
|
-
// @ts-expect-error - this is hidden from TS
|
87
|
-
UnistylesShadowRegistry.add(ref, [extractedResult], variants, [fnArgs]);
|
88
106
|
}
|
89
107
|
});
|
90
108
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","forwardRef","useEffect","useRef","Pressable","NativePressableReactNative","UnistylesShadowRegistry","jsx","_jsx","initialState","pressed","hovered","focused","events","
|
1
|
+
{"version":3,"names":["React","forwardRef","useEffect","useRef","Pressable","NativePressableReactNative","UnistylesShadowRegistry","jsx","_jsx","initialState","pressed","hovered","focused","events","isFunctionWithBoundArgs","fn","extractFunctionArgs","styleResult","getBoundArgs","Array","isArray","map","style","extractStyleResult","updateStyles","ref","variants","state","fnArgs","extractedResult","add","props","passedRef","storedRef","styleRef","current","handler","newState","Object","entries","forEach","event","addEventListener","removeEventListener"],"sourceRoot":"../../../src","sources":["components/Pressable.web.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAC5D,SAASC,SAAS,IAA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