Skip to content

Instantly share code, notes, and snippets.

@holmesal
Created May 11, 2016 20:21
Show Gist options
  • Save holmesal/1ebdc091bfd426032aa5577632130db7 to your computer and use it in GitHub Desktop.
Save holmesal/1ebdc091bfd426032aa5577632130db7 to your computer and use it in GitHub Desktop.
1/x with react-native Animated
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