rn-css 1.6.4 → 1.6.5
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.
- package/dist/styleComponent.js +17 -20
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/styleComponent.tsx +17 -20
- package/src/types.ts +1 -0
package/dist/styleComponent.js
CHANGED
|
@@ -25,12 +25,19 @@ function buildCSSString(chunks, functs, props, shared) {
|
|
|
25
25
|
computedString += props.rnCSS.replace(/=/gm, ':') + ';';
|
|
26
26
|
return computedString;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
const hash = (0, generateHash_1.default)(css);
|
|
30
|
-
const rns = (0, cssToRN_1.default)(css);
|
|
28
|
+
function convertCSS(css, init) {
|
|
31
29
|
(0, cssToRN_1.default)(css);
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const hash = (0, generateHash_1.default)(css);
|
|
31
|
+
const style = styleMap[hash];
|
|
32
|
+
if (style) {
|
|
33
|
+
style.usages++;
|
|
34
|
+
return style;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const rns = (0, cssToRN_1.default)(css);
|
|
38
|
+
styleMap[hash] = { style: rns, usages: init ? 0 : 1, hash };
|
|
39
|
+
return styleMap[hash];
|
|
40
|
+
}
|
|
34
41
|
}
|
|
35
42
|
const styled = (Component) => {
|
|
36
43
|
const styledComponent = (chunks, ...functs) => {
|
|
@@ -40,28 +47,18 @@ const styled = (Component) => {
|
|
|
40
47
|
// Build the css string with the context
|
|
41
48
|
const css = react_1.default.useMemo(() => buildCSSString(chunks, functs, props, shared), [props, shared]);
|
|
42
49
|
// Store the style in RN format
|
|
43
|
-
const [rnStyle, setRNStyle] = react_1.default.useState(() =>
|
|
50
|
+
const [rnStyle, setRNStyle] = react_1.default.useState(() => convertCSS(css, true).style);
|
|
44
51
|
react_1.default.useEffect(() => {
|
|
45
52
|
// Try to load an existing style from the style map or save it for next time
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
if (style) {
|
|
49
|
-
setRNStyle(style.style);
|
|
50
|
-
style.usages++;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
const rns = (0, cssToRN_1.default)(css);
|
|
54
|
-
setRNStyle(rns);
|
|
55
|
-
styleMap[hash] = { style: rns, usages: 1 };
|
|
56
|
-
}
|
|
53
|
+
const style = convertCSS(css, false);
|
|
54
|
+
setRNStyle(style.style);
|
|
57
55
|
// When the style is not used anymore, we destroy it
|
|
58
56
|
return () => {
|
|
59
|
-
const style = styleMap[hash];
|
|
60
57
|
setTimeout(() => {
|
|
61
58
|
style.usages--;
|
|
62
59
|
if (style.usages <= 0)
|
|
63
|
-
delete styleMap[hash];
|
|
64
|
-
},
|
|
60
|
+
delete styleMap[style.hash];
|
|
61
|
+
}, 300);
|
|
65
62
|
};
|
|
66
63
|
}, [css]);
|
|
67
64
|
const { needsLayout, needsHover } = react_1.default.useMemo(() => ({
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
package/src/styleComponent.tsx
CHANGED
|
@@ -33,12 +33,19 @@ function buildCSSString<T extends { rnCSS?: string }> (chunks: TemplateStringsAr
|
|
|
33
33
|
if (props.rnCSS) computedString += props.rnCSS.replace(/=/gm, ':') + ';'
|
|
34
34
|
return computedString
|
|
35
35
|
}
|
|
36
|
-
function
|
|
37
|
-
const hash = calculHash(css)
|
|
38
|
-
const rns = cssToStyle(css)
|
|
36
|
+
function convertCSS (css: string, init?: boolean) {
|
|
39
37
|
cssToStyle(css)
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
const hash = calculHash(css)
|
|
39
|
+
const style = styleMap[hash]
|
|
40
|
+
if (style) {
|
|
41
|
+
style.usages++
|
|
42
|
+
return style
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const rns = cssToStyle(css)
|
|
46
|
+
styleMap[hash] = { style: rns, usages: init ? 0 : 1, hash }
|
|
47
|
+
return styleMap[hash]
|
|
48
|
+
}
|
|
42
49
|
}
|
|
43
50
|
const styled = <Props, >(Component: React.ComponentType<Props>) => {
|
|
44
51
|
const styledComponent = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & Props>)[]) => {
|
|
@@ -48,27 +55,17 @@ const styled = <Props, >(Component: React.ComponentType<Props>) => {
|
|
|
48
55
|
// Build the css string with the context
|
|
49
56
|
const css = React.useMemo(() => buildCSSString(chunks, functs, props, shared), [props, shared])
|
|
50
57
|
// Store the style in RN format
|
|
51
|
-
const [rnStyle, setRNStyle] = React.useState<Style>(() =>
|
|
58
|
+
const [rnStyle, setRNStyle] = React.useState<Style>(() => convertCSS(css, true).style)
|
|
52
59
|
React.useEffect(() => {
|
|
53
60
|
// Try to load an existing style from the style map or save it for next time
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
if (style) {
|
|
57
|
-
setRNStyle(style.style)
|
|
58
|
-
style.usages++
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
const rns = cssToStyle(css)
|
|
62
|
-
setRNStyle(rns)
|
|
63
|
-
styleMap[hash] = { style: rns, usages: 1 }
|
|
64
|
-
}
|
|
61
|
+
const style = convertCSS(css, false)
|
|
62
|
+
setRNStyle(style.style)
|
|
65
63
|
// When the style is not used anymore, we destroy it
|
|
66
64
|
return () => {
|
|
67
|
-
const style = styleMap[hash]
|
|
68
65
|
setTimeout(() => {
|
|
69
66
|
style.usages--
|
|
70
|
-
if (style.usages <= 0) delete styleMap[hash]
|
|
71
|
-
},
|
|
67
|
+
if (style.usages <= 0) delete styleMap[style.hash]
|
|
68
|
+
}, 300)
|
|
72
69
|
}
|
|
73
70
|
}, [css])
|
|
74
71
|
|