Created
May 11, 2016 20:21
-
-
Save holmesal/1ebdc091bfd426032aa5577632130db7 to your computer and use it in GitHub Desktop.
1/x with react-native Animated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { | |
Animated, | |
Component, | |
View | |
} from 'react-native'; | |
export default class EasingTest extends Component { | |
state = { | |
input: new Animated.Value(0) | |
}; | |
componentDidMount() { | |
const max = 937; | |
const output = this.state.input.interpolate({ | |
inputRange: [0,max], | |
outputRange: [0,1/max], | |
easing: t => 1 / t | |
}); | |
setInterval(() => { | |
const input = this.state.input.__getValue(); | |
const expected = 1 / input; | |
const actual = output.__getValue(); | |
const error = Math.abs(expected - actual) / max; | |
console.info(`f(${input}) = ${actual} (expected ${expected}, error ${Math.round(error * 100)}%`); | |
}, 200); | |
Animated.timing(this.state.input, { | |
toValue: max, | |
duration: 1000 | |
}).start(); | |
} | |
render() { | |
return <View /> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment