1

I set a simple animated value like:

this.state = {
    filterOffset = new Animated.Value(0)
}

handleToogle() {
    var _toValue = this.state.filterOffset.interpolate({
        inputRange: [0, 1],
        outputRange: [1, 0]
    })
    Animated.timing(this.state.filterOffset, {
        toValue: _toValue,
        duration: 100
    }).start()
}

<View onPress={() => this.handleToogle()}>
</View>

Here I want to toggle a view.

I just want to set the value to 0 if 1 and vice versa so that I can apply style accordingly to another animated view.

Is it possible I can set an animated value to animation as a value.

Its not working for me ? Or there any better way to do this

Green Eagle
  • 227
  • 3
  • 12
  • Ok so you shouldn't use animated inside state as a first. And second can you post your entire code to show how you want to use the animated value, makes it easier to help – Nemi Shah May 24 '18 at 04:14
  • @NemiShah Why shouldn't you use animated inside a state? I think thats the way how it is documented: https://reactnative.dev/docs/animations, isn't it? – Sebastian Knopp Feb 28 '20 at 11:08
  • @SebastianKnopp you are right, my comment was from a time where I was still a little knaive about react native. Having the animated inside state is the general norm and is completely fine to do. – Nemi Shah Mar 06 '20 at 05:40

0 Answers0