react-native-responsive-metrics 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Umang Thakkar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # react-native-responsive-metrics
2
+
3
+ [![npm version](https://img.shields.io/npm/v/react-native-responsive-metrics)](https://www.npmjs.com/package/react-native-responsive-metrics)
4
+ [![license](https://img.shields.io/npm/l/react-native-responsive-metrics)](./LICENSE)
5
+
6
+ Responsive scaling utilities for React Native. Scales UI consistently across phones and tablets based on a baseline design size of **390×844** (iPhone 14).
7
+
8
+ Made by [Umang Thakkar](https://github.com/Umang2809)
9
+
10
+ ---
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install react-native-responsive-metrics
16
+ # or
17
+ yarn add react-native-responsive-metrics
18
+ ```
19
+
20
+ ---
21
+
22
+ ## Usage
23
+
24
+ ```ts
25
+ import {
26
+ horizontalScale,
27
+ verticalScale,
28
+ moderateScale,
29
+ getResponsiveIconSize,
30
+ isTablet,
31
+ } from "react-native-responsive-metrics";
32
+
33
+ const styles = StyleSheet.create({
34
+ container: {
35
+ paddingHorizontal: horizontalScale(16),
36
+ paddingVertical: verticalScale(12),
37
+ borderRadius: moderateScale(8),
38
+ },
39
+ title: {
40
+ fontSize: moderateScale(18),
41
+ },
42
+ icon: {
43
+ width: getResponsiveIconSize(24),
44
+ height: getResponsiveIconSize(24),
45
+ },
46
+ });
47
+ ```
48
+
49
+ ---
50
+
51
+ ## API
52
+
53
+ | Function | Signature | Description |
54
+ | ----------------------- | ------------------------------------------- | ------------------------------------------------------- |
55
+ | `horizontalScale` | `(size: number) => number` | Scales based on screen width |
56
+ | `verticalScale` | `(size: number) => number` | Scales based on screen height |
57
+ | `moderateScale` | `(size: number, factor?: number) => number` | Balanced scale, less aggressive (default factor: `0.5`) |
58
+ | `getResponsiveIconSize` | `(baseSize?: number) => number` | Scales icon size to smallest screen dimension |
59
+ | `isTablet` | `boolean` | `true` if device width ≥ 768px |
60
+
61
+ ---
62
+
63
+ ## When to use which
64
+
65
+ | Function | Best for |
66
+ | ----------------------- | ------------------------------------- |
67
+ | `horizontalScale` | padding, margin, width |
68
+ | `verticalScale` | height, top/bottom spacing |
69
+ | `moderateScale` | font sizes, border radius, icon sizes |
70
+ | `getResponsiveIconSize` | SVG icons, image sizes |
71
+
72
+ ---
73
+
74
+ ## Baseline
75
+
76
+ | Property | Value |
77
+ | --------------------- | ------------------- |
78
+ | Design width | `390px` (iPhone 14) |
79
+ | Design height | `844px` (iPhone 14) |
80
+ | Tablet max width cap | `550px` |
81
+ | Tablet max height cap | `900px` |
82
+
83
+ ---
84
+
85
+ ## Also check out
86
+
87
+ 🗂 **React Native Base Template** — A ready-to-use React Native project structure to get started fast.
88
+
89
+ 👉 [@umang-thakkar/base-template on npm](https://www.npmjs.com/package/@umang-thakkar/base-template)
90
+
91
+ ---
92
+
93
+ ## License
94
+
95
+ MIT © [Umang Thakkar](https://github.com/Umang2809)
package/lib/index.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ export declare const isTablet: boolean;
2
+ /**
3
+ * Scale based on screen width.
4
+ * Use for: padding, margin, width
5
+ */
6
+ export declare const horizontalScale: (size: number) => number;
7
+ /**
8
+ * Scale based on screen height.
9
+ * Use for: height, top/bottom spacing
10
+ */
11
+ export declare const verticalScale: (size: number) => number;
12
+ /**
13
+ * Balanced scale — less aggressive than horizontalScale.
14
+ * Use for: font sizes, border radius, icon sizes
15
+ * @param factor - scaling aggressiveness (default: 0.5)
16
+ */
17
+ export declare const moderateScale: (size: number, factor?: number) => number;
18
+ /**
19
+ * Icon size scaled to the smallest screen dimension.
20
+ * Use for: SVG icons, image sizes
21
+ */
22
+ export declare const getResponsiveIconSize: (baseSize?: number) => number;
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,QAAQ,EAAE,OAAsB,CAAC;AAQ9C;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,MACD,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MACG,CAAC;AAEjD;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,EAAE,SAAQ,MAAY,KAAG,MACnB,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,WAAU,MAAY,KAAG,MAM9D,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getResponsiveIconSize = exports.moderateScale = exports.verticalScale = exports.horizontalScale = exports.isTablet = void 0;
4
+ const react_native_1 = require("react-native");
5
+ const { width, height } = react_native_1.Dimensions.get("window");
6
+ const guidelineBaseWidth = 390;
7
+ const guidelineBaseHeight = 844;
8
+ exports.isTablet = width >= 768;
9
+ const tabletMaxWidth = 550;
10
+ const tabletMaxHeight = 900;
11
+ const effectiveWidth = exports.isTablet ? Math.min(width, tabletMaxWidth) : width;
12
+ const effectiveHeight = exports.isTablet ? Math.min(height, tabletMaxHeight) : height;
13
+ /**
14
+ * Scale based on screen width.
15
+ * Use for: padding, margin, width
16
+ */
17
+ const horizontalScale = (size) => (effectiveWidth / guidelineBaseWidth) * size;
18
+ exports.horizontalScale = horizontalScale;
19
+ /**
20
+ * Scale based on screen height.
21
+ * Use for: height, top/bottom spacing
22
+ */
23
+ const verticalScale = (size) => (effectiveHeight / guidelineBaseHeight) * size;
24
+ exports.verticalScale = verticalScale;
25
+ /**
26
+ * Balanced scale — less aggressive than horizontalScale.
27
+ * Use for: font sizes, border radius, icon sizes
28
+ * @param factor - scaling aggressiveness (default: 0.5)
29
+ */
30
+ const moderateScale = (size, factor = 0.5) => size + ((0, exports.horizontalScale)(size) - size) * factor;
31
+ exports.moderateScale = moderateScale;
32
+ /**
33
+ * Icon size scaled to the smallest screen dimension.
34
+ * Use for: SVG icons, image sizes
35
+ */
36
+ const getResponsiveIconSize = (baseSize = 100) => {
37
+ const scaleFactor = Math.min(effectiveWidth / guidelineBaseWidth, effectiveHeight / guidelineBaseHeight);
38
+ return baseSize * scaleFactor;
39
+ };
40
+ exports.getResponsiveIconSize = getResponsiveIconSize;
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+CAA0C;AAE1C,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,yBAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAEnD,MAAM,kBAAkB,GAAW,GAAG,CAAC;AACvC,MAAM,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+ "version": "1.0.0",
4
+ "description": "Responsive scaling utilities for React Native — phones and tablets",
5
+ "main": "lib/index.js",
6
+ "module": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "files": [
9
+ "lib",
10
+ "README.md"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "prepare": "npm run build"
15
+ },
16
+ "keywords": [
17
+ "react-native",
18
+ "responsive",
19
+ "scale",
20
+ "scaling",
21
+ "tablet",
22
+ "dimensions",
23
+ "metrics",
24
+ "ui",
25
+ "layout",
26
+ "horizontalScale",
27
+ "verticalScale",
28
+ "moderateScale"
29
+ ],
30
+ "author": "",
31
+ "license": "MIT",
32
+ "peerDependencies": {
33
+ "react-native": ">=0.60.0"
34
+ },
35
+ "devDependencies": {
36
+ "typescript": "^5.0.0",
37
+ "@types/react-native": "^0.73.0"
38
+ }
39
+ }