1
- import { is , raf , flush , eachProp , Timeout } from '@react-spring/shared'
1
+ import {
2
+ is ,
3
+ raf ,
4
+ flush ,
5
+ eachProp ,
6
+ Timeout ,
7
+ Globals as G ,
8
+ } from '@react-spring/shared'
2
9
import { Falsy } from '@react-spring/types'
3
10
4
11
import { getDefaultProps } from './helpers'
@@ -88,8 +95,23 @@ export function runAsync<T extends AnimationTarget>(
88
95
// Create the bail signal outside the returned promise,
89
96
// so the generated stack trace is relevant.
90
97
const bailSignal = new BailSignal ( )
98
+ const skipAnimationSignal = new SkipAniamtionSignal ( )
91
99
92
100
return ( async ( ) => {
101
+ if ( G . skipAnimation ) {
102
+ /**
103
+ * We need to stop animations if `skipAnimation`
104
+ * is set in the Globals
105
+ *
106
+ */
107
+ stopAsync ( state )
108
+
109
+ // create the rejection error that's handled gracefully
110
+ skipAnimationSignal . result = getFinishedResult ( target , false )
111
+ bail ( skipAnimationSignal )
112
+ throw skipAnimationSignal
113
+ }
114
+
93
115
bailIfEnded ( bailSignal )
94
116
95
117
const props : any = is . obj ( arg1 ) ? { ...arg1 } : { ...arg2 , to : arg1 }
@@ -115,6 +137,16 @@ export function runAsync<T extends AnimationTarget>(
115
137
}
116
138
117
139
let result ! : AnimationResult < T >
140
+
141
+ if ( G . skipAnimation ) {
142
+ /**
143
+ * We need to stop animations if `skipAnimation`
144
+ * is set in the Globals
145
+ */
146
+ stopAsync ( state )
147
+ return getFinishedResult ( target , false )
148
+ }
149
+
118
150
try {
119
151
let animating ! : Promise < void >
120
152
@@ -139,6 +171,8 @@ export function runAsync<T extends AnimationTarget>(
139
171
} catch ( err ) {
140
172
if ( err instanceof BailSignal ) {
141
173
result = err . result
174
+ } else if ( err instanceof SkipAniamtionSignal ) {
175
+ result = err . result
142
176
} else {
143
177
throw err
144
178
}
@@ -181,3 +215,11 @@ export class BailSignal extends Error {
181
215
)
182
216
}
183
217
}
218
+
219
+ export class SkipAniamtionSignal extends Error {
220
+ result ! : AnimationResult
221
+
222
+ constructor ( ) {
223
+ super ( 'SkipAnimationSignal' )
224
+ }
225
+ }
0 commit comments