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

do not execute finished animation #1618

Merged
merged 1 commit into from
Jan 12, 2021
Merged

Conversation

Szymon20000
Copy link
Contributor

Description

Fixes: #1588

There is a case In runAnimations function (used by useAnimatedStyle) in which we have an array of animations.
Of course, we have to wait until the last animation from the array is done but we cannot execute finished animations.
To prevent that I've added an additional check.

Changes

Added check if the animation has already finished.

Test code and steps to reproduce

import React from 'react'
import {
  StyleSheet
} from 'react-native'
import Animated, {
  useAnimatedStyle,
  withSequence,
  withSpring
  // withTiming
} from 'react-native-reanimated'

// const withSpring = withTiming;

export default function SequenceBug() {
  const animatedStyle = useAnimatedStyle(() => ({
    // if you change every instance of withSpring to withTiming, it works.
    transform: [ {
         scale: withSequence(withSpring(0), withSpring(0.5), withSpring(1), withSpring(1.5))
     },
      {
        translateY: withSequence(withSpring(0), withSpring(5), withSpring(10), withSpring(15))
      } 
    ]
  }))
  return <Animated.View style = {
    [style.item, animatedStyle]
  }
  />
}

const style = StyleSheet.create({
  item: {
    margin: 100,
    width: 300,
    height: 300,
    backgroundColor: 'blue',
    alignSelf: 'center',
    borderRadius: 999
  }
})

Checklist

  • Included code example that can be used to test this change
  • Updated TS types
  • Added TS types tests
  • Added unit / integration tests
  • Updated documentation
  • Ensured that CI passes

@karol-bisztyga
Copy link
Contributor

Good catch, it could be done shorter

let finished = true;
if (!animation.finished) {

but I think it's mergeable

@Szymon20000 Szymon20000 merged commit b190a90 into master Jan 12, 2021
@Szymon20000 Szymon20000 deleted the @szymon/fix_run_animations branch January 12, 2021 15:01
@nandorojo
Copy link
Contributor

Good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple withSpring sequences do not work.
3 participants