react-native-dynamic-responsive 1.0.2 → 1.1.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/README.md CHANGED
@@ -1,26 +1,8 @@
1
1
  # ðŸ“ą react-native-dynamic-responsive
2
2
 
3
- ### Dynamic, Lightweight & TypeScript-First Responsive UI for React Native
3
+ > **Dynamic, Lightweight & TypeScript-First Responsive Styling with Full Theme Support for React Native & Expo.**
4
4
 
5
- Build React Native interfaces that adapt naturally to **different screen sizes, orientations, tablets, foldable devices, and dynamic window dimensions**.
6
-
7
- `react-native-dynamic-responsive` provides a simple, familiar API for responsive scaling while giving modern React Native applications a **dynamic, hook-based styling approach**.
8
-
9
- Built for:
10
-
11
- - ðŸ“ą Phones
12
- - ðŸ“ē Tablets
13
- - 📖 Foldable devices
14
- - ↔ïļ Portrait & landscape
15
- - ⚛ïļ React Native CLI
16
- - 🚀 Expo
17
- - 🔷 TypeScript
18
-
19
- **Zero runtime dependencies. No native configuration required.**
20
-
21
- ## ðŸ“ą Responsive UI Across Devices
22
-
23
- Build once and adapt your interface across phones, landscape layouts, tablets, and foldable devices.
5
+ Build React Native interfaces that adapt effortlessly to different screen sizes, orientations, tablets, foldable devices, and dynamic themes.
24
6
 
25
7
  <p align="center">
26
8
  <img
@@ -36,1303 +18,261 @@ Build once and adapt your interface across phones, landscape layouts, tablets, a
36
18
 
37
19
  ---
38
20
 
39
- ## âœĻ Why react-native-dynamic-responsive?
40
-
41
- Traditional responsive utilities are often designed around a fixed screen size.
42
-
43
- Modern devices are different.
44
-
45
- A React Native application can experience:
46
-
47
- ```
48
- Phone
49
- ↓
50
- Rotation
51
- ↓
52
- Landscape
53
- ↓
54
- Split Screen
55
- ↓
56
- Tablet
57
- ↓
58
- Foldable
59
- ↓
60
- Inner / Outer Display
61
-
62
- ```
63
-
64
- The available screen dimensions can change while your application is running.
65
-
66
- `react-native-dynamic-responsive` is designed around this reality.
67
-
68
- ### The goal
21
+ ## âœĻ Highlights
69
22
 
70
- > **Write responsive styles once and let the layout adapt to the current screen dimensions.**
71
-
72
- ```
73
- const styles = useStyles((r) => ({
74
- container: {
75
- width: r.isTablet ? r.wp(70) : r.wp(90),
76
- padding: r.ms(16),
77
- },
78
-
79
- title: {
80
- fontSize: r.ms(24),
81
- },
82
- }));
83
-
84
- ```
23
+ - ⚡ **Dynamic & Reactive**: Automatically adapts when devices rotate, split screen, fold/unfold, or resize.
24
+ - ðŸŽĻ **Dynamic Theme Support**: Seamlessly updates styles on Dark/Light mode and custom theme changes.
25
+ - ðŸŠķ **Zero Runtime Dependencies**: Ultra-lightweight with no native dependencies needed.
26
+ - ðŸ“ą **Multi-Device Ready**: Built-in support for phones, tablets, foldables, and landscape mode.
27
+ - 🔷 **TypeScript-First**: Complete type safety and autocomplete out of the box.
28
+ - 🚀 **Universal Compatibility**: Works with Expo, Expo Router, and React Native CLI.
85
29
 
86
30
  ---
87
31
 
88
- # 🚀 Installation
32
+ ## 🚀 Installation
89
33
 
90
- ```
34
+ ```bash
91
35
  npm install react-native-dynamic-responsive
92
-
93
36
  ```
94
37
 
95
- or:
38
+ or
96
39
 
97
- ```
40
+ ```bash
98
41
  yarn add react-native-dynamic-responsive
99
-
100
42
  ```
101
43
 
102
- ### No native setup
103
-
104
- The library is designed to work without additional native configuration.
105
-
106
- You can use it directly in:
107
-
108
- - Expo
109
- - Expo Router
110
- - React Native CLI
111
-
112
44
  ---
113
45
 
114
- # ⚡ Quick Start
46
+ ## ⚡ Quick Start
115
47
 
116
- The recommended API is `useStyles()`.
48
+ Use `useStyles()` to create styles that automatically adapt to your screen:
117
49
 
118
- ```
50
+ ```tsx
119
51
  import React from 'react';
120
52
  import { View, Text } from 'react-native';
53
+ import { useStyles, useResponsive } from 'react-native-dynamic-responsive';
121
54
 
122
- import {
123
- useStyles,
124
- useResponsive,
125
- ResponsiveUtils,
126
- } from 'react-native-dynamic-responsive';
127
-
128
- export const MyComponent = () => {
129
- const { isTablet, isFold } = useResponsive();
130
-
55
+ export const WelcomeCard = () => {
56
+ const { isTablet } = useResponsive();
131
57
  const styles = useStyles(createStyles);
132
58
 
133
59
  return (
134
- <View style={styles.container}>
60
+ <View style={styles.card}>
135
61
  <Text style={styles.title}>
136
- {isTablet ? 'Tablet View' : 'Phone View'}
137
- </Text>
138
-
139
- <Text>
140
- {isFold ? 'Foldable Device' : 'Standard Device'}
62
+ {isTablet ? 'Welcome to Tablet View' : 'Welcome'}
141
63
  </Text>
142
64
  </View>
143
65
  );
144
66
  };
145
67
 
146
- const createStyles = (r: ResponsiveUtils) => ({
147
- container: {
148
- width: r.isTablet ? r.wp(70) : r.wp(90),
68
+ const createStyles = (r) => ({
69
+ card: {
70
+ width: r.isTablet ? r.wp(60) : r.wp(90),
149
71
  padding: r.ms(16),
72
+ borderRadius: r.s(12),
150
73
  },
151
-
152
74
  title: {
153
- fontSize: r.ms(24),
154
- fontWeight: '700',
75
+ fontSize: r.ms(20),
76
+ fontWeight: '600',
155
77
  },
156
78
  });
157
-
158
79
  ```
159
80
 
160
81
  ---
161
82
 
162
- # 🧠 How It Works
83
+ ## ðŸŽŊ Best Use Cases & Examples
163
84
 
164
- The library provides a responsive utility object containing scaling functions and device information.
85
+ ### 1. ðŸŽĻ Dynamic Theme Switching (Dark Mode / Custom Themes)
165
86
 
166
- Instead of calculating screen dimensions manually inside every component:
87
+ `useStyles()` automatically recalculates styles when a user or system switches themes without requiring an app reload or screen rotation.
167
88
 
168
- ```
169
- Dimensions.get('window')
89
+ #### Pass `theme` directly into `useStyles` (Recommended)
170
90
 
171
- ```
91
+ ```tsx
92
+ import React from 'react';
93
+ import { View, Text } from 'react-native';
94
+ import { useStyles, ResponsiveUtils } from 'react-native-dynamic-responsive';
95
+ import { useTheme } from './ThemeContext';
172
96
 
173
- you can use:
97
+ export const ThemedCard = () => {
98
+ const theme = useTheme();
99
+
100
+ // Recalculates on theme change AND device rotation/window resize
101
+ const styles = useStyles(createStyles, theme);
174
102
 
175
- ```
176
- const styles = useStyles((r) => ({
103
+ return (
104
+ <View style={styles.card}>
105
+ <Text style={styles.title}>Adaptive & Themed</Text>
106
+ </View>
107
+ );
108
+ };
109
+
110
+ // Define style factory outside the component for best performance
111
+ const createStyles = (r: ResponsiveUtils, theme: any) => ({
177
112
  card: {
178
- width: r.wp(90),
113
+ backgroundColor: theme.colors.cardBackground,
179
114
  padding: r.ms(16),
115
+ borderRadius: r.s(8),
180
116
  },
181
- }));
182
-
183
- ```
184
-
185
- The responsive style function receives the current responsive context.
186
-
187
- When the relevant screen dimensions change, the hook can recalculate the responsive styles for the component.
188
-
189
- This makes the API particularly useful for:
190
-
191
- - orientation changes
192
- - fold/unfold transitions
193
- - tablet layouts
194
- - dynamic window sizes
195
- - split-screen layouts
196
-
197
- ---
198
-
199
- # ⚡ Performance
200
-
201
- Performance is a first-class consideration.
202
-
203
- `react-native-dynamic-responsive` is designed to remain lightweight while providing dynamic responsive behavior.
204
-
205
- ## ðŸŠķ Zero Runtime Dependencies
206
-
207
- The package has:
208
-
209
- ```
210
- 0 Runtime Dependencies
211
-
212
- ```
213
-
214
- React and React Native are used as peer dependencies.
215
-
216
- This helps keep the dependency tree small and avoids introducing additional runtime libraries into your application.
217
-
218
- ---
219
-
220
- ## ðŸ§Đ No Native Module Setup
221
-
222
- The responsive logic is designed to work from the React Native layer.
223
-
224
- You don't need to install an additional native module just to perform responsive scaling.
225
-
226
- That means:
227
-
228
- ```
229
- npm install
230
- ↓
231
- Import package
232
- ↓
233
- Use responsive utilities
234
-
235
- ```
236
-
237
- No additional native linking workflow is required.
238
-
239
- ---
240
-
241
- ## 🔄 Dynamic Updates Only When Dimensions Matter
242
-
243
- Responsive styles are useful because screen dimensions can change.
244
-
245
- Examples:
246
-
247
- ```
248
- Portrait
249
- ↓
250
- Landscape
251
-
252
- Folded
253
- ↓
254
- Unfolded
255
-
256
- Outer Screen
257
- ↓
258
- Inner Screen
259
-
260
- Full Screen
261
- ↓
262
- Split Screen
263
-
264
- ```
265
-
266
- The recommended `useStyles()` API is intended for these dynamic scenarios.
267
-
268
- For applications where dimensions never need to change dynamically, static utility functions are also available.
269
-
270
- ---
271
-
272
- ## ⚠ïļ Performance Best Practices
273
-
274
- For the best performance:
275
-
276
- ### ✅ Keep style factories outside components
277
-
278
- Recommended:
279
-
280
- ```
281
- const createStyles = (r: ResponsiveUtils) => ({
282
- container: {
283
- padding: r.ms(16),
117
+ title: {
118
+ color: theme.colors.text,
119
+ fontSize: r.ms(18),
284
120
  },
285
121
  });
286
-
287
- const MyComponent = () => {
288
- const styles = useStyles(createStyles);
289
-
290
- return <View style={styles.container} />;
291
- };
292
-
293
- ```
294
-
295
- Avoid recreating the complete style factory unnecessarily inside the component.
296
-
297
- ---
298
-
299
- ### ✅ Use `useStyles()` for dynamic layouts
300
-
301
- If your UI needs to react to:
302
-
303
- - rotation
304
- - fold/unfold
305
- - window resizing
306
-
307
- use:
308
-
309
- ```
310
- useStyles()
311
-
312
122
  ```
313
123
 
314
- ---
315
-
316
- ### ✅ Use static utilities when dynamic behavior isn't required
317
-
318
- For fixed/static styling:
319
-
320
- ```
321
- import { ms, s, vs } from 'react-native-dynamic-responsive';
322
-
323
- ```
324
-
325
- This can be useful for existing applications that don't need dynamic screen updates.
124
+ #### Using with Dependency Array
326
125
 
327
- ---
328
-
329
- ## ðŸ“Ķ Bundle & Dependency Philosophy
330
-
331
- The library follows a simple philosophy:
332
-
333
- ```
334
- Small API
335
- +
336
- Zero runtime dependencies
337
- +
338
- React Native primitives
339
- +
340
- TypeScript
341
- =
342
- Low complexity
126
+ ```tsx
127
+ const { colors } = useTheme();
343
128
 
129
+ const styles = useStyles(
130
+ (r) => ({
131
+ container: {
132
+ backgroundColor: colors.surface,
133
+ padding: r.ms(16),
134
+ },
135
+ }),
136
+ [colors] // 👈 Recalculates immediately when theme colors change
137
+ );
344
138
  ```
345
139
 
346
- There are no unnecessary UI components, animation systems, state managers, or styling frameworks bundled into the package.
347
-
348
- The library focuses specifically on responsive calculations and responsive style handling.
349
-
350
140
  ---
351
141
 
352
- # 🌟 Features
142
+ ### 2. ðŸ“ē Tablet & Multi-Column Layouts
353
143
 
354
- ### ðŸ“ą Responsive Scaling
355
-
356
- Scale dimensions according to the current screen size.
357
-
358
- ### 📐 Width & Height Percentages
359
-
360
- Create layouts using percentage-based dimensions.
361
-
362
- ### 🔄 Dynamic Screen Updates
363
-
364
- React to changes in screen dimensions.
365
-
366
- ### 📖 Foldable Support
367
-
368
- Useful for devices where the available display area changes between folded and unfolded states.
369
-
370
- ### ðŸ“ē Tablet Detection
371
-
372
- Easily adapt layouts for larger screens.
373
-
374
- ### ↔ïļ Orientation Detection
375
-
376
- Detect portrait and landscape layouts.
377
-
378
- ### ⚛ïļ Hooks-First API
379
-
380
- Modern React API using:
381
-
382
- ```
383
- useStyles()
384
- useResponsive()
144
+ Adapt layouts between single-column phone displays and multi-column tablet screens:
385
145
 
146
+ ```tsx
147
+ const styles = useStyles((r) => ({
148
+ grid: {
149
+ flexDirection: r.isTablet ? 'row' : 'column',
150
+ flexWrap: 'wrap',
151
+ gap: r.ms(12),
152
+ },
153
+ gridItem: {
154
+ width: r.isTablet ? r.wp(45) : r.wp(90),
155
+ padding: r.ms(16),
156
+ },
157
+ }));
386
158
  ```
387
159
 
388
- ### 🔷 TypeScript
389
-
390
- Type-friendly responsive utilities.
391
-
392
- ### 🚀 Expo Compatible
393
-
394
- Works with Expo applications.
395
-
396
- ### ⚛ïļ React Native CLI Compatible
397
-
398
- Works with standard React Native CLI applications.
399
-
400
- ### ðŸŠķ Lightweight
401
-
402
- Zero runtime dependencies.
403
-
404
160
  ---
405
161
 
406
- # 📐 Responsive Utilities
162
+ ### 3. 📖 Foldable & Dual-Screen Devices
407
163
 
408
- The responsive utility object provides familiar scaling functions.
164
+ Gracefully transition layouts when a foldable device is opened or closed:
409
165
 
410
- ```
166
+ ```tsx
411
167
  const styles = useStyles((r) => ({
412
168
  container: {
413
- width: r.wp(90),
414
- height: r.hp(40),
415
- padding: r.s(16),
416
- marginTop: r.vs(20),
169
+ flexDirection: r.isFold ? 'row' : 'column',
170
+ padding: r.ms(r.isFold ? 24 : 16),
417
171
  },
418
-
419
- title: {
420
- fontSize: r.ms(24),
172
+ sidebar: {
173
+ width: r.isFold ? r.wp(35) : '100%',
174
+ },
175
+ content: {
176
+ width: r.isFold ? r.wp(60) : '100%',
421
177
  },
422
178
  }));
423
-
424
- ```
425
-
426
- ---
427
-
428
- ## Available Functions
429
-
430
- | Function | Description | Example |
431
- | --------------------- | --------------------------- | ---------- |
432
- | `r.s(size)` | Standard horizontal scaling | `r.s(16)` |
433
- | `r.ms(size, factor?)` | Moderate scaling | `r.ms(24)` |
434
- | `r.vs(size)` | Vertical scaling | `r.vs(20)` |
435
- | `r.wp(percent)` | Percentage of screen width | `r.wp(90)` |
436
- | `r.hp(percent)` | Percentage of screen height | `r.hp(50)` |
437
-
438
- ---
439
-
440
- # ðŸ“ą Device Detection
441
-
442
- Use `useResponsive()` when your UI needs device-specific behavior.
443
-
444
- ```
445
- const r = useResponsive();
446
-
447
- ```
448
-
449
- You can then access:
450
-
451
179
  ```
452
- r.isPhone
453
- r.isTablet
454
- r.isFold
455
- r.isSmallPhone
456
- r.isLandscape
457
-
458
- ```
459
-
460
- ---
461
-
462
- ## Device Flags
463
-
464
- | Flag | Condition |
465
- | -------------- | --------------------- |
466
- | `isPhone` | Width < 600 |
467
- | `isFold` | Width â‰Ĩ 600 and < 768 |
468
- | `isTablet` | Width â‰Ĩ 768 |
469
- | `isSmallPhone` | Width â‰Ī 360 |
470
- | `isLandscape` | Width > Height |
471
-
472
- > These thresholds are intended as practical defaults. They should not be treated as a universal hardware classification standard.
473
180
 
474
181
  ---
475
182
 
476
- # 🔄 Orientation
183
+ ### 4. ↔ïļ Orientation Handling (Portrait vs Landscape)
477
184
 
478
- You can easily create different layouts for portrait and landscape.
185
+ Respond smoothly to orientation changes without app reloads:
479
186
 
480
- ```
187
+ ```tsx
481
188
  const styles = useStyles((r) => ({
482
- container: {
483
- width: r.isLandscape
484
- ? r.wp(70)
485
- : r.wp(90),
189
+ banner: {
190
+ height: r.isLandscape ? r.hp(40) : r.hp(25),
191
+ width: '100%',
486
192
  },
487
193
  }));
488
-
489
- ```
490
-
491
- Example:
492
-
493
- ```
494
- PORTRAIT
495
-
496
- ┌──────────┐
497
- │ │
498
- │ Content │
499
- │ │
500
- └──────────┘
501
-
502
-
503
- ↓ ROTATE
504
-
505
-
506
- LANDSCAPE
507
-
508
- ┌──────────────────┐
509
- │ Content │
510
- └──────────────────┘
511
-
512
194
  ```
513
195
 
514
196
  ---
515
197
 
516
- # 📖 Foldable Devices
517
-
518
- Foldable devices introduce an additional responsive challenge.
519
-
520
- The available display area can change significantly between:
521
-
522
- ```
523
- Folded
524
- ↓
525
- Outer Display
526
-
527
- Unfolded
528
- ↓
529
- Inner Display
530
-
531
- ```
198
+ ### 5. 🔍 Using `useResponsive()` in Logic & JSX
532
199
 
533
- A responsive layout should not assume that the original screen dimensions remain constant.
200
+ Use `useResponsive()` when you need device dimensions or device flags in your component logic:
534
201
 
535
- Using:
202
+ ```tsx
203
+ import { useResponsive } from 'react-native-dynamic-responsive';
536
204
 
537
- ```
538
- const styles = useStyles((r) => ({
539
- container: {
540
- width: r.isFold
541
- ? r.wp(90)
542
- : r.wp(70),
543
- },
544
- }));
205
+ export const Header = () => {
206
+ const { isTablet, isLandscape, width } = useResponsive();
545
207
 
208
+ return (
209
+ <View>
210
+ {isTablet ? <TabletNav /> : <MobileDrawer />}
211
+ <Text>Screen Width: {width}px</Text>
212
+ </View>
213
+ );
214
+ };
546
215
  ```
547
216
 
548
- your component can adapt its layout according to the current responsive state.
549
-
550
217
  ---
551
218
 
552
- # ðŸ“ē Tablet Layouts
219
+ ### 6. 📐 Static Responsive Utilities
553
220
 
554
- Tablet layouts often require different proportions from phone layouts.
221
+ For simple apps, constants, or code outside React components, static scaling functions are always available:
555
222
 
556
- Instead of maintaining completely separate styles:
557
-
558
- ```
559
- const styles = useStyles((r) => ({
560
- container: {
561
- width: r.isTablet
562
- ? r.wp(70)
563
- : r.wp(92),
223
+ ```tsx
224
+ import { s, vs, ms, wp, hp, scale, verticalScale, moderateScale } from 'react-native-dynamic-responsive';
564
225
 
565
- padding: r.isTablet
566
- ? r.ms(24)
567
- : r.ms(16),
226
+ const staticStyles = StyleSheet.create({
227
+ box: {
228
+ width: wp('85%'),
229
+ height: hp('20%'),
230
+ paddingHorizontal: s(16),
231
+ paddingVertical: vs(12),
232
+ fontSize: ms(16, 0.3),
568
233
  },
569
- }));
570
-
234
+ });
571
235
  ```
572
236
 
573
- This keeps the responsive logic close to the styles that use it.
574
-
575
237
  ---
576
238
 
577
- # ðŸŽĻ Responsive Typography
239
+ ## 🛠ïļ API Reference
578
240
 
579
- Responsive scaling can also be used for typography.
241
+ ### `ResponsiveUtils` (Available in `useResponsive()` & `useStyles`)
580
242
 
581
- ```
582
- const styles = useStyles((r) => ({
583
- heading: {
584
- fontSize: r.ms(28),
585
- lineHeight: r.ms(34),
586
- },
243
+ | Property / Method | Description | Example |
244
+ | :--- | :--- | :--- |
245
+ | `s(size)` / `scale(size)` | Scale proportionally based on screen width | `r.s(20)` |
246
+ | `vs(size)` / `verticalScale(size)` | Scale proportionally based on screen height | `r.vs(40)` |
247
+ | `ms(size, factor?)` / `moderateScale` | Scale moderately with a dampening factor (default 0.25) | `r.ms(16)` |
248
+ | `wp(percent)` | Width percentage of the current window (0 - 100) | `r.wp(80)` or `r.wp('80%')` |
249
+ | `hp(percent)` | Height percentage of the current window (0 - 100) | `r.hp(50)` or `r.hp('50%')` |
250
+ | `width` | Current window width in pixels | `r.width` |
251
+ | `height` | Current window height in pixels | `r.height` |
252
+ | `isPhone` | `true` when width is less than 600px | `r.isPhone` |
253
+ | `isSmallPhone` | `true` when width is 360px or smaller | `r.isSmallPhone` |
254
+ | `isFold` | `true` for foldable device screen ranges (600px - 767px) | `r.isFold` |
255
+ | `isTablet` | `true` when width is 768px or greater | `r.isTablet` |
256
+ | `isLandscape` | `true` when width is greater than height | `r.isLandscape` |
587
257
 
588
- body: {
589
- fontSize: r.ms(16),
590
- lineHeight: r.ms(24),
591
- },
592
- }));
258
+ ---
593
259
 
594
- ```
260
+ ## ðŸ’Ą Best Practices
595
261
 
596
- Use moderate scaling where aggressive scaling could make typography or spacing unnecessarily large on bigger screens.
262
+ 1. **Define style factories outside components**: Pass `(r, theme) => ({ ... })` to `useStyles(createStyles, theme)` to keep function references clean and memory-efficient.
263
+ 2. **Use moderateScale (`ms`) for typography and padding**: Keeps text and cards comfortable and readable across large screens and tablets.
264
+ 3. **Combine percentage helpers and flexbox**: Use `wp` and `hp` for top-level containers and let Flexbox handle internal alignments.
265
+ 4. **Leverage built-in device flags**: Use `isTablet`, `isFold`, and `isLandscape` for clean, readable conditional layouts.
597
266
 
598
267
  ---
599
268
 
600
- # ðŸ§Đ `useStyles()`
601
-
602
- `useStyles()` is the recommended API for dynamic responsive styles.
603
-
604
- ```
605
- const styles = useStyles((r) => ({
606
- container: {
607
- padding: r.ms(16),
608
- width: r.wp(90),
609
- },
269
+ ## ðŸ‘Ļ‍ðŸ’ŧ Author
610
270
 
611
- title: {
612
- fontSize: r.ms(24),
613
- },
614
- }));
615
-
616
- ```
617
-
618
- ### Why use it?
619
-
620
- It keeps responsive calculations together with the style definition while allowing the styles to respond to the current responsive state.
621
-
622
- ---
623
-
624
- # 🔍 `useResponsive()`
625
-
626
- Use `useResponsive()` when you need responsive information directly inside your component.
627
-
628
- ```
629
- const {
630
- isPhone,
631
- isTablet,
632
- isFold,
633
- isSmallPhone,
634
- isLandscape,
635
- } = useResponsive();
636
-
637
- ```
638
-
639
- Example:
640
-
641
- ```
642
- return (
643
- <View>
644
- {isTablet ? (
645
- <TabletNavigation />
646
- ) : (
647
- <MobileNavigation />
648
- )}
649
- </View>
650
- );
651
-
652
- ```
653
-
654
- ---
655
-
656
- # 🛠ïļ ResponsiveUtils
657
-
658
- The style factory receives a `ResponsiveUtils` object.
659
-
660
- ```
661
- const createStyles = (r: ResponsiveUtils) => ({
662
- container: {
663
- width: r.wp(90),
664
- padding: r.ms(16),
665
- },
666
- });
667
-
668
- ```
669
-
670
- This gives you access to the responsive scaling utilities and device state from one place.
671
-
672
- ---
673
-
674
- # 🆚 Dynamic vs Static Usage
675
-
676
- ## Dynamic usage
677
-
678
- Recommended when dimensions can change:
679
-
680
- ```
681
- const styles = useStyles((r) => ({
682
- container: {
683
- width: r.wp(90),
684
- padding: r.ms(16),
685
- },
686
- }));
687
-
688
- ```
689
-
690
- Use this for:
691
-
692
- - foldables
693
- - orientation changes
694
- - tablets
695
- - split-screen
696
- - dynamic window dimensions
697
-
698
- ---
699
-
700
- ## Static usage
701
-
702
- Useful for existing codebases or styles that don't need to react to dimension changes.
703
-
704
- ```
705
- import { StyleSheet } from 'react-native';
706
- import {
707
- ms,
708
- s,
709
- vs,
710
- } from 'react-native-dynamic-responsive';
711
-
712
- const styles = StyleSheet.create({
713
- box: {
714
- width: s(100),
715
- height: vs(100),
716
- padding: ms(10),
717
- },
718
- });
719
-
720
- ```
721
-
722
- ### Important
723
-
724
- Static utilities are evaluated as normal JavaScript values when your styles are created.
725
-
726
- If your application needs to respond to changing screen dimensions, prefer:
727
-
728
- ```
729
- useStyles()
730
-
731
- ```
732
-
733
- ---
734
-
735
- # 🛍ïļ Real-World Use Cases
736
-
737
- ## E-commerce
738
-
739
- Responsive:
740
-
741
- - product grids
742
- - product cards
743
- - filters
744
- - banners
745
- - checkout screens
746
-
747
- ## Dashboards
748
-
749
- Adapt layouts between:
750
-
751
- ```
752
- Phone → Tablet → Large Screen
753
-
754
- ```
755
-
756
- ## Social Applications
757
-
758
- Responsive:
759
-
760
- - feeds
761
- - profile layouts
762
- - media cards
763
- - navigation
764
-
765
- ## Enterprise Applications
766
-
767
- Support different company devices without maintaining completely separate layouts.
768
-
769
- ## Foldable Applications
770
-
771
- Adapt the UI when available display dimensions change.
772
-
773
- ## Design Systems
774
-
775
- Create reusable responsive spacing and typography rules across an application.
776
-
777
- ---
778
-
779
- # 🔐 Security & Dependencies
780
-
781
- The package is intentionally lightweight.
782
-
783
- ### Runtime dependencies
784
-
785
- ```
786
- 0
787
-
788
- ```
789
-
790
- ### Peer dependencies
791
-
792
- ```
793
- React
794
- React Native
795
-
796
- ```
797
-
798
- The package does not require additional runtime libraries for responsive calculations.
799
-
800
- For security-sensitive production environments, always review the exact package version and dependency tree used by your application.
271
+ **Dharmendra**
272
+ [LinkedIn Profile](https://www.linkedin.com/in/dharmendra-appdeveloper)
801
273
 
802
274
  ---
803
275
 
804
- # 🧊 Testing & Production Readiness
805
-
806
- Responsive behavior should be tested on more than one screen size.
807
-
808
- Recommended testing matrix:
809
-
810
- | Device Type | Portrait | Landscape |
811
- | -------------- | -------- | --------- |
812
- | Small Phone | ✅ | ✅ |
813
- | Standard Phone | ✅ | ✅ |
814
- | Large Phone | ✅ | ✅ |
815
- | Tablet | ✅ | ✅ |
816
- | Foldable | ✅ | ✅ |
817
-
818
- Also test:
819
-
820
- - screen rotation
821
- - split-screen mode where supported
822
- - navigation transitions
823
- - modal layouts
824
- - keyboard interaction
825
- - safe-area handling
826
- - very small and very large content
827
- - text scaling/accessibility settings
828
-
829
- > Responsive scaling solves dimension-related layout problems. It does not replace good accessibility, safe-area handling, content wrapping, or platform-specific UI testing.
830
-
831
- ---
832
-
833
- # ⚠ïļ What This Library Does NOT Do
834
-
835
- `react-native-dynamic-responsive` is focused on responsive calculations and responsive style handling.
836
-
837
- It does **not** attempt to replace:
838
-
839
- - React Native `SafeAreaView`
840
- - accessibility APIs
841
- - navigation libraries
842
- - animation libraries
843
- - design systems
844
- - state management
845
- - device-specific business logic
846
-
847
- Use the right tool for each responsibility.
848
-
849
- ---
850
-
851
- # ðŸ’Ą When Should I Use This?
852
-
853
- Use this package when your application needs:
854
-
855
- ```
856
- Different screen sizes
857
- +
858
- Dynamic dimensions
859
- +
860
- Responsive spacing
861
- +
862
- Responsive typography
863
- +
864
- Tablet layouts
865
- +
866
- Orientation handling
867
- +
868
- Foldable support
869
-
870
- ```
871
-
872
- It is especially useful when you want a simple responsive API without introducing a large styling framework.
873
-
874
- ---
875
-
876
- # ðŸĪ” Frequently Asked Questions
877
-
878
- ## Does it work with Expo?
879
-
880
- Yes.
881
-
882
- The package is designed to work with Expo projects.
883
-
884
- ---
885
-
886
- ## Does it work with Expo Router?
887
-
888
- Yes.
889
-
890
- Expo Router is built on top of React Native navigation patterns, so the responsive utilities can be used inside your screens and components normally.
891
-
892
- ---
893
-
894
- ## Does it work with React Native CLI?
895
-
896
- Yes.
897
-
898
- No separate React Native CLI-specific implementation is required for normal usage.
899
-
900
- ---
901
-
902
- ## Does it require native configuration?
903
-
904
- The package is designed to be used without additional native configuration.
905
-
906
- Install it and import the utilities directly.
907
-
908
- ---
909
-
910
- ## Does it support TypeScript?
911
-
912
- Yes.
913
-
914
- The package is written for a TypeScript-friendly development experience.
915
-
916
- ---
917
-
918
- ## Does it support tablets?
919
-
920
- Yes.
921
-
922
- You can use:
923
-
924
- ```
925
- r.isTablet
926
-
927
- ```
928
-
929
- and responsive width/height utilities to create tablet-specific layouts.
930
-
931
- ---
932
-
933
- ## Does it support foldable devices?
934
-
935
- The responsive APIs are designed to respond to changing screen dimensions, making them suitable for foldable layouts.
936
-
937
- You can also use:
938
-
939
- ```
940
- r.isFold
941
-
942
- ```
943
-
944
- for the package's configured fold-device classification.
945
-
946
- ---
947
-
948
- ## Does it automatically make my entire application responsive?
949
-
950
- No.
951
-
952
- The library provides the tools.
953
-
954
- Your application still needs responsive layout decisions.
955
-
956
- For example:
957
-
958
- ```
959
- r.isTablet
960
- ? tabletLayout
961
- : mobileLayout
962
-
963
- ```
964
-
965
- The package handles the responsive calculations; your UI determines how those calculations should be used.
966
-
967
- ---
968
-
969
- ## Is it a replacement for Flexbox?
970
-
971
- No.
972
-
973
- React Native Flexbox remains the primary layout system.
974
-
975
- This library complements Flexbox by providing responsive dimensions, scaling and device information.
976
-
977
- ---
978
-
979
- ## Is it a replacement for `Dimensions`?
980
-
981
- Not completely.
982
-
983
- You can still use React Native's APIs when you need low-level device/window information.
984
-
985
- This library provides a more convenient responsive styling layer on top of those concepts.
986
-
987
- ---
988
-
989
- ## Does it work with `StyleSheet.create()`?
990
-
991
- Yes, through the static utilities:
992
-
993
- ```
994
- ms()
995
- s()
996
- vs()
997
-
998
- ```
999
-
1000
- However, if your layout needs to react to changing dimensions, use:
1001
-
1002
- ```
1003
- useStyles()
1004
-
1005
- ```
1006
-
1007
- ---
1008
-
1009
- ## Does it work with React Native Web?
1010
-
1011
- The core API is designed around React Native responsive behavior.
1012
-
1013
- If React Native Web compatibility is important for your application, test the specific APIs you use against your target web environment before relying on device-specific flags.
1014
-
1015
- ---
1016
-
1017
- ## Will it make my app slower?
1018
-
1019
- The library is designed to be lightweight and has zero runtime dependencies.
1020
-
1021
- Dynamic responsive behavior necessarily involves responding to dimension changes. The recommended approach is to use `useStyles()` for components that actually need dynamic responsive behavior rather than unnecessarily applying responsive hooks everywhere.
1022
-
1023
- ---
1024
-
1025
- ## Does it use a state management library?
1026
-
1027
- No.
1028
-
1029
- It does not require Redux, Zustand, MobX, Recoil or another state management library.
1030
-
1031
- ---
1032
-
1033
- ## Does it require Reanimated?
1034
-
1035
- No.
1036
-
1037
- Responsive scaling and dimension handling do not require React Native Reanimated.
1038
-
1039
- ---
1040
-
1041
- ## Does it provide UI components?
1042
-
1043
- No.
1044
-
1045
- This package focuses on responsive utilities and styling rather than providing buttons, cards, modals or other UI components.
1046
-
1047
- ---
1048
-
1049
- ## Can I use it with my existing design system?
1050
-
1051
- Yes.
1052
-
1053
- The scaling utilities can be used inside your existing component and design-system architecture.
1054
-
1055
- For example:
1056
-
1057
- ```
1058
- const spacing = r.ms(16);
1059
- const radius = r.ms(12);
1060
- const titleSize = r.ms(24);
1061
-
1062
- ```
1063
-
1064
- ---
1065
-
1066
- # 🔄 Migration From `react-native-size-matters`
1067
-
1068
- If your application already uses concepts such as:
1069
-
1070
- ```
1071
- ms()
1072
- s()
1073
- vs()
1074
-
1075
- ```
1076
-
1077
- the familiar scaling terminology can make migration easier.
1078
-
1079
- Example:
1080
-
1081
- ```
1082
- import {
1083
- ms,
1084
- s,
1085
- vs,
1086
- } from 'react-native-dynamic-responsive';
1087
-
1088
- ```
1089
-
1090
- For dynamic responsive behavior, prefer:
1091
-
1092
- ```
1093
- const styles = useStyles((r) => ({
1094
- container: {
1095
- padding: r.ms(16),
1096
- },
1097
- }));
1098
-
1099
- ```
1100
-
1101
- ### Important
1102
-
1103
- This package is not intended to be a drop-in replacement for every API or behavior of another responsive library.
1104
-
1105
- Review your existing scaling configuration and test your UI across your target devices after migration.
1106
-
1107
- ---
1108
-
1109
- # 📊 Responsive Design Example
1110
-
1111
- ### Without responsive rules
1112
-
1113
- ```
1114
- ┌──────────────┐
1115
- │ PHONE │
1116
- │ │
1117
- │ ┌────────┐ │
1118
- │ │ CARD │ │
1119
- │ └────────┘ │
1120
- └──────────────┘
1121
-
1122
-
1123
- ↓
1124
-
1125
-
1126
- ┌────────────────────────┐
1127
- │ TABLET │
1128
- │ │
1129
- │ ┌──────────────────┐ │
1130
- │ │ CARD │ │
1131
- │ └──────────────────┘ │
1132
- │ │
1133
- └────────────────────────┘
1134
-
1135
- ```
1136
-
1137
- ### With responsive rules
1138
-
1139
- ```
1140
- const styles = useStyles((r) => ({
1141
- card: {
1142
- width: r.isTablet
1143
- ? r.wp(45)
1144
- : r.wp(90),
1145
-
1146
- padding: r.ms(16),
1147
-
1148
- borderRadius: r.ms(12),
1149
- },
1150
- }));
1151
-
1152
- ```
1153
-
1154
- The same component can use different dimensions based on the available screen.
1155
-
1156
- ---
1157
-
1158
- # ðŸŽŊ Design Philosophy
1159
-
1160
- `react-native-dynamic-responsive` follows a few simple principles:
1161
-
1162
- ### 1. Keep the API small
1163
-
1164
- Developers should not need to learn an entire styling framework.
1165
-
1166
- ### 2. Prefer familiar concepts
1167
-
1168
- Functions such as:
1169
-
1170
- ```
1171
- s()
1172
- ms()
1173
- vs()
1174
- wp()
1175
- hp()
1176
-
1177
- ```
1178
-
1179
- are intentionally easy to understand.
1180
-
1181
- ### 3. Dynamic where it matters
1182
-
1183
- Dynamic responsive behavior is useful when the available screen changes.
1184
-
1185
- ### 4. Avoid unnecessary dependencies
1186
-
1187
- Zero runtime dependencies keeps the package focused.
1188
-
1189
- ### 5. TypeScript-friendly
1190
-
1191
- The API should be comfortable for modern React Native projects.
1192
-
1193
- ### 6. Don't hide React Native
1194
-
1195
- The library complements React Native rather than trying to replace its layout system.
1196
-
1197
- ---
1198
-
1199
- # ðŸ›Ģïļ Roadmap
1200
-
1201
- Potential future improvements may include:
1202
-
1203
- - More responsive breakpoint utilities
1204
- - Additional device classification options
1205
- - Improved responsive configuration
1206
- - More examples
1207
- - Performance benchmarks
1208
- - Expanded test coverage
1209
- - Additional documentation
1210
- - Community feedback-driven improvements
1211
-
1212
- The roadmap may change based on real-world usage and developer feedback.
1213
-
1214
- ---
1215
-
1216
- # 🐛 Troubleshooting
1217
-
1218
- ## Styles are not updating after rotation
1219
-
1220
- Make sure you are using:
1221
-
1222
- ```
1223
- useStyles()
1224
-
1225
- ```
1226
-
1227
- for dynamic styles rather than creating static values with `StyleSheet.create()`.
1228
-
1229
- ---
1230
-
1231
- ## Tablet layout is not triggering
1232
-
1233
- Check the current width used by your application and the configured tablet threshold.
1234
-
1235
- You can inspect:
1236
-
1237
- ```
1238
- const r = useResponsive();
1239
-
1240
- console.log({
1241
- isTablet: r.isTablet,
1242
- isFold: r.isFold,
1243
- isPhone: r.isPhone,
1244
- isLandscape: r.isLandscape,
1245
- });
1246
-
1247
- ```
1248
-
1249
- ---
1250
-
1251
- ## My layout is still overflowing
1252
-
1253
- Responsive scaling does not automatically solve every layout problem.
1254
-
1255
- Also check:
1256
-
1257
- - Flexbox configuration
1258
- - `flexShrink`
1259
- - `flexWrap`
1260
- - text length
1261
- - minimum/maximum dimensions
1262
- - safe areas
1263
- - keyboard behavior
1264
- - accessibility font scaling
1265
-
1266
- ---
1267
-
1268
- # ðŸ“Ķ Package Philosophy
1269
-
1270
- This library intentionally focuses on one problem:
1271
-
1272
- > **Making React Native layouts easier to adapt to changing screen dimensions.**
1273
-
1274
- It does not try to become:
1275
-
1276
- - a UI framework
1277
- - a navigation library
1278
- - an animation framework
1279
- - a state manager
1280
- - a complete design system
1281
-
1282
- Small responsibility.
1283
-
1284
- Simple API.
1285
-
1286
- Predictable behavior.
1287
-
1288
- ---
1289
-
1290
- # ⭐ Support the Project
1291
-
1292
- If this library helps you build responsive React Native applications:
1293
-
1294
- ### ⭐ Star the project
1295
-
1296
- Stars help other developers discover the library.
1297
-
1298
- ### ðŸ“Ķ Install it
1299
-
1300
- Try it in your next React Native project.
1301
-
1302
- ### 🐛 Report issues
1303
-
1304
- Found something unexpected? Open an issue with a reproducible example.
1305
-
1306
- ### ðŸ’Ą Share feedback
1307
-
1308
- Ideas and real-world use cases help shape future releases.
1309
-
1310
- ### ðŸĪ Contribute
1311
-
1312
- Pull requests and documentation improvements are welcome.
1313
-
1314
- ---
1315
-
1316
- # ðŸ‘Ļ‍ðŸ’ŧ Author
1317
-
1318
- ## Dharmendra
1319
-
1320
- React Native / Full Stack Developer
1321
-
1322
- Building tools for modern React Native applications.
1323
-
1324
- ---
1325
-
1326
- # 📄 License
1327
-
1328
- MIT License
1329
-
1330
- Copyright ÂĐ Dharmendra
1331
-
1332
- ---
1333
-
1334
- ## ðŸ“ą Build Once. Adapt Everywhere.
1335
-
1336
- ### `react-native-dynamic-responsive`
276
+ ## 📄 License
1337
277
 
1338
- **Responsive UI for modern React Native applications.**
278
+ MIT ÂĐ [Dharmendra](https://www.linkedin.com/in/dharmendra-appdeveloper)