Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ilz5753 committed Dec 12, 2023
1 parent 696f951 commit 928ea60
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 20 deletions.
157 changes: 145 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,164 @@
# rnutils
# RNUtils (@ilz5753/rnutils) Comprehensive React Native Styling, Animation & Utils Library

React Native Utils
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](#features)
- [Installation](#installation)
- [Animated Components](#animated-components)
- [Animated Components Usage](#animated-components-usage)
- [Hooks](#hooks)
- [Utility Functions](#utility-functions)
- [API Reference](#api-reference)
- [Types](#types)
- [Static Styles Functions](#static-styles-functions)
- [Platform-Specific Utilities](#platform-specific-utilities)
- [Platform-Specific Utilities Usage](#platform-specific-utilities-usage)
- [Extensibility](#extensibility)
- [Contributing](#contributing)
- [License](#license)
- [Acknowledgments](#acknowledgments)

## 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

```sh
npm install rnutils
To install the library, run the following command in your React Native project:

```bash
npm install @ilz5753/rnutils
```

```bash
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.

```ts
import { ReView, ReText, ReTouchableOpacity } from '@ilz5753/@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:

```tsx
<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:

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

## Usage
## 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.

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

**`CustomDimensionValue`**

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

**`StrNum`**

```js
import { multiply } from 'rnutils';
A union type that embraces both string and number, facilitating flexible API design where both types are commonplace.

// ...
**`DerivedColor`**, **`DerivedDimension`**

const result = await multiply(3, 7);
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:

```ts
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

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
We welcome contributions to make RNUtils better for everyone. If you’re looking to contribute, please follow the guidelines in [CONTRIBUTION.md](/CODE_OF_CONDUCT.md). Your proposals, bug reports, and pull requests are appreciated.

## License

MIT
RNUtils is licensed under the MIT License. See the [LICENSE](/LICENSE) file for more details.

## Acknowledgments

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

---

Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
For more detailed usage and API information, please refer to the individual files pertaining to components, hooks, and utilities you wish to employ.

> This README covers a broad overview of RNUtils’ capabilities. For detailed API documentation and more specific examples for each utility, refer to the accompanying documentation provided in the library.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ilz5753/rnutils",
"version": "0.1.0",
"version": "0.1.1",
"description": "React Native Utils",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
8 changes: 5 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export {
useDimensionSizes,
useDimensionSizesStyle,
useNumberSizes,
useNumberSizesStyle,
useNumberSizesStyle
} from './dynamicStyles/reanimated';
export type {
CacheShareValue,
Expand All @@ -28,7 +28,7 @@ export type {
DerivedDimension,
DerivedNumber,
StrNum,
TWorkletFn,
TWorkletFn
} from './dynamicStyles/reanimated';
export {
Layout,
Expand Down Expand Up @@ -89,11 +89,13 @@ export {
tintColor,
top,
width,
zIndex,
zIndex
} from './staticStyles/functions';
export type {
BorderOrSpace,
BorderRadius,
Shadow,
ShadowOffset,
StyleKey
} from './staticStyles/functions';

6 changes: 3 additions & 3 deletions src/staticStyles/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ const CommonStyles = StyleSheet.create({
objectFit: 'scale-down',
},
});
type Key = keyof typeof CommonStyles | boolean;
export const getStyle = (keys?: Key[] | Key) => {
export type StyleKey = keyof typeof CommonStyles | boolean;
export const getStyle = (keys?: StyleKey[] | StyleKey) => {
let o: Record<string, any> = {};
let exe = (key: Key) => {
let exe = (key: StyleKey) => {
if (isString(key)) o = { ...o, ...CommonStyles[key] };
};
if (keys)
Expand Down
3 changes: 2 additions & 1 deletion src/staticStyles/functions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { capitalize } from 'lodash';
import type { ColorValue, DimensionValue } from 'react-native';
import { Platform } from 'react-native';
import { getStyle } from './common';
import { getStyle, type StyleKey } from './common';
export const backgroundColor = (backgroundColor?: ColorValue) => ({
backgroundColor,
});
Expand Down Expand Up @@ -562,3 +562,4 @@ export const row = getStyle('fdr');
export const pa = getStyle('pa');
export const overlay1 = [pa, zIndex(1)];
export const overlayMax = [pa, zIndex(10e12)];
export type { StyleKey };

0 comments on commit 928ea60

Please sign in to comment.