Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/__tests__
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test": "jest",
"test:dev": "jest --watch --no-coverage",
"test:coverage:watch": "jest --watch",
"test:ts": "tsc --noEmit",
"test:ts": "tsc -p types/__tests__/tsconfig.json",
"postinstall": "node -e \"console.log('\\u001b[35m\\u001b[1mEnjoy react-spring? You can now donate to our open collective:\\u001b[22m\\u001b[39m\\n > \\u001b[34mhttps://opencollective.com/react-spring/donate\\u001b[0m')\""
},
"husky": {
Expand Down Expand Up @@ -97,6 +97,7 @@
"rollup-plugin-node-resolve": "4.0.0",
"rollup-plugin-size-snapshot": "0.8.0",
"rollup-plugin-uglify": "6.0.2",
"spec.ts": "^1.1.0",
"typescript": "3.3.3"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/animated/AnimatedInterpolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ export default class AnimatedInterpolation extends AnimatedArray<Animated>
range: number[] | InterpolationConfig | ((...args: any[]) => IpValue),
output?: (number | string)[]
): AnimatedInterpolation {
return new AnimatedInterpolation(this, range as number[], output!)
return new AnimatedInterpolation(this, range as number[], output)
}
}
21 changes: 16 additions & 5 deletions src/animated/AnimatedValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { InterpolationConfig } from '../types/interpolation'
import Animated from './Animated'
import AnimatedInterpolation from './AnimatedInterpolation'
import AnimatedProps from './AnimatedProps'
import { now } from './Globals'

/**
* Animated works by building a directed acyclic graph of dependencies
Expand Down Expand Up @@ -41,15 +42,15 @@ function addAnimatedStyles(
export default class AnimatedValue extends Animated implements SpringValue {
private animatedStyles = new Set<AnimatedProps>()

public value: number | string
public startPosition: number | string
public lastPosition: number | string
public value: any
public startPosition: any
public lastPosition: any
public lastVelocity?: number
public startTime?: number
public lastTime?: number
public done = false

constructor(value: number | string) {
constructor(value: any) {
super()
this.value = value
this.startPosition = value
Expand All @@ -67,7 +68,7 @@ export default class AnimatedValue extends Animated implements SpringValue {
this.animatedStyles.clear()
}

public setValue = (value: number | string, flush = true) => {
public setValue = (value: any, flush = true) => {
this.value = value
if (flush) this.flush()
}
Expand All @@ -82,4 +83,14 @@ export default class AnimatedValue extends Animated implements SpringValue {
): AnimatedInterpolation {
return new AnimatedInterpolation(this, range as number[], output!)
}

public reset(isActive: boolean) {
this.startPosition = this.value
this.lastPosition = this.value
this.lastVelocity = isActive ? this.lastVelocity : undefined
this.lastTime = isActive ? this.lastTime : undefined
this.startTime = now()
this.done = false
this.animatedStyles.clear()
}
}
8 changes: 4 additions & 4 deletions src/animated/AnimatedValueArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import AnimatedValue from './AnimatedValue'

export default class AnimatedValueArray extends AnimatedArray<AnimatedValue>
implements SpringValue {
constructor(values: (string | number)[]) {
constructor(values: AnimatedValue[]) {
super()
this.payload = values.map(n => new AnimatedValue(n))
this.payload = values
}

public setValue(value: (string | number)[] | string | number, flush = true) {
public setValue(value: any, flush = true) {
if (Array.isArray(value)) {
if (value.length === this.payload.length) {
value.forEach((v, i) => this.payload[i].setValue(v, flush))
Expand All @@ -29,6 +29,6 @@ export default class AnimatedValueArray extends AnimatedArray<AnimatedValue>
range: number[] | InterpolationConfig | ((...args: any[]) => any),
output?: (number | string)[]
): AnimatedInterpolation {
return new AnimatedInterpolation(this, range as number[], output!)
return new AnimatedInterpolation(this, range as number[], output)
}
}
Loading