osamaqarem/react-native-image-colors

expo compatibility

Closed this issue · 5 comments

Hi it says that this package is supported on expo projects but I am still getting this error

TypeError: null is not an object (evaluating '_module.RNImageColors.getColors')

I am using this version "react-native-image-colors": "^1.5.0" with the sample provided on the example page

hello, can you please write the steps taken to run the example project?
the issue template is an example
https://github.com/osamaqarem/react-native-image-colors/blob/master/.github/ISSUE_TEMPLATE/bug_report.md

I just tried running it on a brand new expo project.
I can add these steps to the README if they help you.


Expo Fresh Project Example

expo init example # assuming minimal (managed workflow)
cd example/
expo install expo-dev-client
yarn add react-native-image-colors

Its recommended to use EAS, but this guide will show local development with Android Studio and Xcode

expo run:ios 
# or
expo run:android

sorry I meant I was running the code from the example in my project. I am using the "blank" expo workflow with the expo go app and installed the package with expo install react-native-image-colors is it only compatible with certain workflows? it is also throwing the "Unexpected platform key" error when I run this code

useEffect(() => {

       const color = ImageColors.getColors(uriPIC, {
           fallback: '#000',
       })
           .then(res => res.json())
           .then(resColor => { console.log("COLORSUCESS"); return resColor })
           .catch((err) => { console.log(err, "COLORERROR"); return err; })

       console.log(color)

       switch (color.platform) {
           case 'android':
               // android result properties
               const vibrantColor = color.vibrant
               break
           case 'web':
               // web result properties
               const lightVibrantColor = color.lightVibrant
               break
           case 'ios':
               // iOS result properties
               const primaryColor = color.primary
               console.log(primaryColor)
               break
           default:
               throw new Error('Unexpected platform key')
       }
   }, [])

expo-dev-client must be installed on your project so you can use this library. it should work with any workflow

https://docs.expo.dev/development/getting-started/#installing--expo-dev-client--in-your-project

expo-dev-client is designed to support any workflow, release process, or set of dependencies in the Expo / React Native ecosystem. Whatever the needs of your project, either now or in the future, you'll be able to create development builds for it and get the productivity and quality of life improvements of JavaScript-driven development.

then you can link react-native-image-colors as a native module by running

expo run:ios 
# or
expo run:android

this won't change your workflow, its just a new feature from expo to allow using any non-expo native module.

ok its working now thank you