Skip to content

Commit b818f08

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

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
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 & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ import {
1212
flushCalls,
1313
} from 'shared'
1414
import {
15-
AnimatedType,
1615
AnimatedValue,
1716
AnimatedString,
18-
AnimatedArray,
1917
getPayload,
2018
getAnimated,
2119
setAnimated,
2220
Animated,
21+
getAnimatedType,
2322
} from 'animated'
2423
import * as G from 'shared/globals'
2524

@@ -490,7 +489,7 @@ export class SpringValue<T = any> extends FrameValue<T> {
490489
protected _updateNode(value: any): Animated | undefined {
491490
let node = getAnimated(this)
492491
if (!is.und(value)) {
493-
const nodeType = getNodeType(value)
492+
const nodeType = getAnimatedType(value)
494493
if (!node || node.constructor !== nodeType) {
495494
setAnimated(this, (node = nodeType.create(value)))
496495
}
@@ -680,7 +679,7 @@ export class SpringValue<T = any> extends FrameValue<T> {
680679
if (immediate) {
681680
node = this._updateNode(goal)!
682681
} else {
683-
const nodeType = getNodeType(to)
682+
const nodeType = getAnimatedType(to)
684683
if (nodeType !== node.constructor) {
685684
throw Error(
686685
`Cannot animate between ${node.constructor.name} and ${nodeType.name}, as the "to" prop suggests`
@@ -940,18 +939,6 @@ export class SpringValue<T = any> extends FrameValue<T> {
940939
}
941940
}
942941

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-
955942
/**
956943
* The "finished" value is determined by each "onRest" handler,
957944
* based on whether the current value equals the goal value that

0 commit comments

Comments
 (0)