Skip to content
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

Conditions "if" #29

Closed
ghost opened this issue Aug 2, 2017 · 2 comments
Closed

Conditions "if" #29

ghost opened this issue Aug 2, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Aug 2, 2017

Hello ViroTeam,

Do you think that we can setup conditions with your plateform like :

Imagine there are 3 questions with 3 differents answers for each question only one answer is valid per question (Like True/False)

Building something like

IF specific buttons are clicked during the 3 questions THEN we can show the results on another
scene

Do you think it might work, I'm embarrassed to ask you again if you are able to build an exemple for this. If you can't I can understand

Thanks in advance

Michael

@achuvm
Copy link
Collaborator

achuvm commented Aug 2, 2017

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!

@achuvm
Copy link
Collaborator

achuvm commented Sep 22, 2017

Closing this issue due to lack of activity.

Feel free to reopen this issue, create another issue or contact us at support@viromedia.com.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant