-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
TypeScript for Layout Animations #2137
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5d21efa
Start with TS
piaskowyk 46bc02b
More types
piaskowyk e13849e
Type for builder
piaskowyk da6518d
Type for builder and style
piaskowyk 6965210
Refactor
piaskowyk 087023c
Default Animations
piaskowyk 75b6953
Rotate type
piaskowyk 69fb3d5
Globaltypes
piaskowyk e481c93
Refactor
piaskowyk d8a02a2
Update type for AnimatedLayout
piaskowyk a60ff29
Improvements after review
piaskowyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1 +1,17 @@ | ||||
declare const _WORKLET: boolean; | ||||
declare const _stopObservingProgress: (tag: number, flag: boolean) => void; | ||||
declare const _startObservingProgress: (tag: number, flag: boolean) => void; | ||||
declare namespace NodeJS { | ||||
interface Global { | ||||
Comment on lines
+4
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this is wrapped in Nodejs namespace? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I found information that namespace NodeJS is required for the definition of properties in the global object. But correct me please if I am wrong.
|
||||
LayoutAnimationRepository: { | ||||
configs: Record<string, unknown>; | ||||
registerConfig(tag: number, config: Record<string, unknown>): void; | ||||
removeConfig(tag: number): void; | ||||
startAnimationForTag( | ||||
tag: number, | ||||
type: unknown, | ||||
yogaValues: unknown | ||||
): void; | ||||
}; | ||||
} | ||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
src/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
import { withDelay, withTiming, withSpring } from '../../animations'; | ||
import { | ||
EntryExitAnimationFunction, | ||
AnimationFunction, | ||
BaseBuilderAnimationConfig, | ||
LayoutAnimationAndConfig, | ||
EntryExitAnimationBuild, | ||
} from './commonTypes'; | ||
import { EasingFn } from '../../Easing'; | ||
|
||
export class BaseAnimationBuilder { | ||
durationV?: number; | ||
easingV?: EasingFn; | ||
delayV?: number; | ||
rotateV?: string; | ||
type?: AnimationFunction; | ||
dampingV?: number; | ||
massV?: number; | ||
stiffnessV?: number; | ||
overshootClampingV?: number; | ||
restDisplacementThresholdV?: number; | ||
restSpeedThresholdV?: number; | ||
|
||
static createInstance: () => BaseAnimationBuilder; | ||
build: EntryExitAnimationBuild; | ||
|
||
static duration(durationMs: number): BaseAnimationBuilder { | ||
const instance = this.createInstance(); | ||
return instance.duration(durationMs); | ||
} | ||
|
||
duration(durationMs: number): BaseAnimationBuilder { | ||
this.durationV = durationMs; | ||
return this; | ||
} | ||
|
||
static easing(easingFunction: EasingFn): BaseAnimationBuilder { | ||
const instance = this.createInstance(); | ||
return instance.easing(easingFunction); | ||
} | ||
|
||
easing(easingFunction: EasingFn): BaseAnimationBuilder { | ||
this.easingV = easingFunction; | ||
return this; | ||
} | ||
|
||
static delay(delayMs: number): BaseAnimationBuilder { | ||
const instance = this.createInstance(); | ||
return instance.delay(delayMs); | ||
} | ||
|
||
delay(delayMs: number): BaseAnimationBuilder { | ||
this.delayV = delayMs; | ||
return this; | ||
} | ||
|
||
static rotate(degree: string): BaseAnimationBuilder { | ||
const instance = this.createInstance(); | ||
return instance.rotate(degree); | ||
} | ||
|
||
rotate(degree: string): BaseAnimationBuilder { | ||
this.rotateV = degree; | ||
return this; | ||
} | ||
|
||
static springify(): BaseAnimationBuilder { | ||
const instance = this.createInstance(); | ||
return instance.springify(); | ||
} | ||
|
||
springify(): BaseAnimationBuilder { | ||
this.type = withSpring as AnimationFunction; | ||
return this; | ||
} | ||
|
||
static damping(damping: number): BaseAnimationBuilder { | ||
const instance = this.createInstance(); | ||
return instance.damping(damping); | ||
} | ||
|
||
damping(damping: number): BaseAnimationBuilder { | ||
this.dampingV = damping; | ||
return this; | ||
} | ||
|
||
static mass(mass: number): BaseAnimationBuilder { | ||
const instance = this.createInstance(); | ||
return instance.mass(mass); | ||
} | ||
|
||
mass(mass: number): BaseAnimationBuilder { | ||
this.massV = mass; | ||
return this; | ||
} | ||
|
||
static stiffness(stiffness: number): BaseAnimationBuilder { | ||
const instance = this.createInstance(); | ||
return instance.stiffness(stiffness); | ||
} | ||
|
||
stiffness(stiffness: number): BaseAnimationBuilder { | ||
this.stiffnessV = stiffness; | ||
return this; | ||
} | ||
|
||
static overshootClamping(overshootClamping: number): BaseAnimationBuilder { | ||
const instance = this.createInstance(); | ||
return instance.overshootClamping(overshootClamping); | ||
} | ||
|
||
overshootClamping(overshootClamping: number): BaseAnimationBuilder { | ||
this.overshootClampingV = overshootClamping; | ||
return this; | ||
} | ||
|
||
static restDisplacementThreshold( | ||
restDisplacementThreshold: number | ||
): BaseAnimationBuilder { | ||
const instance = this.createInstance(); | ||
return instance.restDisplacementThreshold(restDisplacementThreshold); | ||
} | ||
|
||
restDisplacementThreshold( | ||
restDisplacementThreshold: number | ||
): BaseAnimationBuilder { | ||
this.restDisplacementThresholdV = restDisplacementThreshold; | ||
return this; | ||
} | ||
|
||
static restSpeedThreshold(restSpeedThreshold: number): BaseAnimationBuilder { | ||
const instance = this.createInstance(); | ||
return instance.restSpeedThreshold(restSpeedThreshold); | ||
} | ||
|
||
restSpeedThreshold(restSpeedThreshold: number): BaseAnimationBuilder { | ||
this.restSpeedThresholdV = restSpeedThreshold; | ||
return this; | ||
} | ||
|
||
static build(): EntryExitAnimationFunction { | ||
const instance = this.createInstance(); | ||
return instance.build(); | ||
} | ||
|
||
getDelayFunction(): AnimationFunction { | ||
const delay = this.delayV; | ||
return delay | ||
? withDelay | ||
: (_, animation) => { | ||
'worklet'; | ||
return animation; | ||
}; | ||
} | ||
|
||
getAnimationAndConfig(): LayoutAnimationAndConfig { | ||
const duration = this.durationV; | ||
const easing = this.easingV; | ||
const rotate = this.rotateV; | ||
const type = this.type ? this.type : (withTiming as AnimationFunction); | ||
const damping = this.dampingV; | ||
const mass = this.massV; | ||
const stiffness = this.stiffnessV; | ||
const overshootClamping = this.overshootClampingV; | ||
const restDisplacementThreshold = this.restDisplacementThresholdV; | ||
const restSpeedThreshold = this.restSpeedThresholdV; | ||
|
||
const animation = type; | ||
|
||
const config: BaseBuilderAnimationConfig = {}; | ||
|
||
if (type === withTiming) { | ||
if (easing) { | ||
config.easing = easing; | ||
} | ||
if (duration) { | ||
config.duration = duration; | ||
} | ||
if (rotate) { | ||
config.rotate = rotate; | ||
} | ||
} else { | ||
if (damping) { | ||
config.damping = damping; | ||
} | ||
if (mass) { | ||
config.mass = mass; | ||
} | ||
if (stiffness) { | ||
config.stiffness = stiffness; | ||
} | ||
if (overshootClamping) { | ||
config.overshootClamping = overshootClamping; | ||
} | ||
if (restDisplacementThreshold) { | ||
config.restDisplacementThreshold = restDisplacementThreshold; | ||
} | ||
if (restSpeedThreshold) { | ||
config.restSpeedThreshold = restSpeedThreshold; | ||
} | ||
if (rotate) { | ||
config.rotate = rotate; | ||
} | ||
} | ||
return [animation, config]; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/reanimated2/layoutReanimation/animationBuilder/BaseBounceAnimationBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { withDelay, withTiming } from '../../animations'; | ||
import { | ||
EntryExitAnimationFunction, | ||
AnimationFunction, | ||
LayoutAnimationAndConfig, | ||
BounceBuilderAnimationConfig, | ||
EntryExitAnimationBuild, | ||
} from './commonTypes'; | ||
|
||
export class BaseBounceAnimationBuilder { | ||
durationV: number; | ||
delayV: number; | ||
|
||
static createInstance: () => BaseBounceAnimationBuilder; | ||
build: EntryExitAnimationBuild; | ||
|
||
static duration(durationMs: number): BaseBounceAnimationBuilder { | ||
const instance = this.createInstance(); | ||
return instance.duration(durationMs); | ||
} | ||
|
||
duration(durationMs: number): BaseBounceAnimationBuilder { | ||
this.durationV = durationMs; | ||
return this; | ||
} | ||
|
||
static delay(delayMs: number): BaseBounceAnimationBuilder { | ||
const instance = this.createInstance(); | ||
return instance.delay(delayMs); | ||
} | ||
|
||
delay(delayMs: number): BaseBounceAnimationBuilder { | ||
this.delayV = delayMs; | ||
return this; | ||
} | ||
|
||
getDelayFunction(): AnimationFunction { | ||
const delay = this.delayV; | ||
return delay | ||
? withDelay | ||
: (_, animation) => { | ||
'worklet'; | ||
return animation; | ||
}; | ||
} | ||
|
||
getAnimationAndConfig(): LayoutAnimationAndConfig { | ||
const duration = this.durationV; | ||
const type = withTiming; | ||
const animation = type; | ||
|
||
const config: BounceBuilderAnimationConfig = {}; | ||
|
||
if (duration) { | ||
config.duration = duration; | ||
} | ||
|
||
return [animation, config]; | ||
} | ||
|
||
static build(): EntryExitAnimationFunction { | ||
const instance = this.createInstance(); | ||
return instance.build(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is just a temporary solution. We will add types for animation in the next PR.