rn-css 1.6.3 → 1.6.6

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.
@@ -11,12 +11,9 @@ const react_native_1 = require("react-native");
11
11
  const convertStyle_1 = __importDefault(require("./convertStyle"));
12
12
  const cssToRN_1 = __importDefault(require("./cssToRN"));
13
13
  const features_1 = require("./features");
14
- const generateHash_1 = __importDefault(require("./generateHash"));
15
14
  exports.defaultUnits = { em: 16, vw: 1, vh: 1, vmin: 1, vmax: 1, rem: 16, px: 1, pt: 72 / 96, in: 96, pc: 9, cm: 96 / 2.54, mm: 96 / 25.4 };
16
15
  exports.RemContext = react_1.default.createContext(exports.defaultUnits.rem);
17
16
  exports.FontSizeContext = react_1.default.createContext(exports.defaultUnits.em);
18
- // We use this to cache the computed styles
19
- const styleMap = {};
20
17
  // We use this to share value within the component (Theme, Translation, whatever)
21
18
  exports.SharedValue = react_1.default.createContext(undefined);
22
19
  function buildCSSString(chunks, functs, props, shared) {
@@ -25,13 +22,6 @@ function buildCSSString(chunks, functs, props, shared) {
25
22
  computedString += props.rnCSS.replace(/=/gm, ':') + ';';
26
23
  return computedString;
27
24
  }
28
- function initFromCSS(css) {
29
- const hash = (0, generateHash_1.default)(css);
30
- const rns = (0, cssToRN_1.default)(css);
31
- (0, cssToRN_1.default)(css);
32
- styleMap[hash] = { style: rns, usages: 0 };
33
- return rns;
34
- }
35
25
  const styled = (Component) => {
36
26
  const styledComponent = (chunks, ...functs) => {
37
27
  const ForwardRefComponent = react_1.default.forwardRef((props, ref) => {
@@ -40,29 +30,11 @@ const styled = (Component) => {
40
30
  // Build the css string with the context
41
31
  const css = react_1.default.useMemo(() => buildCSSString(chunks, functs, props, shared), [props, shared]);
42
32
  // Store the style in RN format
43
- const [rnStyle, setRNStyle] = react_1.default.useState(() => initFromCSS(css));
33
+ const [rnStyle, setRNStyle] = react_1.default.useState(() => (0, cssToRN_1.default)(css));
44
34
  react_1.default.useEffect(() => {
45
35
  // Try to load an existing style from the style map or save it for next time
46
- const hash = (0, generateHash_1.default)(css);
47
- const style = styleMap[hash];
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
- }
57
- // When the style is not used anymore, we destroy it
58
- return () => {
59
- const style = styleMap[hash];
60
- style.usages--;
61
- setTimeout(() => {
62
- if (style.usages <= 0)
63
- delete styleMap[hash];
64
- }, 3000);
65
- };
36
+ const style = (0, cssToRN_1.default)(css);
37
+ setRNStyle(style);
66
38
  }, [css]);
67
39
  const { needsLayout, needsHover } = react_1.default.useMemo(() => ({
68
40
  // needsFontSize: !!css.match(/\b(\d+)(\.\d+)?em\b/)
package/dist/types.d.ts CHANGED
@@ -79,9 +79,3 @@ export declare type Transform = {
79
79
  rotateY?: string;
80
80
  rotateZ?: string;
81
81
  };
82
- export declare type StyleMap = {
83
- [key: string]: {
84
- usages: number;
85
- style: Style;
86
- };
87
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-css",
3
- "version": "1.6.3",
3
+ "version": "1.6.6",
4
4
  "scripts": {
5
5
  "test": "jest",
6
6
  "prepare": "tsc",
@@ -5,16 +5,12 @@ import { FlatList, FlatListProps, LayoutChangeEvent, Platform, SectionList, Sect
5
5
  import convertStyle from './convertStyle'
6
6
  import cssToStyle from './cssToRN'
7
7
  import { useFontSize, useHover, useLayout, useScreenSize, useMediaQuery } from './features'
8
- import calculHash from './generateHash'
9
- import type { Style, StyleMap, Units } from './types'
8
+ import type { Style, Units } from './types'
10
9
 
11
10
  export const defaultUnits: Units = { em: 16, vw: 1, vh: 1, vmin: 1, vmax: 1, rem: 16, px: 1, pt: 72 / 96, in: 96, pc: 9, cm: 96 / 2.54, mm: 96 / 25.4 }
12
11
  export const RemContext = React.createContext<number>(defaultUnits.rem)
13
12
  export const FontSizeContext = React.createContext(defaultUnits.em)
14
13
 
15
- // We use this to cache the computed styles
16
- const styleMap: StyleMap = {}
17
-
18
14
  // We use this to share value within the component (Theme, Translation, whatever)
19
15
  export const SharedValue = React.createContext<unknown>(undefined)
20
16
 
@@ -33,13 +29,6 @@ function buildCSSString<T extends { rnCSS?: string }> (chunks: TemplateStringsAr
33
29
  if (props.rnCSS) computedString += props.rnCSS.replace(/=/gm, ':') + ';'
34
30
  return computedString
35
31
  }
36
- function initFromCSS (css: string) {
37
- const hash = calculHash(css)
38
- const rns = cssToStyle(css)
39
- cssToStyle(css)
40
- styleMap[hash] = { style: rns, usages: 0 }
41
- return rns
42
- }
43
32
  const styled = <Props, >(Component: React.ComponentType<Props>) => {
44
33
  const styledComponent = <S, >(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & Props>)[]) => {
45
34
  const ForwardRefComponent = React.forwardRef<React.ComponentType<S & Props & OptionalProps>, S & Props & OptionalProps>((props: S & Props & OptionalProps, ref) => {
@@ -48,28 +37,11 @@ const styled = <Props, >(Component: React.ComponentType<Props>) => {
48
37
  // Build the css string with the context
49
38
  const css = React.useMemo(() => buildCSSString(chunks, functs, props, shared), [props, shared])
50
39
  // Store the style in RN format
51
- const [rnStyle, setRNStyle] = React.useState<Style>(() => initFromCSS(css))
40
+ const [rnStyle, setRNStyle] = React.useState<Style>(() => cssToStyle(css))
52
41
  React.useEffect(() => {
53
42
  // Try to load an existing style from the style map or save it for next time
54
- const hash = calculHash(css)
55
- const style = styleMap[hash]
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
- }
65
- // When the style is not used anymore, we destroy it
66
- return () => {
67
- const style = styleMap[hash]
68
- style.usages--
69
- setTimeout(() => {
70
- if (style.usages <= 0) delete styleMap[hash]
71
- }, 3000)
72
- }
43
+ const style = cssToStyle(css)
44
+ setRNStyle(style)
73
45
  }, [css])
74
46
 
75
47
  const { needsLayout, needsHover } = React.useMemo(() => ({
package/src/types.ts CHANGED
@@ -85,10 +85,3 @@ export type Transform = {
85
85
  rotateY?: string;
86
86
  rotateZ?: string;
87
87
  }
88
-
89
- export type StyleMap = {
90
- [key: string]: {
91
- usages: number;
92
- style: Style;
93
- };
94
- }