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

chore(TS): animation #8297

Merged
merged 122 commits into from Dec 30, 2022
Merged

chore(TS): animation #8297

merged 122 commits into from Dec 30, 2022

Conversation

Lazauya
Copy link
Contributor

@Lazauya Lazauya commented Sep 18, 2022

Changes

  • Refactor animation logic into classes:
    • AnimationBase contains all the logic
    • Subclasses handle initialization logic and impl calculate that returns the current value of the animation
  • animate color
  • fix end value calculation:
    there was a conflict happening in the cases:
    • passing byValue without endValue since defaults are assigned to both, endValue and byValue diverged
    • passing diverged byValue, endValue
    • this fix uncovered bugs in easing functions that I fixed
  • Color:
    • accept more param types (color source, color instance) in constructor and deprecate fromSource as it has become redundant
  • BREAKING:
    return animation instance from animate instead of a cancel function and remove findAnimationByXXX from AnimationRegistry

Gist

@asturur there are too many threads in this PR. All are pretty much stale accept #8297 (review) that I would like you to comment on.

Proposals

  • What about making AnimationBase extend Observable and fire state events?
const context = animate({ ... })
context.on('change', () => {})
  • It is possible to make animate accept also a color animation options object
animate({
  startValue: [r,g,b,a] // TS will find this hard to handle since it is an array and will fall into the array animation case
  type: 'color' // this will do the job
})
  • accept color values in color animation
animate({
  startValue: 'colorString' // TS will find this easy to understand and handle as `ColorAnimation`
})
animate({
  startValue: new Color('colorString') // even better, making passing `type: color` redundant
})
  • accept color space option for color animation
animate({
  startValue: new Color('colorString') // even better, making passing `type: color` redundant
  colorSpace: 'hsl'
})

type fixes,
mergeWithDefaults for animate
ran npm audit
# Conflicts:
#	src/constants.ts
#	src/typedefs.ts
#	src/util/anim_ease.ts
#	src/util/animate.ts
#	src/util/animate_color.ts
#	src/util/lang_object.ts
Copy link
Contributor

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments, nothing major
Checkout package-lock.json from master (upstream probably) so it is removed from the PR diff
And run prettier

src/util/anim_ease.ts Outdated Show resolved Hide resolved
src/util/animate.ts Outdated Show resolved Hide resolved
src/util/animate.ts Outdated Show resolved Hide resolved
src/util/anim_ease.ts Outdated Show resolved Hide resolved
src/util/anim_ease.ts Outdated Show resolved Hide resolved
src/util/animate.ts Outdated Show resolved Hide resolved
src/util/animate.ts Outdated Show resolved Hide resolved
src/util/animate.ts Outdated Show resolved Hide resolved
src/util/animate_color.ts Outdated Show resolved Hide resolved
src/constants.ts Outdated Show resolved Hide resolved
src/util/anim_ease.ts Outdated Show resolved Hide resolved
src/util/animate.ts Outdated Show resolved Hide resolved
}
},
onChange: (current, valuePerc, timePerc) =>
onChange?.(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we slipped in a bunch of optional chaining operator, but those are not supported before chrome 80.
We didn't fully decide yet which browsers are we going to support, in this case better leave the code as it was.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove the chaining ops, but typescript compiles it down into unchained anyway so I don't get why we should remove them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know that's a problem

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because typescript compile down a lot of stuff that we don't let it do.
For now we let the browsersupport of rollup compile the stuff for us.
I couldn't get Typescript to choose browser granularity in chosing what to compile to, and at the end what you have to support is browsers.

src/util/animate.ts Outdated Show resolved Hide resolved
src/util/animate_color.ts Outdated Show resolved Hide resolved
@asturur
Copy link
Member

asturur commented Sep 18, 2022

there are at least 3 behavor change i would like to see reverted, and it seems to me you added a target new option that should be proposed on a separate PR.

@Lazauya
Copy link
Contributor Author

Lazauya commented Sep 18, 2022

there are at least 3 behavor change i would like to see reverted, and it seems to me you added a target new option that should be proposed on a separate PR.

The only ACTUAL behavior change is that the currentState of a color animation is now a TColorAlphaSource instead of a color string. See my other comments about the target stuff. I can change it but the problem is its SUPER hard to generify the animate util function to work with "normal" animations and color animations. It took me a long time to realize that just changing animateColor match animate would be more clean in the end. I can make another PR specifically for that I suppose if that would be better.

Copy link
Contributor

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typed animation registry to avoid confusion

it's weird that when I comment and review the comments are displayed out of context

src/util/animate.ts Outdated Show resolved Hide resolved
}
},
onChange: (current, valuePerc, timePerc) =>
onChange?.(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know that's a problem

src/util/animate.ts Outdated Show resolved Hide resolved
src/util/animate_color.ts Outdated Show resolved Hide resolved
@asturur
Copy link
Member

asturur commented Sep 19, 2022

there are at least 3 behavor change i would like to see reverted, and it seems to me you added a target new option that should be proposed on a separate PR.

The only ACTUAL behavior change is that the currentState of a color animation is now a TColorAlphaSource instead of a color string. See my other comments about the target stuff. I can change it but the problem is its SUPER hard to generify the animate util function to work with "normal" animations and color animations. It took me a long time to realize that just changing animateColor match animate would be more clean in the end. I can make another PR specifically for that I suppose if that would be better.

I think the 3 behavor change are:

removal of ...restOptions
remove of calculateColor where @ShaMan123 pointed out
on the onChange part assuming that the value is always an array and removing the array check
Arent' those changes?

Adding in pr description modified the color animate function to be more generic doesn't help much in understanding why are you changing things, on top of that those changes should be factored away from a typing pr.

@Lazauya Lazauya changed the title Animate & Animate Color Typing Animate & Animation Registry Sep 23, 2022
@Lazauya
Copy link
Contributor Author

Lazauya commented Sep 23, 2022

I went ahead and removed animate color stuff. I'm putting that in a new PR where I'll clean it up.

@Lazauya Lazauya changed the title Animate & Animation Registry Animate & Animation Registry Typing Sep 24, 2022
@Lazauya
Copy link
Contributor Author

Lazauya commented Sep 30, 2022

@ShaMan123 @asturur Any outstanding issues with this?

Copy link
Contributor

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the status of the isMany typing?
I would like that in this PR

src/util/animate.ts Outdated Show resolved Hide resolved
src/util/animate.ts Outdated Show resolved Hide resolved
@ShaMan123
Copy link
Contributor

ShaMan123 commented Oct 1, 2022

In order to pass tests:

  • Add a changelog entry describing changes
  • run npm run prettier:write and commit
  • lint is not your fault

ShaMan123
ShaMan123 previously approved these changes Dec 27, 2022
Copy link
Contributor

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor patch color
updated from master
updated description
seems good to go

@ShaMan123
Copy link
Contributor

@asturur let's merge this one
Too long has it been waiting

@asturur
Copy link
Member

asturur commented Dec 29, 2022

@asturur let's merge this one Too long has it been waiting

We had a list of priorities i m going in order.
I have to re-catch up because i have no idea what is this anymore.
Re-reading now.

@asturur
Copy link
Member

asturur commented Dec 29, 2022

Ok fixed merge conflicts that is step 1

@asturur
Copy link
Member

asturur commented Dec 29, 2022

notes for me since this is a long review

@asturur asturur self-assigned this Dec 29, 2022
@asturur
Copy link
Member

asturur commented Dec 29, 2022

this build
313352 Dec 29 22:31 fabric.min.js
master build
311733 Dec 29 22:37 fabric.min.js

1.6KB extra, not sure why, they usually reduce, but not an issue

@asturur
Copy link
Member

asturur commented Dec 29, 2022

Will take me tomorrow to finish reading this.
I wish there was a little bit more explanation on the pr message.
Is it clear that the external interface isn't changed ( apart for the returned value ) but a bit more of text on AnimationBase and Animation, ArrayAnimation and ColorAnimation would have been nice.
You have to consider the order you get the files to review is not the execution order and you start reading having no idea what is going to happen.

if (!propIsColor && typeof to === 'string') {
// check for things like +=50
// which should animate so that the thing moves by 50 units in the positive direction
to = to.includes('=')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we dump this?

@ShaMan123
Copy link
Contributor

You have to consider the order you get the files to review is not the execution order and you start reading having no idea what is going to happen.

Point taken

@asturur
Copy link
Member

asturur commented Dec 30, 2022

I think this PR is good, thanks both.
I want to simplify something, maybe i can do that following up with a different pr.
Example:

  • object animatabale could not use util animate but just start the animation on its own
  • get rid of all custom syntax += syntax for animation.
  • remove the FX_DURATION concepts and all the 4 premade effects and relegate them to a folder called examples.

I have noticed there are type tests, and i see they can't run for now. is that correct?

@asturur asturur merged commit 695cf10 into fabricjs:master Dec 30, 2022
@ShaMan123
Copy link
Contributor

object animatabale could not use util animate but just start the animation on its own

didn't get what you meant.

The rest I agree.

I have noticed there are type tests, and i see they can't run for now. is that correct?

Correct. #8394 handles the test framework.

frankrousseau pushed a commit to cgwire/fabric.js that referenced this pull request Jan 6, 2023
Co-authored-by: kristpregracke <kpregracke@redfoundry.com>
Co-authored-by: ShaMan123 <shacharnen@gmail.com>
Co-authored-by: Shachar <34343793+ShaMan123@users.noreply.github.com>
Co-authored-by: Andrea Bogazzi <andreabogazzi79@gmail.com>
ShaMan123 added a commit that referenced this pull request Mar 16, 2024
Co-authored-by: kristpregracke <kpregracke@redfoundry.com>
Co-authored-by: ShaMan123 <shacharnen@gmail.com>
Co-authored-by: Shachar <34343793+ShaMan123@users.noreply.github.com>
Co-authored-by: Andrea Bogazzi <andreabogazzi79@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Animate color seems broken in current master
4 participants