react-native-size-matters is a lightweight utility library for React Native designed to simplify the scaling of UI elements across various device screen sizes. It helps developers avoid manually adjusting layouts for different screen dimensions by providing a set of robust scaling functions (e.g., `scale`, `verticalScale`, `moderateScale`, `moderateVerticalScale`) and a `ScaledSheet` API that automatically processes style annotations. The library is currently stable at version `0.4.2`, with recent minor updates suggesting an active development and maintenance cadence. Its key differentiators include being lightweight with zero external dependencies beyond `react-native` itself, and offering flexible scaling options, including linear and moderate scaling with adjustable factors. It promotes a "develop once" approach, aiming for consistent UI appearance starting from a standard ~5-inch mobile device.
npm install react-native-size-mattersVerified import paths — ran on the pinned version, not inferred.
This example demonstrates both functional scaling (`moderateScale`, `verticalScale`) and the `ScaledSheet` API with various annotations (`@s`, `@vs`, `@ms`, `@ms<factor>`) to scale UI elements like text and boxes, adapting them to different screen sizes in React Native. It also shows a regular `StyleSheet` for comparison.
If you are configuring custom guideline sizes, migrate your Babel configuration to use `babel-plugin-dotenv-import` instead of `react-native-dotenv`. Ensure your `.babelrc` or `babel.config.js` is updated accordingly.
Upgrade to `react-native-size-matters@0.4.1` or higher to resolve potential issues with string values in styles. Always ensure that `ScaledSheet` annotations are correctly formatted if you intend to use strings for scaled values.
Upgrade to `react-native-size-matters@0.1.4` or higher. When using TypeScript, ensure that style properties expecting numbers are provided with numerical values, or that string values are correctly annotated for `ScaledSheet` to process them.
Remove `react-native-dotenv` from your project and replace its usage in your Babel configuration with `babel-plugin-dotenv-import`. Refer to the `react-native-size-matters` documentation for the correct setup of `babel-plugin-dotenv-import`.
Ensure you are wrapping your style definitions with `ScaledSheet.create({})` when using string-based scaling annotations (e.g., `'10@s'`). If the error persists, especially with older versions, upgrade `react-native-size-matters` to `v0.1.4` or higher.Always use `const styles = ScaledSheet.create({ /* ... */ })` when defining styles that include scaling annotations like `'10@s'`. Do not try to apply the annotations within a standard `StyleSheet.create` call.