Socket
Socket
Sign inDemoInstall

react-native-vibrant-color

Package Overview
Dependencies
452
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-native-vibrant-color

A library to extract dominant colors from images in react-native


Version published
Weekly downloads
8
increased by166.67%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

*NOTE: * This was forked from hu9osaez to get support for promises which he did not release

react-native-vibrant-color

PRs Welcome Extract the dominant colors of an image (Just for Android).

Getting started

$ npm install react-native-vibrant-color --save

Mostly automatic installation

$ react-native link react-native-vibrant-color

Manual installation

Android
  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.idanlo.rnvibrantcolor.RNVibrantColorPackage; to the imports at the top of the file
  • Add new RNVibrantColorPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-vibrant-color'
    project(':react-native-vibrant-color').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-vibrant-color/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-vibrant-color')
    

Usage

import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';
import { colorsFromUrl } from 'react-native-vibrant-color';

const imageUrl = 'https://source.unsplash.com/random/800x600';

const styles = StyleSheet.create({
    container: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center'
    },
    image: {
        width: 300,
        height: 300,
        borderRadius: 10
    }
});

class Example extends Component {
    constructor() {
        super();
        this.state = {
            color: '#ffffff',
        };
    }

    componentWillMount() {
        colorsFromUrl(imageUrl).then(colors => {
            self.setState({ color: colors.averageColor });
        });
    }

    render() {
        return (
            <View style={[styles.container, {backgroundColor: this.state.color }]}>
                <Image style={styles.image} source={{ uri: imageUrl}} />
            </View>
        );
    }
}

API

Methods
  • colorsFromUrl(imageUrl): Promise resolves an object with the prominent colors from the image. Object properties are averageColor, dominantColor, vibrantColor, darkVibrantColor and lightVibrantColor. If some color doesn't exist will return #CCCCCC.

Keywords

FAQs

Last updated on 01 Apr 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc