Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-hsv-picker

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-hsv-picker

A React-Native HSV (Hue, Saturation & Value) color picker

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-hsv-picker

a react native HSV(hue, saturation, value) color picker

Originally authored by Yuan Fu react-native-hsv-color-picker Forked and converted to TypeScript : 04/2021

TypeScript

Preview

View Live Demo

react-native-hsv-picker is a React Native component for selection of an HSV (hue, saturation, value) color value.

Highlighted Features:

  1. Real Rendering - no image involved / all colors are truly rendered
  2. Performance - empowered by native gradient lib
  3. Fully Controlled - no inner state involved
  4. Fully Supported - support both React Native & Expo projects

Install

$ npm install react-native-hsv-picker --save

Use with Expo Project

You are all set.

Use with React Native Project

react-native-hsv-picker is powered by expo-linear-gradient. If you're not using a Managed Expo project, you have to follow these instructions to properly install it.

Usage

a minimally-configured HSV color picker

import React from 'react';
import { StyleSheet, View } from 'react-native';
import HsvColorPicker from 'react-native-hsv-picker';

type ExampleProps = {}; 
type ExampleState = {hue: number, sat: number, val: number };
export default class Example extends React.Component<ExampleProps, ExampleState> {
  constructor(props) {
    super(props);
    this.state = {
      hue: 0,
      sat: 0,
      val: 1,
    };
    this.onSatValPickerChange = this.onSatValPickerChange.bind(this);
    this.onHuePickerChange = this.onHuePickerChange.bind(this);
  }

  onSatValPickerChange({ saturation, value }: { saturation: number, value: number }) {
    this.setState({
      sat: saturation,
      val: value,
    });
  }

  onHuePickerChange({ hue }: { hue: number }) {
    this.setState({
      hue,
    });
  }

  render() {
    const { hue, sat, val } = this.state;
    return (
      <View style={styles.container}>
        <HsvColorPicker
          huePickerHue={hue}
          onHuePickerDragMove={this.onHuePickerChange}
          onHuePickerPress={this.onHuePickerChange}
          satValPickerHue={hue}
          satValPickerSaturation={sat}
          satValPickerValue={val}
          onSatValPickerDragMove={this.onSatValPickerChange}
          onSatValPickerPress={this.onSatValPickerChange}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Props

Basic Props
PropTypeDefaultDescription
containerStyleStyleProp{}style for the outmost container
huePickerContainerStyleStyleProp{}style for the hue picker container
huePickerBorderRadiusnumber0border radius for the hue picker
huePickerHuenumber0hue value(h in hsv, ranged in [0, 360]) for the hue picker
huePickerBarWidthnumber12bar width for the hue picker
huePickerBarHeightnumber200bar height for the hue picker
huePickerSliderSizenumber24slider diameter for the hue picker
satValPickerContainerStyleStyleProp{}style for the saturation & value picker container
satValPickerBorderRadiusnumber0border radius for the saturation & value picker
satValPickerSizenumber200width / height for the saturation & value picker
satValPickerSliderSizenumber24slider diameter for the saturation & value picker
satValPickerHuenumber0hue value(h in hsv, ranged in [0, 360]) for the saturation & value picker
satValPickerSaturationnumber1saturation value(s in hsv, ranged in [0, 1]) for the saturation & value picker
satValPickerValuenumber1value(v in hsv, ranged in [0, 1]) for the saturation & value picker
Callback Props
PropCallback ParamsDescription
onHuePickerDragStart{
    hue: number,
    gestureState: gestureState
}
called when hue picker starts to drag
onHuePickerDragMove{
    hue: number,
    gestureState: gestureState
}
called when hue picker is dragging
onHuePickerDragEnd{
    hue: number,
    gestureState: gestureState
}
called when hue picker stops dragging
onHuePickerDragTerminate{
    hue: number,
    gestureState: gestureState
}
called when another component has become the responder
onHuePickerPress{
    hue: number,
    nativeEvent: nativeEvent
}
called when hue picker is pressed
onSatValPickerDragStart{
    saturation: number,
    value: number,
    gestureState: gestureState
}
called when saturation & value picker starts to drag
onSatValPickerDragMove{
    saturation: number,
    value: number,
    gestureState: gestureState
}
called when saturation & value picker is dragging
onSatValPickerDragEnd{
    saturation: number,
    value: number,
    gestureState: gestureState
}
called when saturation & value picker stops dragging
onSatValPickerDragTerminate{
    saturation: number,
    value: number,
    gestureState: gestureState
}
called when another component has become the responder
onSatValPickerPress{
    saturation: number,
    value: number,
    nativeEvent: nativeEvent
}
called when saturation & value picker is pressed

Methods

Instance Methods

Use ref to call instance methods

MethodParamsReturn TypeDescription
getCurrentColor-stringget current picked color in hex format

Dev

The demo folder contains a standalone Expo project, which can be used for dev purposes.

react-native - 0.63
react - 16.13

License

MIT

Keywords

FAQs

Package last updated on 14 Apr 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc