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

[Animated] Animated.View component loses shadow on animation #16870

Closed
llanginger opened this issue Nov 17, 2017 · 6 comments
Closed

[Animated] Animated.View component loses shadow on animation #16870

llanginger opened this issue Nov 17, 2017 · 6 comments
Labels
Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@llanginger
Copy link

Is this a bug report?

Yes (I think!)

Have you read the Contributing Guidelines?

Yes

Environment

Environment:
OS: macOS High Sierra 10.13.1
Node: 8.9.0
Yarn: 1.2.1
npm: 5.5.1
Watchman: Not Found
Xcode: Xcode 9.1 Build version 9B55
Android Studio: Not Found

Packages: (wanted => installed)
react: 16.0.0-beta.5 => 16.0.0-beta.5
react-native: 0.49.1 => 0.49.1

Target Platform: iOS (8)

Steps to Reproduce

  1. Initialize new react-native project, import Animated and TouchableWithoutOpacity

  2. Create simple Animated function - in my case:

bounce() {
    this.springValue.setValue(0)
    Animated.spring(
        this.springValue,
        {
            toValue: 1,
            friction: 5,
            velocity: 20
        }
    ).start()
}

along with interpolation such as:

const bounceScale = this.springValue.interpolate({
    inputRange: [0, 0.5, 1],
    outputRange: [1, 0.99, 1]
})
  1. Create an Animated.View component with style props that include an animated {transform: { scale: bounceScale}} as well as shadow (offset and opacity) style props.

  2. Place the above Animated.View component inside a TouchableWithoutOpacity component and set onPress={this.bounce}

Expected Behavior

Animated.View component would, onPress, animate according to the bounce function leaving all other style props intact

Actual Behavior

Bounce function completes and removes shadow props:

Issue gif

Reproducible Demo

Snack demo: https://snack.expo.io/BkmcUs3yf

@mujavidb
Copy link

I had a similar problem with the elevation property. I fixed it by resetting the property to a new Animated.Value on completion, as such:

Animated.spring(
    this.springValue,
    {
        toValue: 1,
        friction: 5,
        velocity: 20
    }
).start(() => {
    this.springValue = new Animated.Value(1) // <--here
})

@llanginger
Copy link
Author

I was hopeful but alas, this seems not to solve my problem :(

@mujavidb
Copy link

Ahh, that's unfortunate. Instead of this.springValue = new Animated.Value(1) I have also used this.springValue.setValue(1)

@llanginger
Copy link
Author

Same deal, unfortunately - setValue certainly does its thing but the shadow disappears until the next time the component fully re-renders

@mujavidb
Copy link

So if you stored the animation in the component state a change to its value, would trigger a re-render.

A temporary solution, but I guess having this.setState({springValue: new Animated.Value(1)}) in the animation callback could be a fix.

@stale
Copy link

stale bot commented Jan 19, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jan 19, 2018
@stale stale bot closed this as completed Jan 26, 2018
@facebook facebook locked and limited conversation to collaborators May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

2 participants