GithubHelp home page GithubHelp logo

ilp64 / react-native-color-picker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from instea/react-native-color-picker

0.0 1.0 0.0 651 KB

Color picker component for IOS/Android

License: Apache License 2.0

JavaScript 100.00%

react-native-color-picker's Introduction

react-native-color-picker

React Native implementation of color picker for both Android and iOS.

android preview iphone preview

  • works both in controlled and uncontrolled way
  • old color can be displayed for visual comparison
  • holo and triangle color pickers

Getting started

Install the color picker

npm install react-native-color-picker --save

And use it in your application

import { ColorPicker } from 'react-native-color-picker'

const Picker = () => (
  <ColorPicker
    onColorSelected={color => alert(`Color selected: ${color}`)}
    style={{flex: 1}}
  />
)

Color picker will use space you provide. Therefore it is necessary to provide styles that will determine picker's size.

API

Color picker type

We provide two types of color picker - holo (default) and triangle color picker. Both has the same API so that they are interchangable. Just import it and use it the same way:

import { ColorPicker, TriangleColorPicker } from 'react-native-color-picker'
ColorPicker TriangleColorPicker

Props

Color pickers accepts properties below. Each property which define color is represented as a color string.

Property Type Note
color `String HSV`
defaultColor String Defines initial selected color in uncontrolled component.
oldColor String Old color to be used for visual comparision. If it is not defined, whole circle is representing selected color.
style Style Styles passed to color picker container
onColorSelected Function Callback with color (HEX string) as argument called when user confirms color selection.
onColorChange Function Callback called each time when color is changed. Used in controlled component. Argument is color in HSV representation (see below)
onOldColorSelected Function Callback with color (HEX string) as argument called when user selects old color.

When using color picker as a controlled component you should always use HSV color representation to avoid conversion from/to HEX or RGB. HSV color representation is an object literal with properties:

{
  h: number, // <0, 360>
  s: number, // <0, 1>
  v: number, // <0, 1>
}

Helper functions

To utilize HSV -> HEX/RGB conversion we provide helper functions:

import { toHsv, fromHsv } from 'react-native-color-picker'

toHsv('blue') // { h: 24, s: 1, v: 1 }

fromHsv({ h: 200, s: 0.4, v:0.4 }) // #3d5866

Examples

Limitations

  • Does not work well within ScrollView due to touch event interference.

Thanks

Our implementation was inspired by Android Holo ColorPicker

react-native-color-picker's People

Contributors

ilp64 avatar madox2 avatar sodik82 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.