tisho / Switch.framerfx

Utility component for Framer X that lets you switch between different states of an element
31 stars 4 forks source link

switch triggering re-rending of unrelated frame #10

Open bise1157 opened 4 years ago

bise1157 commented 4 years ago

Hi,

I ran into a problem with switch somehow changing the state of a frame that is not linked to switch in any way. Not sure if this is a bug or if I just do not understand the underlying functionality here.

Basically I do have a simple override that is toggling the x position of a frame via DataObject whenever a button is tapped. Initially the frame is shown and gets moved off the screen after tapping the button. There is also a switch component on the screen. If this component gets updated (next state action) also the overlay frame gets re-rendered and is moved back into the screen, even though the DataObject does not change.

A bit difficult to describe, so here is a framerx file, showing what is happening.

Thanks! Ben

switch_bug_test_1.framerx.zip

tisho commented 3 years ago

Thanks for reporting this @bise1157 and sorry for getting back to you so late. Switch uses framer motion's AnimatePresence for most transition types internally, and it seems like this is what causes this issue. I brought it up with the team and it turns out that within later versions of Framer that support Magic Motion, using AnimatePresence will trigger an additional call to a forceUpdate function on a context that wraps the entire frame, and this in turn causes a reset of some of the transforms of an element. This might be fixed by the upcoming version of framer-motion, so I'll keep an eye out. In the meantime, you can probably still use the left property, instead of x to shift an element's position. It doesn't seem to be affected by the reset in my testing.

Hope this helps.