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

Add warning for style animations missing initial values #3947

Merged
merged 2 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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