Skip to content

Commit 55f3a24

Browse files
committed
Remove redundant code
1 parent d0223f7 commit 55f3a24

File tree

6 files changed

+22
-27
lines changed

6 files changed

+22
-27
lines changed

src/Chase.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react'
22
import { Animated, Easing } from 'react-native'
33
import { SpinnerProps, defaultProps } from './SpinnerProps'
44
import AnimationContainer from './AnimationContainer'
5-
import { anim, stagger } from './utils'
5+
import { loop, stagger } from './utils'
66

77
export default class Chase extends React.Component<SpinnerProps> {
88
static defaultProps = defaultProps
@@ -29,7 +29,7 @@ export default class Chase extends React.Component<SpinnerProps> {
2929
initAnimation={() => ({
3030
chase: (value) => ({
3131
values: [value],
32-
animation: anim({
32+
animation: loop({
3333
duration: 2500,
3434
easing: Easing.linear,
3535
value: value,

src/Plane.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react'
22
import { Animated } from 'react-native'
33
import { SpinnerProps, defaultProps } from './SpinnerProps'
44
import AnimationContainer from './AnimationContainer'
5-
import { anim } from './utils'
5+
import { loop } from './utils'
66

77
export default class Plane extends React.Component<SpinnerProps> {
88
static defaultProps = defaultProps
@@ -22,7 +22,7 @@ export default class Plane extends React.Component<SpinnerProps> {
2222
initAnimation={() => ({
2323
plane: (value) => ({
2424
values: [value],
25-
animation: anim({
25+
animation: loop({
2626
duration: 1200,
2727
value: value,
2828
keyframes: [0, 50, 100],

src/Pulse.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react'
22
import { Animated, Easing } from 'react-native'
33
import { SpinnerProps, defaultProps } from './SpinnerProps'
44
import AnimationContainer from './AnimationContainer'
5-
import { anim } from './utils'
5+
import { loop } from './utils'
66

77
export default class Pulse extends React.Component<SpinnerProps> {
88
static defaultProps = defaultProps
@@ -22,7 +22,7 @@ export default class Pulse extends React.Component<SpinnerProps> {
2222
initAnimation={() => ({
2323
pulse: (value) => ({
2424
values: [value],
25-
animation: anim({
25+
animation: loop({
2626
duration: 1200,
2727
value: value,
2828
easing: Easing.bezier(0.455, 0.03, 0.515, 0.955),

src/Swing.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react'
22
import { Animated, Easing } from 'react-native'
33
import { SpinnerProps, defaultProps } from './SpinnerProps'
44
import AnimationContainer from './AnimationContainer'
5-
import { anim } from './utils'
5+
import { loop } from './utils'
66

77
export default class Swing extends React.Component<SpinnerProps> {
88
static defaultProps = defaultProps
@@ -28,7 +28,7 @@ export default class Swing extends React.Component<SpinnerProps> {
2828
initAnimation={() => ({
2929
swing: (value) => ({
3030
values: [value],
31-
animation: anim({
31+
animation: loop({
3232
duration: 1800,
3333
value: value,
3434
easing: Easing.linear,
@@ -37,7 +37,7 @@ export default class Swing extends React.Component<SpinnerProps> {
3737
}),
3838
swingDot: (value) => ({
3939
values: [value],
40-
animation: anim({
40+
animation: loop({
4141
duration: 2000,
4242
value: value,
4343
keyframes: [0, 50, 100],

src/Wander.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react'
22
import { Animated, View } from 'react-native'
33
import { SpinnerProps, defaultProps } from './SpinnerProps'
44
import AnimationContainer from './AnimationContainer'
5-
import { anim } from './utils'
5+
import { loop } from './utils'
66

77
export default class Wander extends React.Component<SpinnerProps> {
88
static defaultProps = defaultProps
@@ -23,7 +23,7 @@ export default class Wander extends React.Component<SpinnerProps> {
2323
initAnimation={() => ({
2424
wander: (value) => ({
2525
values: [value],
26-
animation: anim({
26+
animation: loop({
2727
duration: 2000,
2828
value: value,
2929
keyframes: [0, 25, 50, 75, 100],

src/utils.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EasingFunction, Easing, Animated, Platform } from 'react-native'
22

3-
export function createKeyframeEasingFunction(
3+
function createKeyframeEasingFunction(
44
keyframes: number[],
55
easing: EasingFunction
66
) {
@@ -22,36 +22,32 @@ export function createKeyframeEasingFunction(
2222
}
2323
}
2424

25-
export interface AnimationConfig {
25+
interface AnimationConfig {
2626
duration: number
2727
value: Animated.Value
2828
keyframes?: number[]
2929
toValue?: number
3030
easing?: EasingFunction
31-
infinite?: boolean
32-
delay?: number
3331
}
3432

35-
export function anim({
33+
function loop({
3634
duration,
3735
value,
3836
keyframes = [0, 100],
3937
easing = Easing.bezier(0.42, 0.0, 0.58, 1.0),
4038
toValue = 100,
41-
infinite = true,
42-
delay = 0,
4339
}: AnimationConfig) {
4440
const timing = Animated.timing(value, {
4541
duration: duration,
4642
easing: createKeyframeEasingFunction(keyframes, easing),
4743
toValue: toValue,
4844
useNativeDriver: Platform.OS !== 'web',
49-
delay: delay,
5045
})
51-
return infinite ? Animated.loop(timing) : timing
46+
47+
return Animated.loop(timing)
5248
}
5349

54-
export function stagger(
50+
function stagger(
5551
time: number,
5652
amount: number,
5753
animationConfig: AnimationConfig
@@ -62,8 +58,6 @@ export function stagger(
6258
keyframes = [0, 100],
6359
easing = Easing.bezier(0.42, 0.0, 0.58, 1.0),
6460
toValue = 100,
65-
infinite = true,
66-
delay = 0,
6761
} = animationConfig
6862
const easingFunction = createKeyframeEasingFunction(keyframes, easing)
6963

@@ -73,13 +67,12 @@ export function stagger(
7367
.map((_) => new Animated.Value(0))
7468

7569
const animations = values.map((value) =>
76-
anim({
70+
loop({
7771
value,
7872
duration,
7973
easing,
8074
toValue,
8175
keyframes,
82-
infinite,
8376
})
8477
)
8578

@@ -93,9 +86,9 @@ export function stagger(
9386
easing: easingFunction,
9487
toValue: toValue,
9588
useNativeDriver: true,
96-
delay: delay,
9789
})
98-
const animation = infinite ? Animated.loop(timing) : timing
90+
91+
const animation = Animated.loop(timing)
9992

10093
// React Native only does 60fps
10194
// https://github.com/facebook/react-native/blob/d3980dceab90b118cc7f69696967aa7f8d4388d9/Libraries/Animated/src/animations/TimingAnimation.js#L78
@@ -125,3 +118,5 @@ export function stagger(
125118

126119
return { animation, values }
127120
}
121+
122+
export { loop, stagger, AnimationConfig }

0 commit comments

Comments
 (0)