# react-native-cm-theme

> Quick add theme for react native app

Latest version **1.0.3** (published 2021-09-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-cm-theme
pnpm add react-native-cm-theme
yarn add react-native-cm-theme
bun add react-native-cm-theme
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2021-09-16 |
| First published | 2021-09-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | milker90 |
| Maintainers | milker90 |
| Keywords | react-native, react native theme, react native dark mode, dark mode, theme |

## Links

- npm: https://www.npmjs.com/package/react-native-cm-theme
- Repository: https://github.com/Milker90/react-native-cm-theme
- Homepage: https://github.com/Milker90/react-native-cm-theme#readme
- Issues: https://github.com/Milker90/react-native-cm-theme/issues
- npm.io page: https://npm.io/package/react-native-cm-theme

## Recent versions

- 1.0.3 (latest) — 2021-09-16
- 1.0.2 — 2021-09-15
- 1.0.1 — 2021-09-14
- 1.0.0 — 2021-09-14

## README

# react-native-cm-theme

## Install

`npm install react-native-cm-theme --save`

or

`yarn add react-native-cm-theme --save`

## Usage

### 1. Ready theme data

```
<!-- theme color -->
const CommonColors = {
    light: {
        m1: '#141414',
    },
    dark: {
        m1: '#ffffff',
    }
}

<!-- theme style -->
const CommonStyles = {
    light: {
        container: {
            backgroundColor: '#FFFFFF',
            flex: 1,
        },
    },
    dark: {
        container: {
            backgroundColor: '#080618',
            flex: 1,
        },
    },
};

<!-- theme image -->
const CommonImages = {
    light: {
        add_photo: require('@/assets/image/light/add_photo.png')
    },
    dark: {
        add_photo: require('@/assets/image/dark/add_photo.png'),
    },
};

<!-- data -->
const data = { themeColors: [CommonColors], themeStyles: CommonStyles, themeImages: CommonImages }
```

The key in the data represents a type of theme data. Its name can be customized. For example, the color can be defined as "themeColors" or "colors"; the json file can be defined as "themeJsons"; these keys will be used in UI components.

The value corresponding to the key can be an array or an object, the theme data included in the object, and the theme name can be customized, such as "light", "dark", "red", etc.

### 2. Make CMThemeProvider as root node

```
const App = () => {
  const theme = useColorScheme();
  return (
    <CMThemeProvider theme={theme} data={data}>
      <Root />
    </CMThemeProvider>
  );
};

export default App;
```

### 3. Use theme data in function component or class component

#### Use in function component

```
import { useTheme } from 'react-native-cm-theme';

const { theme, themeStyles, themeColors, themeImages } = useTheme();
```

#### Use in class component

```
import { CMTheme } from 'react-native-cm-theme';

return <CMTheme>{({theme, themeColors, themeStyles, themeImages }) => {children}</CMTheme>
```

"themeStyles", "themeColors", and "themeImages" are defined in the data, and you can customize your own.

---
_Source: https://npm.io/package/react-native-cm-theme · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
