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

What is Framer? Join the Community
Return to index
Joshua Tucker
Posted Sep 15 - Read on Facebook

Hello all! Anyone have a clever way of stopping a switch event from firing?

I have a layer that switches between states on a DragStart and DragEnd. The switch fires with no delay on DragStart and has a 3 second delay on DragEnd. If I drag again before the layer hides in 3 seconds, it essentially stacks and then it just flickers between the two states until it clears the "queue." I was digging in source and not sure if there was a better way other than hacking around with _previousStates and possibly just changing its _currentState to a previousState to avoid constant firing. Not sure if this would work however.

Also, on the same vein – if you set a delay on a switch, Events.StateDidSwitch fires before technically the animation begins, let alone ends. Intentional?

7 Comments

Jordan Robert Dobson

Is this a birthday request per chance?

Jordan Robert Dobson

Are you using willSwitch at all?

How does the 3 second delay get placed? Would calling an invertal work? Then cancel the interval it if another DragStart event fires.

Joshua Tucker

Jordan Robert Dobson Can it be a birthday request? :).

WillSwitch as in Events.StateWillSwitch? I don't think it would help in this context.

I'm passing in the delay in animationOptions on the switch call itself.

layer.states.switch "state", (delay: 3, curve: "spring(250, 45, 0)".

If I listen to this layer's state changes, "state" immediately emits StateDidSwitch even though animation hasn't even started, or ended.

Jordan Robert Dobson

Can you call the delay another way? Inside a Utils delay or interval?

Joshua Tucker

The other way would be to set its animationOptions before calling, but that wouldn't help. I could use a delay, then I could clear it if needed. I was trying to avoid that because in past experiences, delay/interval can at times stack regardless of whether I reference it or not and clear it appropriately.

George Kedenburg III
Joshua Tucker

George Kedenburg III That works too! Thanks for sharing my friend.

Read the entire post on Facebook