@sergeymell/nativescript-color-wheel
Advanced tools
Comparing version
@@ -21,61 +21,60 @@ import * as common from './common'; | ||
} | ||
// Interfaces decorator with implemented interfaces on this class | ||
let ClickListener = class ClickListener extends java.lang.Object { | ||
constructor() { | ||
super(); | ||
// Required by Android runtime when native class is extended through TypeScript. | ||
return global.__native(this); | ||
} | ||
onTouch(view, event) { | ||
// Handle only tap end | ||
if (event.getAction() !== android.view.KeyEvent.ACTION_UP) { | ||
return true; | ||
} | ||
/** Get the rendered bitmap */ | ||
const imgDrawable = view.getDrawable(); | ||
// @ts-ignore | ||
const bitmap = imgDrawable.getBitmap(); | ||
/** Define the coordinates of the tap */ | ||
const eventXY = Array.create('float', 2); | ||
eventXY[0] = event.getX(); | ||
eventXY[1] = event.getY(); | ||
const invertMatrix = new android.graphics.Matrix(); | ||
view.getImageMatrix().invert(invertMatrix); | ||
invertMatrix.mapPoints(eventXY); | ||
let x = eventXY[0]; | ||
let y = eventXY[1]; | ||
// Limit x, y range within bitmap | ||
if (x < 0) { | ||
x = 0; | ||
} | ||
else if (x > bitmap.getWidth() - 1) { | ||
x = bitmap.getWidth() - 1; | ||
} | ||
if (y < 0) { | ||
y = 0; | ||
} | ||
else if (y > bitmap.getHeight() - 1) { | ||
y = bitmap.getHeight() - 1; | ||
} | ||
/** Get color at the point of tap */ | ||
const touchedRGB = bitmap.getPixel(x, y); | ||
const owner = view.owner; | ||
if (touchedRGB && owner) { | ||
owner.notify({ | ||
eventName: 'colorSelect', | ||
object: Object.assign({}, owner, { | ||
isFirstChange: false, | ||
color: new Color(touchedRGB), | ||
colorPosition: { x, y } | ||
}) | ||
}); | ||
} | ||
var ClickListener = /** @class */ (function (_super) { | ||
__extends(ClickListener, _super); | ||
function ClickListener() { | ||
var _this = _super.call(this) || this; | ||
// Required by Android runtime when native class is extended through TypeScript. | ||
return global.__native(_this); | ||
} | ||
ClickListener.prototype.onTouch = function (view, event) { | ||
// Handle only tap end | ||
if (event.getAction() !== android.view.KeyEvent.ACTION_UP) { | ||
return true; | ||
} | ||
/** Get the rendered bitmap */ | ||
var imgDrawable = view.getDrawable(); | ||
// @ts-ignore | ||
var bitmap = imgDrawable.getBitmap(); | ||
/** Define the coordinates of the tap */ | ||
var eventXY = Array.create('float', 2); | ||
eventXY[0] = event.getX(); | ||
eventXY[1] = event.getY(); | ||
var invertMatrix = new android.graphics.Matrix(); | ||
view.getImageMatrix().invert(invertMatrix); | ||
invertMatrix.mapPoints(eventXY); | ||
var x = eventXY[0]; | ||
var y = eventXY[1]; | ||
// Limit x, y range within bitmap | ||
if (x < 0) { | ||
x = 0; | ||
} | ||
else if (x > bitmap.getWidth() - 1) { | ||
x = bitmap.getWidth() - 1; | ||
} | ||
if (y < 0) { | ||
y = 0; | ||
} | ||
else if (y > bitmap.getHeight() - 1) { | ||
y = bitmap.getHeight() - 1; | ||
} | ||
/** Get color at the point of tap */ | ||
var touchedRGB = bitmap.getPixel(x, y); | ||
var owner = view.owner; | ||
if (touchedRGB && owner) { | ||
owner.notify({ | ||
eventName: 'colorSelect', | ||
object: Object.assign({}, owner, { | ||
isFirstChange: false, | ||
color: new Color(touchedRGB), | ||
colorPosition: { x: x, y: y } | ||
}) | ||
}); | ||
} | ||
return true; | ||
}; | ||
ClickListener = __decorate([ | ||
NativeClass, | ||
Interfaces([android.view.View.OnTouchListener]), | ||
__metadata("design:paramtypes", []) | ||
Interfaces([android.view.View.OnTouchListener]) | ||
], ClickListener); | ||
return ClickListener; | ||
}(java.lang.Object)); | ||
touchListener = new ClickListener(); | ||
@@ -82,0 +81,0 @@ } |
import * as common from './common'; | ||
import { Color } from '@nativescript/core'; | ||
global.moduleMerge(common, exports); | ||
/** | ||
* Tap handler implementation | ||
* [Documentation]{@link https://stackoverflow.com/questions/12770181/how-to-get-the-pixel-color-on-touch} | ||
*/ | ||
let TapHandler = class TapHandler extends NSObject { | ||
tap(args) { | ||
var TapHandler = /** @class */ (function (_super) { | ||
__extends(TapHandler, _super); | ||
function TapHandler() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
TapHandler.prototype.tap = function (args) { | ||
/** Define tap position */ | ||
const position = args.locationInView(args.view); | ||
const x = position.x; | ||
const y = position.y; | ||
var position = args.locationInView(args.view); | ||
var x = position.x; | ||
var y = position.y; | ||
/** Draw 1 pixel canvas in place */ | ||
let pixel = malloc(4 * interop.sizeof(interop.types.uint8)); | ||
let colorSpace = CGColorSpaceCreateDeviceRGB(); | ||
let context = CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorSpace, 2 /* kCGImageAlphaPremultipliedFirst */); | ||
var pixel = malloc(4 * interop.sizeof(interop.types.uint8)); | ||
var colorSpace = CGColorSpaceCreateDeviceRGB(); | ||
var context = CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorSpace, CGImageAlphaInfo.kCGImageAlphaPremultipliedFirst); | ||
CGContextTranslateCTM(context, -x, -y); | ||
args.view.layer.renderInContext(context); | ||
/** Emit selected color */ | ||
const reference = new interop.Reference(interop.types.uint8, pixel); | ||
const owner = args.view.owner; | ||
var reference = new interop.Reference(interop.types.uint8, pixel); | ||
var owner = args.view.owner; | ||
if (reference.value && owner) { | ||
@@ -29,3 +29,3 @@ owner.notify({ | ||
color: new Color(reference[0], reference[1], reference[2], reference[3]), | ||
colorPosition: { x, y } | ||
colorPosition: { x: x, y: y } | ||
}) | ||
@@ -38,10 +38,8 @@ }); | ||
free(pixel); | ||
} | ||
}; | ||
TapHandler.ObjCExposedMethods = { | ||
'tap': { returns: interop.types.void, params: [interop.types.id, interop.types.id] } | ||
}; | ||
TapHandler = __decorate([ | ||
NativeClass | ||
], TapHandler); | ||
}; | ||
TapHandler.ObjCExposedMethods = { | ||
'tap': { returns: interop.types.void, params: [interop.types.id, interop.types.id] } | ||
}; | ||
return TapHandler; | ||
}(NSObject)); | ||
const handler = new TapHandler(); | ||
@@ -48,0 +46,0 @@ export class ColorWheel extends common.ColorWheelCommon { |
{ | ||
"name": "@sergeymell/nativescript-color-wheel", | ||
"version": "1.0.11", | ||
"description": "Simple and flexible color picker for NativeScript Core and Angular appliactions", | ||
"version": "1.0.12", | ||
"description": "Simple and flexible color picker for NativeScript Core and Angular applications", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "typings": "index.d.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
55405
-5.67%567
-0.53%