rn-css 1.5.3 → 1.5.4

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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertValue = exports.parseValue = void 0;
4
4
  const maths_1 = require("./cssToRN/maths");
5
+ const react_native_1 = require("react-native");
5
6
  /** Take a css value like 12em and return [12, 'em'] */
6
7
  function parseValue(value) {
7
8
  // Match a single unit
@@ -21,6 +22,8 @@ function convertValue(key, value, units) {
21
22
  // Percentage values need to rely on an other unit as reference
22
23
  const finalUnits = { ...units };
23
24
  if (value.includes('%')) {
25
+ if (react_native_1.Platform.OS === 'web')
26
+ return value;
24
27
  if (['marginTop', 'marginBottom', 'translateY'].includes(key))
25
28
  finalUnits['%'] = units.height / 100;
26
29
  else if (['marginLeft', 'marginRight', 'translateX'].includes(key))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-css",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "scripts": {
5
5
  "test": "jest",
6
6
  "prepare": "tsc",
@@ -1,5 +1,6 @@
1
1
  import type { PartialStyle, Transform, Units } from './types'
2
2
  import { calculate, min, max } from './cssToRN/maths'
3
+ import { Platform } from 'react-native'
3
4
 
4
5
  /** Take a css value like 12em and return [12, 'em'] */
5
6
  export function parseValue (value: string): [number, string | undefined] {
@@ -20,6 +21,7 @@ export function convertValue (key: keyof PartialStyle | keyof Transform, value:
20
21
  // Percentage values need to rely on an other unit as reference
21
22
  const finalUnits = { ...units }
22
23
  if (value.includes('%')) {
24
+ if (Platform.OS === 'web') return value
23
25
  if (['marginTop', 'marginBottom', 'translateY'].includes(key)) finalUnits['%'] = units.height! / 100
24
26
  else if (['marginLeft', 'marginRight', 'translateX'].includes(key)) finalUnits['%'] = units.width! / 100
25
27
  else if (key.startsWith('border') && key.endsWith('Radius')) finalUnits['%'] = (units.width! + units.height!) / 200