Git Product home page Git Product logo

Comments (2)

achuvm avatar achuvm commented on July 29, 2024

Hi @Zirconiumirish,

Yes, it is possible and there are a few ways to do this, some more "proper" than others. I do want to point out that our platform is built on top of React-Native and so, you can use most React-Native modules, components, etc in conjunction with your Viro application (you just can't put React-Native views in React-Viro components).

Essentially, you want to store state and the recommended way of doing so in React-Native is using a state-tracking framework such as Redux or Relay. Those are fully-fledged solutions that are used in many deployed React-Native apps, but do require some setup and learning on your behalf.

However, because React-Native is built on Javascript and Node, we can also transfer information through the use of modules and/or global variables.

In the below gist, I've added a TestModuleVar.js file with a moduleVar variable that will contain some value (in this case, this string "foobar"). Now, in my SwapImageTest scene, I have imported my TestModuleVar and made it print* out the value of that moduleVar variable when the scene renders. When I tap on the top image, it'll change that moduleVar to contain the value "barfoo" and print it out.

Code here:
https://gist.github.com/achuvm/e35ab38d8f7a5af8cce71730e1425f37

So for you to do what you want, you could create 3 variables in a separate module, and as your user answers questions, update those values in the first scene. Then when you are ready for the second scene, simply import that module and access the values. This would work for now, but if you have the time, I'd take a look at a more "proper" state-management module/system.

I've tested this and it looks like it does work between scenes (but that's not shown in the gist). If it doesn't work, apparently you can also use the global variable that Node.js provides by simply setting values like this global.globalVar = true from anywhere in your program and accessing it in the same way, but I've not tested that.

Let me know if that works.

Thanks,

Andy

*Note: I believe on iOS you'll need Xcode to see the console.log output even from JS, and they'll look something like this:
2017-08-02 01:11:06.303 [info][tid:com.facebook.react.JavaScript] TestModuleVar.moduleVar is: foobar
On Android, you can use adb logcat or Android Studio/Eclipse, etc. If you know of a way of seeing the Javascript logs without those tools, let us know!

from viro.

achuvm avatar achuvm commented on July 29, 2024

Closing this issue due to lack of activity.

Feel free to reopen this issue, create another issue or contact us at [email protected].

Thanks!

from viro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.