0.1.2 • Published 6 months ago

@doj/react-native-responsive-kit v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

npm License Downloads

šŸ“¦ @doj/react-native-responsive-kit

A lightweight, dynamic utility kit for building responsive and consistent designs across all devices in React Native. Includes utilities for screen width, screen height, status bar height, responsive sizes, spacing, gaps, font sizes, and hooks for real-time updates.


✨ Features

  • šŸ“± Responsive width and height helpers
  • šŸ”  Responsive text and element sizing (rs)
  • šŸ“ Always up-to-date screen dimensions
  • šŸŽÆ Consistent spacing and gap utilities
  • šŸ”” Predefined responsive font sizes
  • ā™»ļø useSizes() hook to dynamically track screen changes (rotation, resizing)
  • šŸ›”ļø Safe and type-friendly

šŸ“„ Installation

npm install @doj/react-native-responsive-kit

or

yarn add @doj/react-native-responsive-kit

šŸš€ Usage

import {
  wp,
  hp,
  rs,
  sizes,
  spacing,
  gap,
  fontSizes,
  useSizes,
} from '@doj/react-native-responsive-kit';

šŸ“ Responsive Width and Height

import { wp, hp } from '@doj/react-native-responsive-kit';

<View
  style={{
    width: wp(80), // 80% of screen width
    height: hp(20), // 20% of screen height
  }}
/>;

šŸ”  Responsive Text and Sizes

import { rs } from '@doj/react-native-responsive-kit';

<Text style={{ fontSize: rs(16) }}>Responsive Text</Text>

<View style={{ padding: rs(10) }}>
  <Text>Button</Text>
</View>

šŸ“ Access Device Sizes

import { sizes } from '@doj/react-native-responsive-kit';

console.log(sizes.screenWidth); // current device screen width
console.log(sizes.screenHeight); // current device screen height
console.log(sizes.statusBarHeight); // current status bar height

šŸŽÆ Consistent Spacing

import { spacing } from '@doj/react-native-responsive-kit';

<View
  style={{
    padding: spacing.md,
    marginBottom: spacing.lg,
  }}
/>;
NameSize (Responsive)
spacing.xsExtra Small (~4)
spacing.smSmall (~8)
spacing.mdMedium (~16)
spacing.lgLarge (~24)
spacing.xlExtra Large (~32)
spacing.xl22x Extra Large (~40)
spacing.xl33x Extra Large (~48)
spacing.xl44x Extra Large (~56)
spacing.xl55x Extra Large (~64)
spacing.xl66x Extra Large (~72)
spacing.xl77x Extra Large (~80)
spacing.xl88x Extra Large (~88)
spacing.xl99x Extra Large (~96)
spacing.xl1010x Extra Large (~104)

Spacing is automatically responsive using rs() scaling!


āž– Add Gaps Between Flex Children

import { gap } from '@doj/react-native-responsive-kit';

<View style={[{ flexDirection: 'row' }, gap('md')]}>
  <Text>Item 1</Text>
  <Text>Item 2</Text>
</View>;

āœ… Works in flex containers without needing gap support from React Native!


šŸ”” Predefined Responsive Font Sizes

import { fontSizes } from '@doj/react-native-responsive-kit';

<Text style={{ fontSize: fontSizes['2xl'] }}>Responsive Heading</Text>;
NameSize (responsive)
fontSizes.xsExtra Small (~10)
fontSizes.smSmall (~12)
fontSizes.mdMedium (~14)
fontSizes.lgLarge (~16)
fontSizes.xlExtra Large (~18)
fontSizes.xl22x Extra Large (~20)
fontSizes.xl33x Extra Large (~24)
fontSizes.xl44x Extra Large (~28)
fontSizes.xl55x Extra Large (~32)
fontSizes.xl66x Extra Large (~36)
fontSizes.xl77x Extra Large (~40)
fontSizes.xl88x Extra Large (~44)
fontSizes.xl99x Extra Large (~48)
fontSizes.xl1010x Extra Large (~52)
fontSizes.xl1111x Extra Large (~56)
fontSizes.xl1212x Extra Large (~60)
fontSizes.xl1313x Extra Large (~64)
fontSizes.xl1414x Extra Large (~68)
fontSizes.xl1515x Extra Large (~72)
fontSizes.xl1616x Extra Large (~76)

ā™»ļø useSizes() Hook

import { useSizes } from '@doj/react-native-responsive-kit';

const { screenWidth, screenHeight, wp, hp, rs, spacing, gap, fontSizes } =
  useSizes();

console.log('Width:', screenWidth);
console.log('Height:', screenHeight);

āœ… Always stays updated if the device rotates or resizes!


šŸ› ļø API Reference

NameTypeDescription
wp(percentage: number)numberGet width as % of screen width
hp(percentage: number)numberGet height as % of screen height
rs(size?: number \| null \| undefined)numberGet a scaled responsive size
sizes.screenWidthnumberDevice screen width (live)
sizes.screenHeightnumberDevice screen height (live)
sizes.statusBarHeightnumberStatus bar height
spacingobjectPredefined consistent responsive spacings
gap(size: keyof typeof spacing)objectFlex gap utility using spacing keys
fontSizesobjectPredefined responsive font sizes
useSizes(){ screenWidth, screenHeight, statusBarHeight, wp, hp, rs, spacing, gap, fontSizes }React Hook version, always up-to-date

🧩 How rs() Works

  • If you pass a value (rs(16)), it scales it based on the current screen height.
  • If you don't pass a value (rs(undefined)), it falls back to a default size calculated from height.

This makes it super reliable for fonts, icons, paddings, margins, etc.


šŸ“š Example

import {
  wp,
  hp,
  rs,
  spacing,
  fontSizes,
  gap,
} from '@doj/react-native-responsive-kit';

const App = () => {
  return (
    <View
      style={{
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
        ...gap('lg'),
      }}
    >
      <View
        style={{
          width: wp(90),
          height: hp(25),
          backgroundColor: 'lightblue',
          borderRadius: spacing.sm,
          padding: spacing.md,
          justifyContent: 'center',
          alignItems: 'center',
        }}
      >
        <Text style={{ fontSize: fontSizes['2xl'] }}>Responsive Box</Text>
      </View>
    </View>
  );
};

šŸ’° Support the Project

If you find this project useful and would like to support the development, you can donate via the following platforms:

ā˜• Buy Me A Coffee

Buy me a coffee

šŸ’Ž Patreon

Become a Patron on Patreon

Your contributions will help keep this project active and improve its features. Thank you for your support! šŸ™


šŸ›”ļø License

MIT License Ā© 2025 Daddy Omar Jeng