@sergeymell/nativescript-color-wheel
Advanced tools
Comparing version
@@ -29,13 +29,14 @@ import * as common from './common'; | ||
color: new Color(reference[0], reference[1], reference[2], reference[3]), | ||
colorPosition: { x: x, y: y } | ||
}) | ||
colorPosition: { x: x, y: y }, | ||
}), | ||
}); | ||
} | ||
/** Release allocated memory */ | ||
CGColorSpaceRelease(colorSpace); | ||
CGContextRelease(context); | ||
// TODO: For some reason such memory release crashes the app. Let's believe in JS Garbage collector until I find correct solution | ||
// releaseNativeObject(colorSpace); | ||
// releaseNativeObject(context); | ||
free(pixel); | ||
}; | ||
TapHandler.ObjCExposedMethods = { | ||
'tap': { returns: interop.types.void, params: [interop.types.id, interop.types.id] } | ||
tap: { returns: interop.types.void, params: [interop.types.id, interop.types.id] }, | ||
}; | ||
@@ -51,3 +52,3 @@ return TapHandler; | ||
target: handler, | ||
action: 'tap' | ||
action: 'tap', | ||
}); | ||
@@ -60,12 +61,15 @@ imageView.addGestureRecognizer(tap); | ||
*/ | ||
const colorSpace = CGColorSpaceCreateDeviceRGB(); | ||
const filter = CIFilter.filterWithNameWithInputParameters('CIHueSaturationValueGradient', { | ||
//@ts-ignore | ||
'inputColorSpace': CGColorSpaceCreateDeviceRGB(), | ||
'inputDither': 0, | ||
'inputRadius': this.radius, | ||
'inputSoftness': 0, | ||
'inputValue': 1 | ||
inputColorSpace: colorSpace, | ||
inputDither: 0, | ||
inputRadius: this.radius, | ||
inputSoftness: 0, | ||
inputValue: 1, | ||
}); | ||
const image = new UIImage(filter.outputImage); | ||
const image = UIImage.imageWithCIImage(filter.outputImage); | ||
imageView.image = image; | ||
// TODO: For some reason such memory release crashes the app. Let's believe in JS Garbage collector until I find correct solution | ||
// releaseNativeObject(colorSpace); | ||
return imageView; | ||
@@ -124,5 +128,3 @@ } | ||
const blue = reference[blueOffset(x, y, width)]; | ||
const distance = Math.abs(red - color.r) + | ||
Math.abs(green - color.g) + | ||
Math.abs(blue - color.b); | ||
const distance = Math.abs(red - color.r) + Math.abs(green - color.g) + Math.abs(blue - color.b); | ||
if (distance < metrics) { | ||
@@ -136,4 +138,5 @@ metrics = distance; | ||
/** Release allocated memory */ | ||
CGColorSpaceRelease(colorSpace); | ||
CGContextRelease(context); | ||
// TODO: For some reason such memory release crashes the app. Let's believe in JS Garbage collector until I find correct solution | ||
// releaseNativeObject(colorSpace); | ||
// releaseNativeObject(context); | ||
free(bitmapData); | ||
@@ -146,4 +149,4 @@ if (resX > -1 && resY > -1) { | ||
color, | ||
colorPosition: { x: resX, y: resY } | ||
}) | ||
colorPosition: { x: resX, y: resY }, | ||
}), | ||
}); | ||
@@ -150,0 +153,0 @@ } |
{ | ||
"name": "@sergeymell/nativescript-color-wheel", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "Simple and flexible color picker for NativeScript Core and Angular applications", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# NativeScript Color Wheel | ||
NativeScript 6 version of this plugin is available | ||
at https://github.com/SergeyMell/nativescript-n6-color-wheel | ||
## Description | ||
This plugin is actually a color picker plugin which can be used | ||
as a simple component wherever you need it. It allows you to | ||
This plugin is actually a color picker plugin which can be used | ||
as a simple component wherever you need it. It allows you to | ||
- pick a color by clicking appropriate position on the color wheel | ||
@@ -11,10 +16,11 @@ - render whatever UI as a picker icon customizing it on your own needs | ||
Plugin works simultaneously for both iOS and Android platforms and | ||
Plugin works simultaneously for both iOS and Android platforms and | ||
is not based on any additional libraries, CocoaPods etc | ||
### Examples | ||
|Color wheel with custom selection picker|Color picker in a modal dialog| | ||
|---|---| | ||
|![][1]|![][2]| | ||
| Color wheel with custom selection picker | Color picker in a modal dialog | | ||
| ---------------------------------------- | ------------------------------ | | ||
| ![][1] | ![][2] | | ||
[1]: https://github.com/SergeyMell/nativescript-plugins/blob/assets/android-with-picker.gif?raw=true | ||
@@ -24,7 +30,11 @@ [2]: https://github.com/SergeyMell/nativescript-plugins/blob/assets/ios-modal.gif?raw=true | ||
## Installation | ||
```javascript | ||
ns plugin add @sergeymell/nativescript-color-wheel | ||
``` | ||
## Usage | ||
### In NativeScript Core applications: | ||
```xml | ||
@@ -34,14 +44,17 @@ <clw:ColorWheel width="200" height="200" color="#FFB35E" | ||
``` | ||
### In NativeScript Angular applications: | ||
1. Add `NativeScriptColorWheelModule` from `@sergeymell/nativescript-color-wheel/angular` to the `imports` section of your Angular module | ||
2. Use the `ColorWheel` component where you need it | ||
```html | ||
<ColorWheel width="200" height="200" margin="20" | ||
(colorSelect)="onColorSelected($event)"></ColorWheel> | ||
<ColorWheel width="200" height="200" margin="20" (colorSelect)="onColorSelected($event)"></ColorWheel> | ||
``` | ||
### TODOs: | ||
- optimize the algorithm of initial color location determination | ||
- make color brightness configurable (at least for Android) | ||
- add support of other color selection area forms (i.e. square) | ||
- add support of other color selection area forms (i.e. square) | ||
@@ -48,0 +61,0 @@ ## License |
Sorry, the diff of this file is not supported yet
56153
1.35%570
0.53%61
27.08%