color thief for react-native (ios & android)
npm install react-native-color-thiefA React Native node module that grabs the dominant color or a representative color palette from an image uri.
An adapted version of Sven Woltmann's fast color-thief-java and Kazuki Ohara's ColorThiefSwift from Lokesh Dhakar's original javascript project color-thief
``sh`
npm install react-native-color-thief --save
or using yarn
`sh`
yarn add react-native-color-thief
$ react-native link react-native-color-thief
Requirements
- Xcode 10.2
- Swift 5
- iOS 9
1. In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name]node_modules
2. Go to ➜ react-native-color-thief and add RNColorThief.xcodeprojlibRNColorThief.a
3. In XCode, in the project navigator, select your project. Add to your project's Build Phases ➜ Link Binary With LibrariesCmd+R
4. Run your project ()
1. Open up android/app/src/main/java/[...]/MainActivity.javaimport com.RNColorThief.RNColorThiefPackage;
- Add to the imports at the top of the filenew RNColorThiefPackage()
- Add to the list returned by the getPackages() methodandroid/settings.gradle
2. Append the following lines to :`
`
include ':react-native-color-thief'
project(':react-native-color-thief').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-color-thief/android')
android/app/build.gradle
3. Insert the following lines inside the dependencies block in :`
`
compile project(':react-native-color-thief')
and getPalette return a Promise.`javascript
import RNColorThief from 'react-native-color-thief';// get array of color objects [{ r, g, b }]
RNColorThief.getPalette(imageUri, colorCount, quality, includeWhite).then((palette) => {
console.log('palette', palette);
}).catch((error) => {
console.log('error', error);
});
// get dominant color object { r, g, b }
RNColorThief.getColor(imageUri, quality, includeWhite).then((color) => {
console.log('color', color);
}).catch((error) => {
console.log('error', error);
});
`
Showcase
This library is used by following apps. Please send a pull request if you are also using the library.
$3
* Playstore
* App store
* Github(Open source)Troubleshooting
1. (iOS) If you aren't currently using swift in your project, you may need to add a
dummy.swift` file with a bridging header in order to successfully build.