react-native-pixel-color
react-native-pixel-color copied to clipboard
Unhandled promise rejection: TypeError: null is not an object (evaluating '_reactNative.NativeModules.RNPixelColor.getHex')
The Project / Implementation
Attempting to implement color picking functionality in an expo app (created through expo init
) using TypeScript. A picture is taken with expo-camera
and has its uri passed into react-native-pixel-color
as a parameter, along with an object containing the x and y coordinates.
Installation
The dependency (react-native-pixel-color
) was installed using yarn.
The Issue
Calling the getHex()
method with proper parameters results in the following error message:
[Unhandled promise rejection: TypeError: null is not an object (evaluating '_reactNative.NativeModules.RNPixelColor.getHex')]
- node_modules\react-native-pixel-color\index.js:5:63 in Promise$argument_0
- node_modules\react-native\node_modules\promise\setimmediate\core.js:45:6 in tryCallTwo
- node_modules\react-native\node_modules\promise\setimmediate\core.js:200:22 in doResolve
- node_modules\react-native\node_modules\promise\setimmediate\core.js:66:11 in Promise
- node_modules\react-native-pixel-color\index.js:5:22 in getHex
* http://192.168.0.12:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:128332:47 in <unknown>
- node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
- node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates
Code Snippet
<View
style={styles.container}
onTouchStart={({ nativeEvent }) => {
camRef.current.takePictureAsync().then(
data => {
const picData = data;
console.log(picData);
PixelColor.getHex(picData.uri, coordObj).then((color: string) => {
console.log(color);
});
}
);
console.log('-EVENT: touch detected');
}}
>
I'm not entirely sure whether this is a compatibility issue with expo or something with the module itself, but it's certainly worth looking into.
Same issue, any updates?
From what I can see in the code... there is absolutely no Android code to extract hex value from an image. In the index.js
it is not even checked if the platform is iOS or Android, it defaults to iOS RNPixelColor
library. There is an Android library included for image resizing, it has nothing to do with what this project aims to solve and is not used anywhere.
Use this instead: https://github.com/dudyn5ky1/react-native-get-pixel-color
tl;dr this misleading library is hot garbage for Android
I am also getting [TypeError: Cannot read property 'getHex' of null] on Android. Works in on iOS.