This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Jacek Stryk
Posted Feb 02 - Read on Facebook

Is there a way to use Utils.cycle() in reverse? Example: array choices = [a,b,c,d]. Pressing a keyboard key Utils.cycle() and returns choices[0], choices[1] etc.

When I press backspace I want Utils.cycle to return the PREVIOUS array value (choices[0]) not the NEXT one choices[2].

Any ideas how to make the Utils. cycle() bidirectional?

I guess I can do choices.reverse() and start cycling through that but looking for a better solution

7 Comments

Radek Kyselý

You can write your own reverse cycle() :)

Jacek Stryk

Radek Kyselý writing code is the last resort. Looking for lazy solutions :) hehe

Radek Kyselý

Here you can find definition of default Utils.cycle()
https://github.com/koenbok/Framer/blob/master/framer/Utils.coffee

Radek Kyselý

The reverse version would be this.
It works on its own: the problem is, you'd need to communicate "current" step between the two functions to make it work from the middle of an array :)

Jacek Stryk

ok, that's cool, let me start with that. Good pointer to https://github.com/.../blob/master/framer/Utils.coffee. I should spend some more time with the source code!

Radek Kyselý

Okay, finally got it :)
Use any positive value (or none at all) to move forward as it's in the default Utils.cycle() or use any negative value to move backwards :)

https://framer.cloud/XJiCH/

Jacek Stryk

Radek Kyselý you the man! Thanks for all the awesome examples!

Read the entire post on Facebook