Skip to content

Commit 7695a80

Browse files
committed
refactor: rename getNodeType to getAnimatedType (and move it to packages/animated)
1 parent 8ed5a42 commit 7695a80

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { is, isAnimatedString } from 'shared'
2+
import { AnimatedType } from './types'
3+
import { AnimatedArray } from './AnimatedArray'
4+
import { AnimatedString } from './AnimatedString'
5+
import { AnimatedValue } from './AnimatedValue'
6+
import { getAnimated } from './Animated'
7+
8+
/** Return the `Animated` node constructor for a given value */
9+
export function getAnimatedType(value: any): AnimatedType {
10+
const parentNode = getAnimated(value)
11+
return parentNode
12+
? (parentNode.constructor as any)
13+
: is.arr(value)
14+
? AnimatedArray
15+
: isAnimatedString(value)
16+
? AnimatedString
17+
: AnimatedValue
18+
}

packages/animated/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export * from './AnimatedString'
44
export * from './AnimatedArray'
55
export * from './AnimatedObject'
66
export * from './AnimatedProps'
7+
export * from './getAnimatedType'
78
export * from './createHost'
89
export * from './types'

packages/core/src/Interpolation.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@ import {
1313
import * as G from 'shared/globals'
1414

1515
import { FrameValue, isFrameValue } from './FrameValue'
16-
import {
17-
getAnimated,
18-
setAnimated,
19-
AnimatedValue,
20-
AnimatedArray,
21-
AnimatedType,
22-
getPayload,
23-
} from 'animated'
16+
import { getAnimated, setAnimated, getAnimatedType, getPayload } from 'animated'
2417

2518
/**
2619
* An `Interpolation` is a memoized value that's computed whenever one of its
@@ -49,7 +42,7 @@ export class Interpolation<In = any, Out = any> extends FrameValue<Out> {
4942
this.calc = createInterpolator(...args)
5043

5144
const value = this._get()
52-
const nodeType: AnimatedType = is.arr(value) ? AnimatedArray : AnimatedValue
45+
const nodeType = getAnimatedType(value)
5346

5447
// Assume the computed value never changes type.
5548
setAnimated(this, nodeType.create(value))

packages/core/src/SpringValue.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
getAnimated,
2121
setAnimated,
2222
Animated,
23+
getAnimatedType,
2324
} from 'animated'
2425
import * as G from 'shared/globals'
2526

@@ -490,7 +491,7 @@ export class SpringValue<T = any> extends FrameValue<T> {
490491
protected _updateNode(value: any): Animated | undefined {
491492
let node = getAnimated(this)
492493
if (!is.und(value)) {
493-
const nodeType = getNodeType(value)
494+
const nodeType = getAnimatedType(value)
494495
if (!node || node.constructor !== nodeType) {
495496
setAnimated(this, (node = nodeType.create(value)))
496497
}
@@ -680,7 +681,7 @@ export class SpringValue<T = any> extends FrameValue<T> {
680681
if (immediate) {
681682
node = this._updateNode(goal)!
682683
} else {
683-
const nodeType = getNodeType(to)
684+
const nodeType = getAnimatedType(to)
684685
if (nodeType !== node.constructor) {
685686
throw Error(
686687
`Cannot animate between ${node.constructor.name} and ${nodeType.name}, as the "to" prop suggests`
@@ -940,18 +941,6 @@ export class SpringValue<T = any> extends FrameValue<T> {
940941
}
941942
}
942943

943-
/** Return the `Animated` node constructor for a given value */
944-
function getNodeType(value: any): AnimatedType {
945-
const parentNode = getAnimated(value)
946-
return parentNode
947-
? (parentNode.constructor as any)
948-
: is.arr(value)
949-
? AnimatedArray
950-
: isAnimatedString(value)
951-
? AnimatedString
952-
: AnimatedValue
953-
}
954-
955944
/**
956945
* The "finished" value is determined by each "onRest" handler,
957946
* based on whether the current value equals the goal value that

0 commit comments

Comments
 (0)