react-native-dynamic-responsive 1.0.0 → 1.0.2

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/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "react-native-dynamic-responsive",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Production-ready dynamic responsive setup for React Native apps.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://gitlab.com/code_dharmendra/react-native-dynamic-responsive.git"
10
+ },
7
11
  "scripts": {
8
12
  "build": "tsc",
9
13
  "prepublishOnly": "npm run build"
@@ -20,7 +24,10 @@
20
24
  "foldable",
21
25
  "dynamic",
22
26
  "size-matters",
23
- "react-native-size-matters"
27
+ "react-native-size-matters",
28
+ "responsive",
29
+ "responsive-ui",
30
+ "dynamic-responsive"
24
31
  ],
25
32
  "author": "Dharmendra (https://www.linkedin.com/in/dharmendra-appdeveloper)",
26
33
  "license": "MIT",
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './responsive';
package/src/responsive.ts DELETED
@@ -1,146 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { Dimensions, PixelRatio, useWindowDimensions, StyleSheet } from 'react-native';
3
-
4
- /**
5
- * ==========================================================
6
- * Base Design Size (iPhone 15 / Modern Design Reference)
7
- * ==========================================================
8
- */
9
- const BASE_WIDTH = 390;
10
- const BASE_HEIGHT = 844;
11
-
12
- /**
13
- * ==========================================================
14
- * Prevent excessive scaling on Tablets / Fold Open
15
- * ==========================================================
16
- */
17
- const MAX_SCALE_WIDTH = 420;
18
- const MAX_SCALE_HEIGHT = 932;
19
-
20
- /**
21
- * ==========================================================
22
- * Current Window (Static - Evaluated Once)
23
- * ==========================================================
24
- */
25
- const getWindow = () => Dimensions.get('window');
26
-
27
- export const SCREEN_WIDTH = () => getWindow().width;
28
- export const SCREEN_HEIGHT = () => getWindow().height;
29
-
30
- export const IS_TABLET = () => SCREEN_WIDTH() >= 768;
31
- export const IS_FOLD = () => SCREEN_WIDTH() >= 600 && SCREEN_WIDTH() < 768;
32
- export const IS_PHONE = () => SCREEN_WIDTH() < 600;
33
- export const IS_SMALL_PHONE = () => SCREEN_WIDTH() <= 360;
34
- export const IS_LANDSCAPE = () => SCREEN_WIDTH() > SCREEN_HEIGHT();
35
-
36
- /**
37
- * ==========================================================
38
- * Static Responsive Scale (For backward compatibility)
39
- * ==========================================================
40
- */
41
- const effectiveWidth = () => Math.min(SCREEN_WIDTH(), MAX_SCALE_WIDTH);
42
- const effectiveHeight = () => Math.min(SCREEN_HEIGHT(), MAX_SCALE_HEIGHT);
43
-
44
- export const scale = (size: number) => (effectiveWidth() / BASE_WIDTH) * size;
45
- export const s = scale;
46
-
47
- export const verticalScale = (size: number) => (effectiveHeight() / BASE_HEIGHT) * size;
48
- export const vs = verticalScale;
49
-
50
- export const moderateScale = (size: number, factor: number = 0.25) =>
51
- size + (scale(size) - size) * factor;
52
- export const ms = moderateScale;
53
-
54
- export const wp = (percent: number | string) => {
55
- const value = typeof percent === 'number' ? percent : parseFloat(percent);
56
- return PixelRatio.roundToNearestPixel((SCREEN_WIDTH() * value) / 100);
57
- };
58
-
59
- export const hp = (percent: number | string) => {
60
- const value = typeof percent === 'number' ? percent : parseFloat(percent);
61
- return PixelRatio.roundToNearestPixel((SCREEN_HEIGHT() * value) / 100);
62
- };
63
-
64
- /**
65
- * ==========================================================
66
- * Dynamic React Hooks (Production-Ready)
67
- * Automatically updates on:
68
- * - Rotation
69
- * - Fold / Unfold
70
- * - Multi Window
71
- * ==========================================================
72
- */
73
-
74
- export type ResponsiveUtils = {
75
- s: (size: number) => number;
76
- scale: (size: number) => number;
77
- vs: (size: number) => number;
78
- verticalScale: (size: number) => number;
79
- ms: (size: number, factor?: number) => number;
80
- moderateScale: (size: number, factor?: number) => number;
81
- wp: (percent: number | string) => number;
82
- hp: (percent: number | string) => number;
83
- width: number;
84
- height: number;
85
- isTablet: boolean;
86
- isFold: boolean;
87
- isPhone: boolean;
88
- isSmallPhone: boolean;
89
- isLandscape: boolean;
90
- };
91
-
92
- export const useResponsive = (): ResponsiveUtils => {
93
- const { width, height } = useWindowDimensions();
94
-
95
- return useMemo(() => {
96
- const eWidth = Math.min(width, MAX_SCALE_WIDTH);
97
- const eHeight = Math.min(height, MAX_SCALE_HEIGHT);
98
-
99
- const _s = (size: number) => (eWidth / BASE_WIDTH) * size;
100
- const _vs = (size: number) => (eHeight / BASE_HEIGHT) * size;
101
- const _ms = (size: number, factor = 0.25) => size + (_s(size) - size) * factor;
102
- const _wp = (percent: number | string) => {
103
- const value = typeof percent === 'number' ? percent : parseFloat(percent);
104
- return PixelRatio.roundToNearestPixel((width * value) / 100);
105
- };
106
- const _hp = (percent: number | string) => {
107
- const value = typeof percent === 'number' ? percent : parseFloat(percent);
108
- return PixelRatio.roundToNearestPixel((height * value) / 100);
109
- };
110
-
111
- return {
112
- s: _s,
113
- scale: _s,
114
- vs: _vs,
115
- verticalScale: _vs,
116
- ms: _ms,
117
- moderateScale: _ms,
118
- wp: _wp,
119
- hp: _hp,
120
- width,
121
- height,
122
- isSmallPhone: width <= 360,
123
- isPhone: width < 600,
124
- isFold: width >= 600 && width < 768,
125
- isTablet: width >= 768,
126
- isLandscape: width > height,
127
- };
128
- }, [width, height]);
129
- };
130
-
131
- /**
132
- * Hook to create dynamic stylesheets that recalculate on dimension changes.
133
- * Usage:
134
- * const styles = useStyles((r) => ({
135
- * container: { padding: r.ms(16) }
136
- * }));
137
- */
138
- export function useStyles<T extends StyleSheet.NamedStyles<T> | StyleSheet.NamedStyles<any>>(
139
- createStyles: (utils: ResponsiveUtils) => T | StyleSheet.NamedStyles<T>
140
- ): T {
141
- const responsive = useResponsive();
142
-
143
- // We only want to recreate the stylesheet if responsive changes (width/height), NOT on every render.
144
- // Assuming createStyles is a pure function that relies ONLY on the 'utils' parameter.
145
- return useMemo(() => StyleSheet.create(createStyles(responsive) as any), [responsive.width, responsive.height]);
146
- }