rn-css 1.6.7 → 1.6.8

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/features.js CHANGED
@@ -68,7 +68,7 @@ const useLayout = (onLayout, needsLayout) => {
68
68
  exports.useLayout = useLayout;
69
69
  /** Apply the new fontSize to the component before we can calculate em units */
70
70
  const useFontSize = (fontSizeTarget, rem, em) => {
71
- const [fontSize, fontUnit] = react_1.default.useMemo(() => fontSizeTarget === undefined ? [fontSizeTarget] : (0, convertUnits_1.parseValue)(fontSizeTarget), [fontSizeTarget]);
71
+ const [fontSize, fontUnit] = react_1.default.useMemo(() => fontSizeTarget === undefined ? [] : (0, convertUnits_1.parseValue)(fontSizeTarget), [fontSizeTarget]);
72
72
  const isRelative = fontUnit && ['rem', 'em', '%'].includes(fontUnit);
73
73
  const newSize = react_1.default.useMemo(() => {
74
74
  if (fontSize && isRelative) {
@@ -79,16 +79,17 @@ const styled = (Component) => {
79
79
  const units = react_1.default.useMemo(() => ({ ...baseUnits, em }), [baseUnits, em]);
80
80
  const styleConvertedFromCSS = react_1.default.useMemo(() => (0, convertStyle_1.default)(finalStyle, units), [finalStyle, units]);
81
81
  const style = react_1.default.useMemo(() => [styleConvertedFromCSS, props.style], [props.style, styleConvertedFromCSS]);
82
+ const flatStyle = react_1.default.useMemo(() => react_native_1.StyleSheet.flatten(style), [style]);
82
83
  const newProps = react_1.default.useMemo(() => {
83
84
  const newProps = { style, onMouseEnter, onMouseLeave, onLayout };
84
- if (react_native_1.StyleSheet.flatten(style).textOverflow === 'ellipsis')
85
+ if (flatStyle.textOverflow === 'ellipsis')
85
86
  Object.assign(newProps, { numberOfLines: 1 });
86
87
  return newProps;
87
- }, [onLayout, onMouseEnter, onMouseLeave, style]);
88
+ }, [flatStyle.textOverflow, onLayout, onMouseEnter, onMouseLeave, style]);
88
89
  // The lines below can improve perfs, but it causes the component to remount when the font size changes
89
90
  // const currentFontSize = React.useContext(FontSizeContext)
90
91
  // if (em !== currentFontSize) {
91
- if (style.fontSize) {
92
+ if (flatStyle.fontSize) {
92
93
  return react_1.default.createElement(exports.FontSizeContext.Provider, { value: em },
93
94
  react_1.default.createElement(Component, { ref: ref, ...props, ...newProps }));
94
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-css",
3
- "version": "1.6.7",
3
+ "version": "1.6.8",
4
4
  "scripts": {
5
5
  "test": "jest",
6
6
  "prepare": "tsc",
package/src/features.tsx CHANGED
@@ -59,7 +59,7 @@ export const useLayout = (onLayout: undefined | ((event: LayoutChangeEvent) => v
59
59
 
60
60
  /** Apply the new fontSize to the component before we can calculate em units */
61
61
  export const useFontSize = (fontSizeTarget: string | undefined, rem: number, em: number): { em: number } => {
62
- const [fontSize, fontUnit] = React.useMemo(() => fontSizeTarget === undefined ? [fontSizeTarget] : parseValue(fontSizeTarget), [fontSizeTarget])
62
+ const [fontSize, fontUnit] = React.useMemo(() => fontSizeTarget === undefined ? [] : parseValue(fontSizeTarget), [fontSizeTarget])
63
63
  const isRelative = fontUnit && ['rem', 'em', '%'].includes(fontUnit)
64
64
  const newSize = React.useMemo(() => {
65
65
  if (fontSize && isRelative) {
@@ -91,16 +91,17 @@ const styled = <Props, >(Component: React.ComponentType<Props>) => {
91
91
 
92
92
  const styleConvertedFromCSS = React.useMemo(() => convertStyle(finalStyle, units), [finalStyle, units])
93
93
  const style: StyleProp<any> = React.useMemo(() => [styleConvertedFromCSS, props.style], [props.style, styleConvertedFromCSS])
94
+ const flatStyle = React.useMemo(() => StyleSheet.flatten(style), [style])
94
95
  const newProps = React.useMemo(() => {
95
96
  const newProps: OptionalProps = { style, onMouseEnter, onMouseLeave, onLayout }
96
- if (StyleSheet.flatten(style).textOverflow === 'ellipsis') Object.assign(newProps, { numberOfLines: 1 })
97
+ if (flatStyle.textOverflow === 'ellipsis') Object.assign(newProps, { numberOfLines: 1 })
97
98
  return newProps
98
- }, [onLayout, onMouseEnter, onMouseLeave, style])
99
+ }, [flatStyle.textOverflow, onLayout, onMouseEnter, onMouseLeave, style])
99
100
 
100
101
  // The lines below can improve perfs, but it causes the component to remount when the font size changes
101
102
  // const currentFontSize = React.useContext(FontSizeContext)
102
103
  // if (em !== currentFontSize) {
103
- if (style.fontSize) {
104
+ if (flatStyle.fontSize) {
104
105
  return <FontSizeContext.Provider value={em}>
105
106
  <Component ref={ref} {...props} {...newProps} />
106
107
  </FontSizeContext.Provider>