Skip to content

Commit 436e01c

Browse files
author
Raúl Gómez Acuña
authored
Feat/docs prerelease (#39)
1 parent 7e1dfa2 commit 436e01c

4 files changed

Lines changed: 164 additions & 130 deletions

File tree

README.md

Lines changed: 22 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@
22

33
>
44
5-
<a title="Join on Slack" href="https://slack.callstack.io"><img src="https://slack.callstack.io/badge.svg" /></a> [![CircleCI](https://circleci.com/gh/callstack-io/react-native-material-palette/tree/master.svg?style=shield)](https://circleci.com/gh/callstack-io/react-native-material-palette/tree/master) [![Coverage Status](https://coveralls.io/repos/github/callstack-io/react-native-material-palette/badge.svg?branch=master)](https://coveralls.io/github/callstack-io/react-native-material-palette?branch=master)
5+
<a title="Join on Slack" href="https://slack.callstack.io"><img src="https://slack.callstack.io/badge.svg" /></a> [![npm version](https://badge.fury.io/js/react-native-material-palette.svg)](https://badge.fury.io/js/react-native-material-palette) [![CircleCI](https://circleci.com/gh/callstack-io/react-native-material-palette/tree/master.svg?style=shield)](https://circleci.com/gh/callstack-io/react-native-material-palette/tree/master) [![Coverage Status](https://coveralls.io/repos/github/callstack-io/react-native-material-palette/badge.svg?branch=master)](https://coveralls.io/github/callstack-io/react-native-material-palette?branch=master)
66

7-
## Install
7+
[Android Palette API](https://developer.android.com/training/material/palette-colors.html) brought to react native. It extracts prominent colors from images to help you create visually engaging apps. At the moment it only supports Android.
8+
9+
## Installation
810

911
Installation and setup guide can be found here: [Setup guide](./docs/SETUP.md).
1012

13+
## Usage with `createMaterialPalette`
14+
15+
```js
16+
import { createMaterialPalette } from "react-native-material-palette";
17+
18+
const palette = await createMaterialPalette({ uri: 'http://dummySite/images/yummy.jpg' });
19+
```
20+
1121
## Usage with `MaterialPaletteProvider` and `withMaterialPalette`
1222

13-
```javascript
23+
```js
1424
import { MaterialPaletteProvider, withMaterialPalette } from 'react-native-material-palette';
1525

1626
const PaletteView = withMaterialPalette(
@@ -38,92 +48,19 @@ const PaletteView = withMaterialPalette(
3848
</MaterialPaletteProvider>
3949
```
4050

41-
The API documentation can be found here: [API documntation](./docs/API.md).
42-
43-
## Usage As API
44-
45-
### `createMaterialPalette()`
46-
47-
```js
48-
// Number is the opaque type returned by require('./image.jpg')
49-
type Image = number | { uri: string }
50-
51-
type ColorProfile =
52-
| 'muted'
53-
| 'vibrant'
54-
| 'darkMuted'
55-
| 'darkVibrant'
56-
| 'lightMuted'
57-
| 'lightVibrant'
58-
59-
type Options = {
60-
region?: { top: number, left: number, bottom: number, right: number },
61-
maximumColorCount?: number = 16,
62-
type?: ColorProfile | Array<ColorProfile> = 'vibrant',
63-
}
64-
65-
type Swatch = {
66-
population: number, // number of pixels
67-
color: string, // color for swatch,
68-
bodyTextColor: string, // appropriate color to use for any 'body' text
69-
titleTextColor: string, // appropriate color to use for any 'title' text
70-
}
71-
72-
type DefaultSwatch = {
73-
color: string,
74-
bodyTextColor: string,
75-
titleTextColor: string,
76-
};
77-
78-
type PaletteDefaults = {
79-
[key: ColorProfile]: DefaultSwatch,
80-
};
81-
82-
PaletteInstance = {
83-
[key: ColorProfile]: ?Swatch,
84-
};
85-
86-
createMaterialPalette: (image: Image, options?: Options, defaults?: PaletteDefaults) => Promise<PaletteInstance>
87-
```
88-
89-
#### Examples
90-
91-
##### Creating a palette from a network resource, with 'vibrant' color profile, maximumColorCount = 16 and the whole region of the image (default behaviour)
92-
```js
93-
import { createMaterialPalette } from "react-native-material-palette";
94-
95-
const palette = await createMaterialPalette({ uri: 'http://dummySite/images/yummy.jpg' });
96-
```
51+
## API
52+
Full API documentation can be found here: [API documentation](./docs/API.md).
9753

98-
##### Creating a palette from an internal image asset, with 'muted' and 'lightVibrant' color profiles, maximumColorCount = 32 and a specific region of the image
99-
```js
100-
import { createMaterialPalette } from "react-native-material-palette";
54+
## Future work
55+
- [ ] iOS support
56+
- [ ] Providing own color profiles
10157

102-
const palette = await createMaterialPalette(require('./assets/image.jpg'), {
103-
region: { top: 0, left: 0, bottom: 50, right: 50},
104-
maximumColorCount: 32,
105-
type: ['muted', 'lightVibrant'],
106-
});
107-
```
58+
## Example app
59+
The repo includes an example app that covers all the API cases. Go [here](./example) to try it out!
10860

109-
##### Creating a palette from an internal image asset and custom defaults
110-
```js
111-
import { createMaterialPalette } from "react-native-material-palette";
61+
![image](https://user-images.githubusercontent.com/4982414/29331952-92fd2cfc-81fe-11e7-9ef3-25f0e17a0c62.png)
11262

113-
const palette = await createMaterialPalette(
114-
require('./assets/image.jpg'),
115-
{
116-
type: ['lightVibrant', 'darkMuted'],
117-
},
118-
{
119-
darkMuted: {
120-
color: '#000000',
121-
bodyTextColor: '#B2B2B2',
122-
titleTextColor: '#F4F4F4',
123-
},
124-
},
125-
);
126-
```
63+
![image](https://user-images.githubusercontent.com/4982414/29332055-f2e25ffc-81fe-11e7-87de-3473d2d74573.png)
12764

12865
## Development
12966

docs/API.md

Lines changed: 107 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,107 @@
11
# API
22

3+
## `createMaterialPalette()`
4+
5+
```js
6+
createMaterialPalette(
7+
image: Image,
8+
options?: Options,
9+
defaults?: PaletteDefaults,
10+
): Promise<PaletteInstance>
11+
12+
// Number is the opaque type returned by require('./image.jpg')
13+
type Image = number | { uri: string }
14+
15+
type Options = {
16+
region?: { top: number, left: number, bottom: number, right: number },
17+
maximumColorCount?: number = 16,
18+
type?: ColorProfile | Array<ColorProfile> = 'vibrant',
19+
}
20+
21+
type PaletteDefaults = {
22+
[key: ColorProfile]: DefaultSwatch,
23+
};
24+
25+
type PaletteInstance = {
26+
[key: ColorProfile]: ?Swatch,
27+
};
28+
29+
type Swatch = {
30+
population: number, // number of pixels
31+
color: string, // color for swatch,
32+
bodyTextColor: string, // appropriate color to use for any 'body' text
33+
titleTextColor: string, // appropriate color to use for any 'title' text
34+
}
35+
36+
type ColorProfile =
37+
| 'muted'
38+
| 'vibrant'
39+
| 'darkMuted'
40+
| 'darkVibrant'
41+
| 'lightMuted'
42+
| 'lightVibrant';
43+
44+
type DefaultSwatch = {
45+
color: string,
46+
bodyTextColor: string,
47+
titleTextColor: string,
48+
};
49+
50+
```
51+
52+
### Description
53+
`createMaterialPalette` is a function that returns a Promise that when resolved, will provide a palette instance with color information about the image provided.
54+
55+
### Arguments
56+
* `image: Image` (__required__) - Local image to create palette from (`require('path/to/image')`) or object with remote URI adress from which the image can be downloaded (`{ uri: 'http://some-domain.ext/image.png' }`).
57+
58+
* `options?: Options` (optional) - Options for palette creation.
59+
* `region` - Indicates what area of the bitmap the builder uses when creating the palette.
60+
* `maximumColorCount` - Sets the maximum number of colors in your palette. The default value is 16, and the optimal value depends on the source image. For landscapes, optimal values range from 8-16 while pictures with faces usually have values that fall between 24-32.
61+
* `type` - Color profiles we aim to target. Defaults to `vibrant`
62+
63+
64+
* `defaults?: PaletteDefaults` (optional) - Defaults which will be used, if the specific color profile is not found.
65+
66+
### Examples
67+
68+
#### Creating a palette from a network resource, with 'vibrant' color profile, maximumColorCount = 16 and the whole region of the image (default behaviour)
69+
```js
70+
import { createMaterialPalette } from "react-native-material-palette";
71+
72+
const palette = await createMaterialPalette({ uri: 'http://dummySite/images/yummy.jpg' });
73+
```
74+
75+
#### Creating a palette from an internal image asset, with 'muted' and 'lightVibrant' color profiles, maximumColorCount = 32 and a specific region of the image
76+
```js
77+
import { createMaterialPalette } from "react-native-material-palette";
78+
79+
const palette = await createMaterialPalette(require('./assets/image.jpg'), {
80+
region: { top: 0, left: 0, bottom: 50, right: 50},
81+
maximumColorCount: 32,
82+
type: ['muted', 'lightVibrant'],
83+
});
84+
```
85+
86+
#### Creating a palette from an internal image asset and custom defaults
87+
```js
88+
import { createMaterialPalette } from "react-native-material-palette";
89+
90+
const palette = await createMaterialPalette(
91+
require('./assets/image.jpg'),
92+
{
93+
type: ['lightVibrant', 'darkMuted'],
94+
},
95+
{
96+
darkMuted: {
97+
color: '#000000',
98+
bodyTextColor: '#B2B2B2',
99+
titleTextColor: '#F4F4F4',
100+
},
101+
},
102+
);
103+
```
104+
3105
## `MaterialPaletteProvider`
4106
5107
### Example of usage:
@@ -34,39 +136,14 @@ class App extends React.Component {
34136
The concept is very similar to `Provider` component from `react-redux`.
35137
36138
### Props
37-
* `image: Image` (__required__) - Local image to create palette from (`require('path/to/image')`) or object with remote URI adress from which the image can be downloaded (`{ uri: 'http://some-domain.ext/image.png' }`) - same as `image` in `MaterialPalette.create` function.
139+
* `image: Image` (__required__) - same as `image` in `createMaterialPalette` function.
38140
39-
* `options?: Options` (optional) - Options for palette creation - same as `options` in `MaterialPalette.create` function:
40-
```javascript
41-
type Options = {
42-
region?: { top: number, left: number, bottom: number, right: number },
43-
maximumColorCount?: number = 16,
44-
type?: ColorProfile | Array<ColorProfile> = 'vibrant',
45-
}
46-
```
141+
* `options?: Options` (optional) - same as `options` in `createMaterialPalette` function.
47142
48-
* `defaults?: PaletteDefaults` (optional) - Global defaults which will be propagated to each _connected_ component, alongside with palette instance, which will be used, if the specific color profile is not found:
49-
```javascript
50-
type ColorProfile =
51-
| 'muted'
52-
| 'vibrant'
53-
| 'darkMuted'
54-
| 'darkVibrant'
55-
| 'lightMuted'
56-
| 'lightVibrant';
57-
58-
type DefaultSwatch = {
59-
color: string,
60-
bodyTextColor: string,
61-
titleTextColor: string,
62-
};
63-
64-
type PaletteDefaults = {
65-
[key: ColorProfile]: DefaultSwatch,
66-
};
67-
```
143+
* `defaults?: PaletteDefaults` (optional) - Global defaults which will be propagated to each _connected_ component, alongside with palette instance, which will be used, if the specific color profile is not found.
68144
69145
* `forceRender?: boolean` (optional) - Forces to render the children regardless whether the palette is being created. __Does not take effect if `LoaderComponent` is specified!__
146+
70147
* `LoaderComponent: React$Component<*, *, *> | ((...args: *) => React$Element<*>)` (optional) - If specified, will render the passed component while waiting for palette to be created:
71148
* `<MateriaPaletteProvider LoaderComponent={SpinnerComponent}>` - will render `SpinnerComponent`,
72149
* `<MateriaPaletteProvider LoaderComponent={() => <Text>Loading</Text>)}>` - will render `Text` component with _Loading_.
@@ -96,7 +173,7 @@ export default withMaterialPalette(
96173
```
97174
98175
### Description
99-
`withMaterialPalette` is a function that returns a Higher Order Component (HOC), which allows to seemlessy _connect_ to the `MaterialPaletteProvider` and get the palette instance via context.
176+
`withMaterialPalette` is a function that returns a Higher Order Component (HOC), which allows to seamlessly _connect_ to the `MaterialPaletteProvider` and get the palette instance via context.
100177
101178
Under the hood, it is a function factory (it returns a new function), similarily to `connect` from `react-redux`, to allow to be used as a decorator:
102179
```javascript

docs/SETUP.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22

33
`react-native-material-palette` is a native module written in Kotlin, thus you need to follow the instructions below in order to set it up.
44

5-
Once the React Native team releases a new version with the [following change](https://github.com/facebook/react-native/commit/d666f30665e4cd336e1a1017954447f486a3e8ce), you will be able to use `react-native link react-native-material-palette`, but for now you have to do it manually.
6-
7-
## Compatibility
8-
9-
Material Palette SDK is __only available in Android 24 or higher__. We __recommend__ using version __25__.
10-
11-
If you're using a lower version, you need to add
12-
```
13-
compile 'com.android.support:support-v4:24.2.0'
14-
```
15-
to `andoid/app/src/build.gradle` in `dependencies` section.
16-
175
## Setup instructions
186

197
1. Install module using npm or yarn:
8+
```bash
9+
yarn add react-native-material-palette
2010
```
21-
$ yarn add react-native-material-palette
11+
12+
### RN 0.47 or higher
13+
14+
2. Link the native library's dependencies
15+
```bash
16+
react-native link react-native-material-palette
2217
```
2318

19+
### RN < 0.47
20+
Linking modules written in Kotlin is only supported from RN 0.47 on. For lower versions, you'll have to follow the manual steps described below:
21+
2422
2. Add the following lines to `android/settings.gradle`:
2523
```diff
2624
rootProject.name = 'YourProjectName'
@@ -54,14 +52,15 @@ public class MainApplication extends Application implements ReactApplication {
5452

5553
```
5654

57-
4. Add the following line to `android/app/src/build.gradle`:
55+
4. Do the following changes to `android/app/src/build.gradle`:
5856
```diff
5957
// ...
6058

6159
dependencies {
6260
+ compile project(':react-native-material-palette')
6361
compile fileTree(dir: "libs", include: ["*.jar"])
64-
compile "com.android.support:appcompat-v7:25.0.1" // Or version 24, depends on your project compileSdkVersion
62+
- compile "com.android.support:appcompat-v7:23.0.1"
63+
+ compile "com.android.support:appcompat-v7:24.0.1" // Or version 25, depends on your project compileSdkVersion
6564
compile "com.facebook.react:react-native:+" // From node_modules
6665
}
6766

example/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Example App
2+
In order to run the example you need to:
3+
4+
1. Clone the repository
5+
6+
2. Go to example folder
7+
8+
```bash
9+
$ cd example
10+
```
11+
12+
3. Install dependencies
13+
14+
```bash
15+
$ yarn
16+
```
17+
18+
4. Run the app
19+
```bash
20+
react-native run-android
21+
```

0 commit comments

Comments
 (0)