css-to-react-native is a utility library that converts standard CSS-like style declarations into React Native stylesheet objects. Currently at version 3.2.0, it is actively maintained by the styled-components organization, indicating a stable release cadence. This library is essential for bridging web CSS styling conventions with React Native's unique styling model, automatically handling unit conversions, shorthand expansions, and platform-specific property transformations (e.g., `text-shadow-offset` to `{ width, height }`). A key differentiator is its ability to handle complex transformations like reversing `transform` order for React Native compatibility and expanding various shorthands such as `font` and `margin`. It focuses on transforming already parsed CSS property-value pairs, delegating the initial CSS parsing to external tools like PostCSS.
npm install css-to-react-nativeVerified import paths — ran on the pinned version, not inferred.
Demonstrates converting an array of CSS property-value tuples, including shorthands and complex values, into a React Native stylesheet object. Shows how `transform` order is handled.
Ensure all properties requiring units have them explicitly defined (e.g., `width: '10px'` instead of `width: 10`).
Provide `line-height` values with explicit units (e.g., `font: '14px/16px Helvetica'` instead of `font: '14px/1.5 Helvetica'`).
Be aware that `box-shadow` styles will not render on Android. Consider platform-specific styling or alternative visual effects for cross-platform support.
Use individual properties like `borderTopWidth`, `borderTopColor`, `borderTopLeftRadius`, etc., for precise border styling.
No manual fix required, but developers should be aware that the internal transformation order might differ from web CSS to ensure correct visual output in React Native.
Utilize a robust CSS parser (e.g., PostCSS, `stylis`) to reliably extract property-value pairs. `css-to-react-native` expects an array of `[property, value]` tuples as its input, not raw CSS strings.
Decompose complex CSS shorthands into individual, supported React Native style properties. Consult React Native's style documentation for specific property support.
No dependency data recorded yet.