Introduction
“One codebase, every screen size. Scale automatically, adapt intelligently, switch layouts when needed.”
A lightweight, zero-dependency utility for creating responsive layouts in React Native and Expo.
Example.tsx
import {
s, responsive, createScaledStyles,
ResponsiveSwitch, useDeviceType,
} from "@vincent-huy-uit/react-native-responsive-ui";
export default function Example() {
const device = useDeviceType(); // "mobile" | "tablet" | "desktop"
// responsive() - different values per device
const columns = responsive({ mobile: 1, tablet: 2, desktop: 3 });
return (
<View style={styles.container}>
{/* s() - scale individual values */}
<Text style={{ fontSize: s(20) }}>
Device: {device} | Columns: {columns}
</Text>
{/* ResponsiveSwitch - render different components */}
<ResponsiveSwitch
mobile={<MobileCard />}
tablet={<TabletCard />}
/>
</View>
);
}
// createScaledStyles() - auto-scale all numeric values
const styles = createScaledStyles({
container: { flex: 1, padding: 16 },
card: { padding: 16, borderRadius: 12 },
});375px
Phone768px
Tablet1440px
DesktopAUTO SCALE
One library, complete responsive toolkit
Scale values with s(), switch values per device with responsive(), auto-scale styles with createScaledStyles(), and render different layouts with ResponsiveSwitch.
When to use linear scaling
Typography
Font sizes, line heights, and letter spacing that remain readable and proportional across all devices.
Spacing & Layout
Padding, margins, gaps, and border radii that maintain visual harmony from phones to tablets.
Iconography
Icon sizes and touch targets that scale appropriately while staying crisp and tappable.