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

Method to hold an animation state for a specified time in compact form #480

Closed
samhattangady opened this issue Mar 6, 2023 · 4 comments · Fixed by #651
Closed

Method to hold an animation state for a specified time in compact form #480

samhattangady opened this issue Mar 6, 2023 · 4 comments · Fixed by #651
Assignees
Labels
a-core Relates to the core package b-enhancement New feature or request c-accepted The issue is ready to be worked on

Comments

@samhattangady
Copy link
Contributor

Description
There are cases where we might want to do some animation, hold it for a certain amount of time, and then move to another.

I have found that it is quite a common usecase in my workflow.

For example, fade some text in, hold it for 2 seconds, and then fade it out again.

Right now, we have to do it like this

yield* headerText().opacity(1, 1, easeInOutCubic);
yield* waitFor(2);
yield* headerText().opacity(0, 1, easeInOutCubic);

// or we can do it like this
// note how the .to method is the same value, and so it keeps the text opacity at 1 for an additional second
yield* headerText().opacity(1, 1, easeInOutCubic).to(1, 2).to(0, 1, easeInOutCubic);

This is very verbose, and it means that if you want to change max opacity from 1 to 0.8, then you would have to make
the change in two places.

Proposed solution
I think one solutions that would be nice is to have a hold method.

yield* headerText().opacity(1, 1, easeInOutCubic).hold(2).to(0, 1, easeInOutCubic);

Additional context
I would like to make the contribution myself, but right now, I don't know where the change should be,
My best guess is in signals/types, in the SignalGenerator.

I would appreciate if you could point me in the correct direction.

@aarthificial
Copy link
Contributor

This is actually a regression because we used to have something like this in v1 during early access.

I think it should be called wait instead of hold to be consistent with functions like waitFor and waitUntil

SignalGenerator only defines the type, the actual implementation of to can be found in SignalContext:

task.to = this.makeAnimate(timingFunction, interpolationFunction, task);
return task;

@aarthificial aarthificial removed their assignment Mar 7, 2023
@aarthificial aarthificial added b-enhancement New feature or request c-accepted The issue is ready to be worked on a-core Relates to the core package labels Mar 7, 2023
@samhattangady
Copy link
Contributor Author

Is there a reason that it was removed? Or any other way that you prefer it to be done?

@aarthificial
Copy link
Contributor

It wasn't removed, per se. v1 had no signals, it used a slightly different api for chained animations:

yield* node.x(ANIMATE)
  .key(200, 2) // transition to 200
  .diff(-100, 2) // transition to 200 - 100
  .do(() => {}) // call a callback
  .waitFor(2) // wait for 2 seconds
  .run(3) // run the chain 3 times.

After switching to signals, to (key) was the only one I had the time to reimplement.

I think implementing it the same way as to is the best solution here.

@samhattangady
Copy link
Contributor Author

Ah got it.
I will try to implement it, and see if I can get it working.

Thanks,

aarthificial added a commit to aarthificial/motion-canvas that referenced this issue May 7, 2023
`SignalGenerator` now has four additional methods for complex chaining:
```ts
yield* circle()
  // initiate the generator
  .scale(0.5, 2)
  // tween to another value
  .to(2, 2)
  // execute a callback
  .do(() => circle().fill('red'))
  // wait for one second
  .wait(1)
  // run the given generator
  .run(circle().position.y(100, 2))
  // tween back to the initial value
  .back(2);
```

Closes motion-canvas#480
Co-authored-by: Samarth Hattangady <samhattangady@gmail.com>
aarthificial added a commit to aarthificial/motion-canvas that referenced this issue May 7, 2023
`SignalGenerator` now has four additional methods for complex chaining:
```ts
yield* circle()
  // initiate the generator
  .scale(0.5, 2)
  // tween to another value
  .to(2, 2)
  // execute a callback
  .do(() => circle().fill('red'))
  // wait for one second
  .wait(1)
  // run the given generator
  .run(circle().position.y(100, 2))
  // tween back to the initial value
  .back(2);
```

Closes motion-canvas#480

Co-authored-by: Samarth Hattangady <samhattangady@gmail.com>
aarthificial added a commit that referenced this issue May 7, 2023
`SignalGenerator` now has four additional methods for complex chaining:
```ts
yield* circle()
  // initiate the generator
  .scale(0.5, 2)
  // tween to another value
  .to(2, 2)
  // execute a callback
  .do(() => circle().fill('red'))
  // wait for one second
  .wait(1)
  // run the given generator
  .run(circle().position.y(100, 2))
  // tween back to the initial value
  .back(2);
```

Closes #480

Co-authored-by: Samarth Hattangady <samhattangady@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-core Relates to the core package b-enhancement New feature or request c-accepted The issue is ready to be worked on
Projects
None yet
2 participants