Skip to content

Commit 0579928

Browse files
committed
Pass animation object directly to animation container
1 parent 4237d52 commit 0579928

File tree

13 files changed

+122
-142
lines changed

13 files changed

+122
-142
lines changed

src/AnimationContainer.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

44
export interface Props {
5-
animation: () => Animated.CompositeAnimation
5+
animation: Animated.CompositeAnimation
66
}
77
export default class AnimationContainer extends React.Component<Props> {
88
animation: Animated.CompositeAnimation
@@ -11,7 +11,7 @@ export default class AnimationContainer extends React.Component<Props> {
1111
super(props)
1212

1313
const { animation } = this.props
14-
this.animation = animation()
14+
this.animation = animation
1515
}
1616

1717
componentDidMount() {

src/Bounce.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@ export default class Bounce extends React.Component<SpinnerProps> {
2020
}
2121
return (
2222
<AnimationContainer
23-
animation={() =>
24-
Animated.stagger(
25-
1000,
26-
this.values.map(value =>
27-
anim({
28-
duration: 2000,
29-
value: value,
30-
keyframes: [0, 45, 55, 100],
31-
})
32-
)
23+
animation={Animated.stagger(
24+
1000,
25+
this.values.map(value =>
26+
anim({
27+
duration: 2000,
28+
value: value,
29+
keyframes: [0, 45, 55, 100],
30+
})
3331
)
34-
}
32+
)}
3533
>
3634
<View style={[{ width: size, height: size }, style]} {...rest}>
3735
{this.values.map((value, index) => (

src/Chase.tsx

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,33 @@ export default class Chase extends React.Component<SpinnerProps> {
2121
}
2222
return (
2323
<AnimationContainer
24-
animation={() =>
25-
Animated.parallel([
26-
Animated.stagger(
27-
100,
28-
this.chaseDotValues.map(value =>
29-
anim({
30-
duration: 2000,
31-
value: value,
32-
keyframes: [0, 80, 100],
33-
})
34-
)
35-
),
36-
Animated.stagger(
37-
100,
38-
this.chaseDotBeforeValues.map(value =>
39-
anim({
40-
duration: 2000,
41-
value: value,
42-
keyframes: [0, 50, 100],
43-
})
44-
)
45-
),
46-
anim({
47-
duration: 2500,
48-
easing: Easing.linear,
49-
value: this.chase,
50-
}),
51-
])
52-
}
24+
animation={Animated.parallel([
25+
Animated.stagger(
26+
100,
27+
this.chaseDotValues.map(value =>
28+
anim({
29+
duration: 2000,
30+
value: value,
31+
keyframes: [0, 80, 100],
32+
})
33+
)
34+
),
35+
Animated.stagger(
36+
100,
37+
this.chaseDotBeforeValues.map(value =>
38+
anim({
39+
duration: 2000,
40+
value: value,
41+
keyframes: [0, 50, 100],
42+
})
43+
)
44+
),
45+
anim({
46+
duration: 2500,
47+
easing: Easing.linear,
48+
value: this.chase,
49+
}),
50+
])}
5351
>
5452
<Animated.View
5553
style={[

src/Circle.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,16 @@ export default class Circle extends React.Component<SpinnerProps> {
1919
}
2020
return (
2121
<AnimationContainer
22-
animation={() =>
23-
Animated.stagger(
24-
100,
25-
this.values.map(value =>
26-
anim({
27-
duration: 1200,
28-
value: value,
29-
keyframes: [0, 40, 80, 100],
30-
})
31-
)
22+
animation={Animated.stagger(
23+
100,
24+
this.values.map(value =>
25+
anim({
26+
duration: 1200,
27+
value: value,
28+
keyframes: [0, 40, 80, 100],
29+
})
3230
)
33-
}
31+
)}
3432
>
3533
<View
3634
style={[

src/CircleFade.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,16 @@ export default class CircleFade extends React.Component<SpinnerProps> {
1919
}
2020
return (
2121
<AnimationContainer
22-
animation={() =>
23-
Animated.stagger(
24-
100,
25-
this.values.map(value =>
26-
anim({
27-
duration: 1200,
28-
value: value,
29-
keyframes: [0, 39, 40, 100],
30-
})
31-
)
22+
animation={Animated.stagger(
23+
100,
24+
this.values.map(value =>
25+
anim({
26+
duration: 1200,
27+
value: value,
28+
keyframes: [0, 39, 40, 100],
29+
})
3230
)
33-
}
31+
)}
3432
>
3533
<View
3634
style={[

src/Flow.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,17 @@ export default class Flow extends React.Component<SpinnerProps> {
1313

1414
return (
1515
<AnimationContainer
16-
animation={() =>
17-
Animated.stagger(
18-
150,
19-
this.values.map(value =>
20-
anim({
21-
duration: 1400,
22-
value: value,
23-
easing: Easing.bezier(0.455, 0.03, 0.515, 0.955),
24-
keyframes: [0, 40, 80, 100],
25-
})
26-
)
16+
animation={Animated.stagger(
17+
150,
18+
this.values.map(value =>
19+
anim({
20+
duration: 1400,
21+
value: value,
22+
easing: Easing.bezier(0.455, 0.03, 0.515, 0.955),
23+
keyframes: [0, 40, 80, 100],
24+
})
2725
)
28-
}
26+
)}
2927
>
3028
<View
3129
style={[

src/Fold.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,17 @@ export default class Fold extends React.Component<SpinnerProps> {
1212
const { size, color, style, ...rest } = this.props
1313
return (
1414
<AnimationContainer
15-
animation={() =>
16-
Animated.parallel(
17-
this.values.map((value, index) =>
18-
anim({
19-
duration: 2400,
20-
value: value,
21-
keyframes: [0, 10, 25, 75, 90, 100],
22-
delay: index * 300,
23-
easing: Easing.linear,
24-
})
25-
)
15+
animation={Animated.parallel(
16+
this.values.map((value, index) =>
17+
anim({
18+
duration: 2400,
19+
value: value,
20+
keyframes: [0, 10, 25, 75, 90, 100],
21+
delay: index * 300,
22+
easing: Easing.linear,
23+
})
2624
)
27-
}
25+
)}
2826
>
2927
<View
3028
style={[

src/Grid.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ export default class Grid extends React.Component<SpinnerProps> {
1313
const { size, color, style, ...rest } = this.props
1414
return (
1515
<AnimationContainer
16-
animation={() =>
17-
Animated.parallel(
18-
this.values.map((value, index) =>
19-
anim({
20-
duration: 1300,
21-
value: value,
22-
keyframes: [0, 35, 70, 100],
23-
delay: delays[index],
24-
})
25-
)
16+
animation={Animated.parallel(
17+
this.values.map((value, index) =>
18+
anim({
19+
duration: 1300,
20+
value: value,
21+
keyframes: [0, 35, 70, 100],
22+
delay: delays[index],
23+
})
2624
)
27-
}
25+
)}
2826
>
2927
<View
3028
style={[

src/Plane.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ export default class Plane extends React.Component<SpinnerProps> {
1212
const { size, color, style, ...rest } = this.props
1313
return (
1414
<AnimationContainer
15-
animation={() =>
16-
anim({ duration: 1200, value: this.value, keyframes: [0, 50, 100] })
17-
}
15+
animation={anim({
16+
duration: 1200,
17+
value: this.value,
18+
keyframes: [0, 50, 100],
19+
})}
1820
>
1921
<Animated.View
2022
style={[

src/Pulse.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ export default class Pulse extends React.Component<SpinnerProps> {
1212
const { size, color, style, ...rest } = this.props
1313
return (
1414
<AnimationContainer
15-
animation={() =>
16-
anim({
17-
duration: 1200,
18-
value: this.value,
19-
easing: Easing.bezier(0.455, 0.03, 0.515, 0.955),
20-
})
21-
}
15+
animation={anim({
16+
duration: 1200,
17+
value: this.value,
18+
easing: Easing.bezier(0.455, 0.03, 0.515, 0.955),
19+
})}
2220
>
2321
<Animated.View
2422
style={[

0 commit comments

Comments
 (0)