Skip to content

Crafting seamless UI/UX in React Native with RNUtils 🚀 Passionate about bridging design and code Contributing to fluid mobile experiences one animation at a time 💫

License

Notifications You must be signed in to change notification settings

ilz5753/rnutils

Repository files navigation

RNUtils (@ilz5753/rnutils) Comprehensive React Native Styling, Animation & Utils Library

RNUtils is an all-encompassing library designed to provide React Native developers with an extensive suite of tools for creating dynamic styles, animations, and utility functions for an improved developer experience and efficient, clean codebases.

Table of Contents

Features

  • A range of Animated Components for improved user experiences with smooth animations
  • Hooks that tap into Reanimated 3(3.3.0) for fluid animations and gestures
  • Regular expressions to identify numeric and percentage-based values
  • Utility functions to streamline common style pattern generations
  • Type support for TypeScript users to leverage strong typing throughout their styles

Installation

To install the library, run the following command in your React Native project:

npm install @ilz5753/rnutils
yarn add @ilz5753/rnutils

Animated Components

The library wraps common React Native components, providing animated versions that can be used interchangeably to enhance your application.

import { ReView, ReText, ReTouchableOpacity } from '@ilz5753/rnutils';

Animated Components Usage

These components act as drop-in replacements for their React Native equivalents, now with support for animated styles generated by Reanimated:

<ReView>
  <ReText>This is animated text within an animated view.</ReText>
</ReView>

Hooks

RNUtils provides a rich set of hooks for working with shared and derived values, easing the animation process with tools for color, dimension, and number interpolations.

useCacheShareValue

This hook manages a shared value for animations with a caching mechanism that memorizes the previous and current states to facilitate reversed or repeated animations.

useColors

Provides a suite of animated styles based on a single color value for different properties including backgroundColor, borderColor, and more.

useNumberSizes

Generate numeric size-based styles like flex, borderRadius, or fontSize that are animatable.

useDimensionSizes

Manipulate dimensions like width, height, margin, and padding with animated support for fluidly responsive designs.

Utility Functions

The library includes numerous utility functions to aid in quick style generation, border radii control, color manipulations, shadow handling, and layout shortcuts, along with others that determine the current operating system for conditional styling logic.

getStyle

Retrieve predefined styles for common needs using design tokens:

const center = getStyle(['aic', 'jcc']); // Align items center, Justify content center

API Reference

For in-depth documentation on the API, including all methods, hooks, and components, please refer to the included API documentation in the package.

Types

TypeScript users can employ RNUtils’ comprehensive types to enforce strict typing throughout their styling code. The library exports types for every provided function and utility, ensuring that errors can be caught at compile-time.

import type {
  CustomDimensionValue,
  StrNum,
  DerivedColor,
  DerivedDimension,
} from '@ilz5753/rnutils';

CustomDimensionValue

Allows either a number or a string percentage value, supporting dynamic dimensions.

StrNum

A union type that embraces both string and number, facilitating flexible API design where both types are commonplace.

DerivedColor, DerivedDimension

Wrap Reanimated’s DerivedValue for specific use-cases like colors and dimensions, associating strong typing with animated values.

Static Styles Functions

With a focus on flexibility, static functions are provided to create scalable styles with minimal code, perfect for a range of scenarios from theming to dynamic user-driven styles.

Platform-Specific Utilities

Detect the current platform using booleans like isAndroid or isIos, or check for mobile environments in general with isMobile.

Platform-Specific Utilities Usage

Import and use functions directly within your style definitions:

import { backgroundColor, flex, Layout } from '@ilz5753/rnutils';

const styles = {
  ...backgroundColor('blue'),
  ...flex(1),
  ...Layout('50%', '25%'),
};

Extensibility

RNUtils is designed to be extensible, working alongside your existing solutions and third-party libraries, allowing for broad compatibility and comprehensive styling control within React Native.

Contributing

We welcome contributions to make RNUtils better for everyone. If you’re looking to contribute, please follow the guidelines in CONTRIBUTION.md. Your proposals, bug reports, and pull requests are appreciated.

License

RNUtils is licensed under the MIT License. See the LICENSE file for more details.

Acknowledgments

Special thanks to all the contributors and the open-source community for their ongoing support and inspiration.


For more detailed usage and API information, please refer to the individual files pertaining to components, hooks, and utilities you wish to employ.

About

Crafting seamless UI/UX in React Native with RNUtils 🚀 Passionate about bridging design and code Contributing to fluid mobile experiences one animation at a time 💫

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published