-
Notifications
You must be signed in to change notification settings - Fork 127
React Native support. #48
Comments
Hi, thanks for the issue. Unfortunately, I'm not sure I understand the problem (possibly because I'm not very familiar with React Native). Could you clarify what you're doing, and what's going wrong? |
I think that snoowrap requires some node dependencies and because React Native is not running in a node environment, those dependencies do not exist. |
Could you be more specific about how you're installing/using snoowrap, and what errors are appearing? A setup where I can reproduce the issue would be ideal. |
So I am using a basic React Native project. I followed the official getting started instructions (mac+android). Then I installed: Then when the App restarts I get: |
Does this issue still happen if you install Between 1.9.0 and 1.10.0, I made a change that causes the |
I have tried So in the end, this is not an issue if there is and will not be support for react native. |
Hmm, I see. In theory, it would be nice if snoowrap could support react native, and I wouldn't mind doing it if it wouldn't pose a large maintenance burden. At the moment, snoowrap uses the following modules from Node's standard library:
So you could probably solve the issues if you installed shims for each of these with something like rn-nodeify, but I acknowledge that this is not ideal. |
I will give rn-nodeify a try later today. Fingers crossed it will work. |
Friendly ping; were you able to resolve this issue? |
I'm not 100% sure if's the same problem, but I got the following error when using Webpack:
Which is caused when I try to Not sure what a good solution would be. For Webpack to realize The solution I'm using is to use the packaged
This workaround is totally fine for me. Since Webpack is a popular tool, perhaps this could be documented where you mention browserify in the README? I'm still trying to figure out why, but I don't get the snoowrap object when I do (Looks like it's the punycode module?) Edit: Thanks for making snoowrap! It's an amazing piece of software. ❤️ |
Thanks for the report. I think the issue is that snoowrap uses I suppose I could trick Webpack by doing something like In response to your other question, I'm not sure why |
I don't think the Do you ever do |
Yes, I do that here. I've been looking at this thread. Apparently it might be possible to resolve this by excluding What happens if you modify snoowrap's |
I could definitely have Webpack ignore I don't know how to use a local copy of snoowrap in my project. |
To clarify, I meant to ask what happens if you monkeypatch |
Yes, that does the trick! I'll try re-writing my code without the |
Great! Let me know if you run into any other Webpack-related issues, otherwise I'll publish a new version of the package with that line added sometime in the next few days. |
After some trial and error I actually was able to get Snoowrap working with react native using rn-nodeify. Initialized project by the steps below and everything seems to be working as intended.
|
Hello, Has there been any progress towards react native support lately? Even with the suggestion from @maciebey I still get the error from Timing.createTimer from this image: https://cloud.githubusercontent.com/assets/4718153/19494137/91ada186-9575-11e6-9c4f-cb73d50e5207.png This occurs only on android and not ios |
I don't use React Native, so working on this issue hasn't been a priority for me. However, if you figure out what needs to be changed in the package and/or make a PR with the changes, I'd be happy to accept it. Right now I'm not familiar with how react native works or its available APIs, and I don't have a development environment set up for react native, so it's difficult for me to debug this issue. |
Same issue only on Android. |
The way I (somewhat naively) see it, each of the native Node modules can either be replaced with a npm package or bypassed:
I'll try and set up a RN environment and have a crack at these, but I make no promises. If I get hit by a bus though, this should be a reasonable starting point. EDIT: |
Hi, I was wondering if there was any progress on this issue? If not, dose anybody know about alternatives to snoowrap? |
@danhab99 I can't speak for the maintainers or other devs but personally I haven't had an opportunity to work on it. Reddit's API is mostly just standard REST and OAuth, so you could in theory use any library that supports those (or, heck, just |
I think I have a solution. I talked with some people on discord and we figured it out, @stelioskiayias screenshot where React was complaining about Snoowrap trying to use the Whenever Snoowrap would try to use a node package that wasn't available, I just installed it. Try running: npm i -S fs events path stream url util |
Issue #243 seems to imply that my solution worked. Unless we want to continue to discuss this issue, I recommend closing. |
Sounds good to me. Feel free to reply again and we can re-open the issue. Solution: Add base 64 globals in your entry file: import {decode, encode} from 'base-64'
if (!global.btoa) {
global.btoa = encode;
}
if (!global.atob) {
global.atob = decode;
} After snoowrap initialization change const snoowrap = new snoowrap({/**...*/});
snoowrap._nextRequestTimestamp = -1; |
I ran into a minor issue while using fromApplicationOnlyAuth: xhr makes a call with a large timeout (2^32), which triggers a warning on Android. Subclassing snoowrap to pass in the timeout fixes things. Call with class NativeSnoowrap extends snoowrap {
constructor(options) {
super(options);
this._nextRequestTimestamp = -1;
}
credentialedClientRequest(options = {}) {
return super.credentialedClientRequest({timeout: 60e3, ...options})
}
} |
I am trying to use snoowrap in a React Native environment, but because its not running in a node environment I get this issue .
I would have thought that this was something that was fix as part of #33 ?
Is there a quick workaround for this?
The text was updated successfully, but these errors were encountered: