-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add interpolate function from kmagiera with example. [WIP] #11
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e3507b3
Add interpolate function from kmagiera with example.
DylanVann 3a2b557
Finish renaming.
DylanVann f4ab3f8
Add extrapolation handling, add more examples, add titles.
DylanVann e9807e2
Update readme.
DylanVann f2c2084
Fix extrapolations.
DylanVann 722b24a
Fix readme.
DylanVann febeb6a
Remove metro-with-symlinks.
DylanVann 74a4742
Change name to getAnimation.
DylanVann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,3 +54,6 @@ buck-out/ | |
|
|
||
| # Bundle artifact | ||
| *.jsbundle | ||
|
|
||
| # metro-with-symlinks | ||
| metro.config.js | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import React, { Component } from 'react'; | ||
| import { StyleSheet, View } from 'react-native'; | ||
|
|
||
| import Animated, { Easing } from 'react-native-reanimated'; | ||
|
|
||
| const { | ||
| set, | ||
| cond, | ||
| eq, | ||
| and, | ||
| add, | ||
| call, | ||
| multiply, | ||
| lessThan, | ||
| startClock, | ||
| stopClock, | ||
| clockRunning, | ||
| block, | ||
| timing, | ||
| debug, | ||
| spring, | ||
| Value, | ||
| Clock, | ||
| event, | ||
| interpolate, | ||
| } = Animated; | ||
|
|
||
| function runSpring(clock, value, dest) { | ||
| const state = { | ||
| finished: new Value(0), | ||
| velocity: new Value(0), | ||
| position: new Value(0), | ||
| time: new Value(0), | ||
| }; | ||
|
|
||
| const config = { | ||
| toValue: new Value(0), | ||
| damping: 7, | ||
| mass: 1, | ||
| stiffness: 121.6, | ||
| overshootClamping: false, | ||
| restSpeedThreshold: 0.001, | ||
| restDisplacementThreshold: 0.001, | ||
| }; | ||
|
|
||
| return block([ | ||
| cond(clockRunning(clock), 0, [ | ||
| set(state.finished, 0), | ||
| set(state.time, 0), | ||
| set(state.position, value), | ||
| set(state.velocity, -2500), | ||
| set(config.toValue, dest), | ||
| startClock(clock), | ||
| ]), | ||
| spring(clock, state, config), | ||
| cond(state.finished, debug('stop clock', stopClock(clock))), | ||
| state.position, | ||
| ]); | ||
| } | ||
|
|
||
| function runTiming(clock, value, dest) { | ||
| const state = { | ||
| finished: new Value(1), | ||
| position: new Value(value), | ||
| time: new Value(0), | ||
| frameTime: new Value(0), | ||
| }; | ||
|
|
||
| const config = { | ||
| duration: 500, | ||
| toValue: new Value(0), | ||
| easing: Easing.inOut(Easing.ease), | ||
| }; | ||
|
|
||
| const reset = [ | ||
| set(state.finished, 0), | ||
| set(state.time, 0), | ||
| set(state.frameTime, 0), | ||
| ] | ||
|
|
||
| return block([ | ||
| cond(and(state.finished, eq(state.position, value)), [ | ||
| ...reset, | ||
| set(config.toValue, dest), | ||
| ]), | ||
| cond(and(state.finished, eq(state.position, dest)), [ | ||
| ...reset, | ||
| set(config.toValue, value), | ||
| ]), | ||
| cond(clockRunning(clock), 0, startClock(clock)), | ||
| timing(clock, state, config), | ||
| state.position, | ||
| ]); | ||
| } | ||
|
|
||
| export default class Example extends Component { | ||
| constructor(props) { | ||
| super(props); | ||
| const clock = new Clock(); | ||
| const base = runTiming(clock, -120, 120); | ||
| this._transX = interpolate(base, [-120, -60, 60, 120], [-20, -1, 1, 20]) | ||
| } | ||
| render() { | ||
| return ( | ||
| <View style={styles.container}> | ||
| <Animated.View | ||
| style={[styles.box, { transform: [{ translateX: this._transX }] }]} | ||
| /> | ||
| </View> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| const BOX_SIZE = 100; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container: { | ||
| flex: 1, | ||
| justifyContent: 'center', | ||
| alignItems: 'center', | ||
| backgroundColor: '#F5FCFF', | ||
| }, | ||
| box: { | ||
| width: BOX_SIZE, | ||
| height: BOX_SIZE, | ||
| borderColor: '#F5FCFF', | ||
| alignSelf: 'center', | ||
| backgroundColor: 'plum', | ||
| margin: BOX_SIZE / 2, | ||
| }, | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,9 @@ | |
| "version": "0.0.1", | ||
| "private": true, | ||
| "scripts": { | ||
| "start": "node node_modules/react-native/local-cli/cli.js start", | ||
| "start": "metro-with-symlinks start", | ||
| "test": "jest", | ||
| "postinstall": "rm -rf node_modules/react-native-reanimated/{.git,node_modules,Example}" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used this with |
||
| "postinstall": "metro-with-symlinks" | ||
| }, | ||
| "dependencies": { | ||
| "react": "16.3.2", | ||
|
|
@@ -18,6 +18,7 @@ | |
| "babel-jest": "22.4.3", | ||
| "babel-preset-react-native": "4.0.0", | ||
| "jest": "22.4.3", | ||
| "metro-with-symlinks": "^1.0.12", | ||
| "react-test-renderer": "16.3.1" | ||
| }, | ||
| "jest": { | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| const config = require('./metro.config.js') | ||
|
|
||
| module.exports = config |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1715,6 +1715,10 @@ decode-uri-component@^0.2.0: | |
| version "0.2.0" | ||
| resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545" | ||
|
|
||
| dedent-js@^1.0.1: | ||
| version "1.0.1" | ||
| resolved "https://registry.yarnpkg.com/dedent-js/-/dedent-js-1.0.1.tgz#bee5fb7c9e727d85dffa24590d10ec1ab1255305" | ||
|
|
||
| deep-extend@~0.4.0: | ||
| version "0.4.2" | ||
| resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.4.2.tgz#48b699c27e334bf89f10892be432f6e4c7d34a7f" | ||
|
|
@@ -3408,6 +3412,12 @@ [email protected]: | |
| dependencies: | ||
| source-map "^0.5.6" | ||
|
|
||
| metro-with-symlinks@^1.0.12: | ||
| version "1.0.12" | ||
| resolved "https://registry.yarnpkg.com/metro-with-symlinks/-/metro-with-symlinks-1.0.12.tgz#d76599face0e6f6dfc849de042249427809ee48c" | ||
| dependencies: | ||
| dedent-js "^1.0.1" | ||
|
|
||
| metro@^0.30.0: | ||
| version "0.30.2" | ||
| resolved "https://registry.yarnpkg.com/metro/-/metro-0.30.2.tgz#e722e0eb106530f6d5bcf8de1f50353a0732cfb3" | ||
|
|
||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (
metro-with-symlinks) makes developing while experimenting with the examples a lot easier. With this you can useyarn link.