Skip to content

Commit 0208040

Browse files
chenesanaleclarson
authored andcommitted
feat: add pause and resume in useSpring/useTransitions ref api
1 parent a7e2c6e commit 0208040

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

packages/core/src/types/spring.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,30 @@ export type SpringStopFn<T> = T extends object
176176
: (keys?: OneOrMore<string>) => void
177177
: () => void
178178

179+
/**
180+
* Pause animating `SpringValue`.
181+
*
182+
* The `T` parameter can be a set of animated values (as an object type)
183+
* or a primitive type for a single animated value.
184+
*/
185+
export type SpringPauseFn<T> = T extends object
186+
? T extends ReadonlyArray<number | string>
187+
? () => void
188+
: (keys?: OneOrMore<string>) => void
189+
: () => void
190+
191+
/**
192+
* Resume paused `SpringValue`.
193+
*
194+
* The `T` parameter can be a set of animated values (as an object type)
195+
* or a primitive type for a single animated value.
196+
*/
197+
export type SpringResumeFn<T> = T extends object
198+
? T extends ReadonlyArray<number | string>
199+
? () => void
200+
: (keys?: OneOrMore<string>) => void
201+
: () => void
202+
179203
/**
180204
* Update the props of each spring, individually or all at once.
181205
*
@@ -202,6 +226,8 @@ export interface SpringHandle<T extends Indexable = any> {
202226
update: SpringsUpdateFn<T>
203227
start: () => AsyncResult<T[]>
204228
stop: SpringStopFn<T>
229+
pause: SpringPauseFn<T>
230+
resume: SpringResumeFn<T>
205231
}
206232

207233
export type SpringConfig = Partial<Omit<AnimationConfig, 'w0'>>

packages/core/src/useSprings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ export function useSprings(
131131
}
132132
},
133133
stop: keys => each(ctrls, ctrl => ctrl.stop(keys)),
134+
pause: keys => each(ctrls, ctrl => ctrl.pause(keys)),
135+
resume: keys => each(ctrls, ctrl => ctrl.resume(keys)),
134136
}),
135137
[]
136138
)

packages/core/src/useTransition.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ export function useTransition(
312312
}
313313
},
314314
stop: keys => each(usedTransitions.current!, t => t.ctrl.stop(keys)),
315+
pause: keys => each(usedTransitions.current!, t => t.ctrl.pause(keys)),
316+
resume: keys => each(usedTransitions.current!, t => t.ctrl.resume(keys)),
315317
}),
316318
[]
317319
)

0 commit comments

Comments
 (0)