Skip to content

Commit

Permalink
Add warning for style animations missing initial values (#3947)
Browse files Browse the repository at this point in the history
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary
Adds a warning for style animations missing initial values.

<!-- Explain the motivation for this PR. Include "Fixes #<number>" if
applicable. -->
  • Loading branch information
jwajgelt authored and piaskowyk committed Jan 17, 2023
1 parent 5a88e49 commit 1b63c80
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion Example/src/LayoutReanimation/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ function AnimatedView() {
'worklet';

return {
initialValues: {},
initialValues: {
transform: [
{ translateY: targetValues.currentHeight / 2 },
{ perspective: 500 },
{ rotateX: '0deg' },
{ translateY: -targetValues.currentHeight / 2 },
{ translateY: 0 },
],
},
animations: {
transform: [
{ translateY: withTiming(targetValues.currentHeight / 2) },
Expand Down
9 changes: 8 additions & 1 deletion src/reanimated2/animation/styleAnimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function setPath<T>(
for (let i = 0; i < keys.length - 1; i++) {
// creates entry if there isn't one
currObj = currObj as { [key: string]: NestedObjectValues<T> };
if (!currObj[keys[i]]) {
if (!(keys[i] in currObj)) {
// if next key is a number create an array
if (typeof keys[i + 1] === 'number') {
currObj[keys[i]] = [];
Expand Down Expand Up @@ -178,6 +178,13 @@ export function withStyleAnimation(
if (prevAnimation && !prevVal) {
prevVal = prevAnimation.current;
}
if (prevVal === undefined) {
console.warn(
`Initial values for animation are missing for property ${currentEntry.path.join(
'.'
)}`
);
}
setPath(animation.current, currentEntry.path, prevVal);
let currentAnimation: AnimationObject;
if (
Expand Down

0 comments on commit 1b63c80

Please sign in to comment.