-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request a version usable in react-native #29
Comments
Hmmm. I guess I'm being naive about expecting node modules to work in react-native. I've found that this particular problem arises because the react-native packager honors the |
document is not defined
@chetstone Have you tried rn-nodeify? Core node modules won't work by default in a RN app because it doesn't actually run on node (V8), but JSC. It's not bulletproof, but runs reasonably well in my experience. That said, I am having trouble with node-vibrant. Can you try it too and see where you get? I don't have a problem with Edit: This might be relevant if it's pngjs related: pngjs/pngjs#64 (For reference)
|
Hmm. Previous PL #21 seems to indicate node-vibrant once worked with React Native. // var Vibrant = require('node-vibrant')
// var NodeImage = require('node-vibrant/lib/image/node')
// var v = new Vibrant(uri, {Image: NodeImage}) Edit: never mind. Just saw followed comments. If I will setup React Native and do some testing once I got the time. |
@stovmascript thanks for the heads-up about rn-nodeify. I also found React-Nativify which seems like a promising approach but I haven't had time to try it. I'm on another project at the moment but will look into this next week. |
@chetstone Cool, in turn, thanks for the heads-up about ReactNativity. Just tried it out and I like it better. There are tradeoffs though. With rn-nodeify, pretty much everything is taken care of for you. You only have to remember to run the postinstall script after installing new packages (i.e. it will run after The ReactNativity solution is IMO more elegant in that you can supply your own bundle transformer function to the RN Packager (super cool) and you can use babel-plugin-rewrite-require to change the With both methods, I've arrived at the same point thought... After importing like this: import Vibrant from 'node-vibrant/lib'; I'm getting this error:
originating at: node_modules/inherits/inherits_browser.js:5 (browser version of the inherits module). If you update this function with what node's currently using, it will trigger the new custom error:
It seems to be happening because the super constructor that's supposed to be passed to this function is not a constructor, but actually an instantiated class, so when you change the superCtor to: Following the stacktrace, it leads to the request package used by jimp, but whether it's a an issue with request or jimp not using request correctly, I don't know. It most likely works fine in node, but only breaks when bundled for the browser or only for react-native even. |
Thanks so much for the thorough report. So do your modifications to inherits suffice to get node-vibrant working with RN or are you still stuck? On Nov 6, 2016, 07:24 -0700, Martin Šťovíček [email protected], wrote:
|
@stovmascript Finally got some time to try with First, I couldn't get the transformer to work. I finally found that the ability to specify Then, the packager for some reason couldn't find the Commenting out the require of Finally, after reading this article, I'm ready to give up on this approach. I haven't tried with It seems a lot more straightforward to build a native wrapper for android around the actual pallete library. I don't know java, but maybe it's time to learn. And it won't work on iOS, but I've been using the colorgrabber component in my iOS app with good success. Not as full-featured as palette, but good enough for my purposes. |
I've just published react-native-palette which wraps the excellent Android Palette class as a native module. The component also supports similar functionality for iOS, but with some issues. It would be nice to also have a javascript-only solution such as node-vibrant which would work on iOS since native support there is somewhat lacking. |
Sorry about the long delay. Real life happened. From A possible workaround: // Prevent jimp from requiring `fs`
process.env.ENVIRONMENT = 'BROWSER'
// Require node.js version vibrant explicitly
const Vibrant = require('node-vibrant/lib/index')
// Load image file into a Buffer in some react-native compatible way
let buf = react_native_read_file('path/to/image')
// Pass buffer to node-vibrant
Vibrant.from(buf).getPalette() Could anyone check whether this approach will work? Thanks. |
A reminder that GitHub has 👍 reactions to issues to show support without clogging the thread |
Your latest version "3.2.0-alpha" crashes in React Native with error "Can't find variable: self" |
i'm sorry i dont really get it , is the node-vibrant lib working with RN or not? |
@Psiiirus it should be working in the non-alpha build |
Im getting |
Did anyone managed to get it working on react native? |
I guess I made it work for jpg, here's my ref implementation if anyone's interested https://gist.github.com/Grohden/0f813f150792af1464776c0a9c1227b1 I'm gonna see if I can exactract and use good colors for my personal project, if that works I'll see if I find a lib that can extract info from png & jpg (maybe there's a port of jimp for rn? maybe we could create one?) and maybe create a 'react-native-vibrant' or add it to this lib edit: right, its not resulting in the same colors as web.. so its not really working I guess |
I'm trying to use this in my react-native app, and the component seems by default to use a browser-based image class, and I can't figure out how to get it to use the node image class as documented in the README.
I have
And when I try to set the Image option with
I get
Cannot read property 'Node' of undefined
I think I'm just not importing Image.Node properly but I'm not sure how to do it.
The text was updated successfully, but these errors were encountered: