Building responsive user interfaces in React Native can quickly become challenging when an application needs to seamlessly support different screen sizes, orientations, tablets, split-screen multi-tasking, and foldable displays.
To simplify this workflow without introducing a heavy styling framework, I created react-native-dynamic-responsive â a lightweight, TypeScript-first responsive UI utility for React Native and Expo applications.
ðĶ Package Specifications
| Specification | Detail |
|---|---|
| Package Name | react-native-dynamic-responsive |
| Version | 1.0.2 |
| License | MIT |
| Compatibility | React Native CLI & Expo (including Expo Router) |
| Runtime Dependencies | 0 (Zero) |
| TypeScript | First-class native support with full typings |
Why I Built This
A traditional and widespread approach to responsive React Native development is repeatedly calling Dimensions.get('window') or useWindowDimensions() and manually calculating pixel ratios or percentages inside every component file:
// Traditional repetitive approach
const { width, height } = Dimensions.get('window');
const isTablet = width >= 768;
const cardWidth = isTablet ? width * 0.7 : width * 0.9;
While this works for simple prototypes, as an enterprise application grows, responsive calculations become repetitive, scattered across dozens of components, and difficult to maintain.
Modern devices also make responsive design more dynamic than ever before:
$$\text{Phone} \longrightarrow \text{Rotation} \longrightarrow \text{Landscape} \longrightarrow \text{Split Screen} \longrightarrow \text{Tablet} \longrightarrow \text{Foldable} \longrightarrow \text{Dynamic Window}$$
The core design philosophy of react-native-dynamic-responsive is simple:
Write responsive styles once and let the layout automatically adapt to the current screen dimensions and orientation.
ðą Responsive UI Across All Form Factors
The library is designed to work reliably across the entire modern hardware ecosystem:
- ðą Standard Phones (Compact to Pro Max viewports)
- ðē Tablets & iPads (iPadOS Stage Manager, split views)
- ð Portrait & Landscape Orientations (Dynamic rotation handling)
- ð Foldable Devices (Samsung Galaxy Fold / Flip, Google Pixel Fold, inner/outer display transitions)
- ðŠ Dynamic Window Dimensions (Android Freeform windows, desktop environments)
- âïļ React Native CLI & ð Expo / Expo Router
- ð 100% TypeScript
Instead of writing separate style sheets or branching conditional checks for every device, you can leverage a single declarative API throughout your codebase.
⥠The useStyles() API
The recommended pattern is the useStyles() hook, which accepts a style creator function that receives a responsive context object (r):
import React from 'react';
import { View, Text } from 'react-native';
import { useStyles } from 'react-native-dynamic-responsive';
export const AdaptiveProfileCard = () => {
const styles = useStyles((r) => ({
card: {
width: r.isTablet ? r.wp(70) : r.wp(92),
padding: r.ms(16),
marginVertical: r.vs(12),
borderRadius: r.ms(12),
backgroundColor: '#FFFFFF',
alignSelf: 'center',
flexDirection: r.isLandscape ? 'row' : 'column',
},
title: {
fontSize: r.ms(22),
fontWeight: '700',
color: '#0F172A',
marginBottom: r.vs(6),
},
body: {
fontSize: r.ms(14),
color: '#475569',
lineHeight: r.ms(20),
},
}));
return (
<View style={styles.card}>
<Text style={styles.title}>Responsive Engineering</Text>
<Text style={styles.body}>
One codebase that renders flawlessly on mobile phones, tablets, and foldables.
</Text>
</View>
);
};
Built-in Responsive Helpers
The responsive context (r) provides intuitive utilities for sizing, spacing, width, height, and typography:
r.wp(percentage): Computes responsive width based on a percentage of the viewport width.r.hp(percentage): Computes responsive height based on a percentage of the viewport height.r.s(size): Standard scale based on guideline base width (defaults to standard 375pt mobile reference).r.vs(size): Vertical scale based on guideline base height (defaults to 812pt mobile reference).r.ms(size, factor?): Moderate scale for font sizes and border radii, preventing UI elements from ballooning excessively on massive screens.r.isTablet: Boolean flag indicating whether the current viewport meets tablet thresholds.r.isLandscape: Boolean flag indicating active landscape orientation.
ð Dynamic Screen Changes & Foldables
Responsive design is not merely about static device detection. Viewport dimensions change dynamically during runtime:
- Device Rotation: User rotates from Portrait to Landscape.
- Split Screen: Android multi-window or iPad Split View changes aspect ratio on the fly.
- Fold / Unfold: Device expands from a compact outer cover screen to a large square inner display.
- Desktop Modes: Samsung DeX or external display connections.
react-native-dynamic-responsive listens to screen metric updates and recalculates styles only when relevant dimension changes occur, guaranteeing smooth transitions without UI stutter.
ðŠķ Zero Runtime Dependencies
One of the central architectural goals was minimizing bundle overhead:
- 0 Runtime Dependencies: No bloated styling engines or heavy native bridges.
- Peer Dependencies: React and React Native are consumed as peer dependencies.
- Tiny Footprint: Extremely fast parse and execution times, critical for performance-conscious mobile applications.
ð Installation & Setup
Install the package via your preferred package manager:
# Using Yarn (Recommended)
yarn add react-native-dynamic-responsive
# Using npm
npm install react-native-dynamic-responsive
No additional native code modifications, pod installations, or configuration steps are required. The package works seamlessly across:
- Expo managed workflow
- Expo Router
- Bare React Native CLI projects
ðĪ Why Not Just Use Dimensions Directly?
React Native's built-in Dimensions API is great, but manually wiring listeners in every component leads to code duplication, memory leak hazards from uncleaned listeners, and messy component bodies.
By delegating responsive calculations to the style layer via useStyles:
- Component logic remains clean: Your component renders JSX rather than calculating math.
- Predictable memoization: Styles recalculate efficiently when dimensions shift.
- Consistency: The entire design system shares identical scaling references (
wp,hp,ms).
ðŊ Design Philosophy
- Keep the API Small: Developers shouldn't have to learn an expansive framework just to scale fonts and paddings.
- Prefer Familiar Concepts: Sizing primitives (
s,vs,ms,wp,hp) are battle-tested and intuitive. - Dynamic by Default: Viewports are fluid, especially in the era of foldables and tablets.
- Zero Bloat: No third-party runtime dependencies.
- TypeScript-First: Full autocomplete and strict type safety out of the box.
ð Build Once, Adapt Everywhere
The vision for react-native-dynamic-responsive is clear: One responsive styling API across all form factors.
Build your components once and let them gracefully adapt across standard phones, landscape setups, iPads, Android tablets, and foldable phones.
ðĶ Get Started
- NPM Package:
react-native-dynamic-responsive - GitLab Repository: code_dharmendra/react-native-dynamic-responsive
- License: MIT
If you are building React Native or Expo applications, give react-native-dynamic-responsive a try and share your feedback or contributions!