File tree 4 files changed +17
-19
lines changed
4 files changed +17
-19
lines changed Original file line number Diff line number Diff line change @@ -81,21 +81,22 @@ export const createHandle = () => {
81
81
if ( ! animation ) return ;
82
82
animation . pause ( ) ;
83
83
} ,
84
- _commit : (
84
+ _persist : (
85
85
animation : Animation | undefined ,
86
86
el : HTMLElement ,
87
87
keyframes : TypedKeyframe [ ]
88
88
) => {
89
89
if ( ! animation ) return ;
90
90
if ( animation . commitStyles ) {
91
91
animation . commitStyles ( ) ;
92
- return ;
92
+ } else {
93
+ // Fallback for commitStyles
94
+ const computedStyle = getComputedStyle ( el ) ;
95
+ getKeyframeKeys ( keyframes ) . forEach ( ( k ) => {
96
+ ( el . style as any ) [ k ] = ( computedStyle as any ) [ k ] ;
97
+ } ) ;
93
98
}
94
- // Fallback for commitStyles
95
- const computedStyle = getComputedStyle ( el ) ;
96
- getKeyframeKeys ( keyframes ) . forEach ( ( k ) => {
97
- ( el . style as any ) [ k ] = ( computedStyle as any ) [ k ] ;
98
- } ) ;
99
+ animation . cancel ( ) ;
99
100
} ,
100
101
_setTime : ( animation : Animation | undefined , time : number ) => {
101
102
if ( ! animation ) return ;
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export type AnimationHandle = {
14
14
cancel : ( ) => AnimationHandle ;
15
15
finish : ( ) => AnimationHandle ;
16
16
pause : ( ) => AnimationHandle ;
17
- commit : ( ) => AnimationHandle ;
17
+ persist : ( ) => AnimationHandle ;
18
18
setTime : ( time : number ) => AnimationHandle ;
19
19
setPlaybackRate : (
20
20
rate : number | ( ( prevRate : number ) => number )
@@ -90,8 +90,8 @@ export const useAnimation = (
90
90
handle . _pause ( getAnimation ( ) ) ;
91
91
return externalHandle ;
92
92
} ,
93
- commit : ( ) => {
94
- handle . _commit ( getAnimation ( ) , getTarget ( ) ! , getKeyframes ( ) ) ;
93
+ persist : ( ) => {
94
+ handle . _persist ( getAnimation ( ) , getTarget ( ) ! , getKeyframes ( ) ) ;
95
95
return externalHandle ;
96
96
} ,
97
97
setTime : ( time ) => {
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ export type AnimationsHandle<ID extends string> = {
15
15
cancel : ( name : ID ) => AnimationsHandle < ID > ;
16
16
finish : ( name : ID ) => AnimationsHandle < ID > ;
17
17
pause : ( name : ID ) => AnimationsHandle < ID > ;
18
- commit : ( name : ID ) => AnimationsHandle < ID > ;
18
+ persist : ( name : ID ) => AnimationsHandle < ID > ;
19
19
setTime : ( name : ID , time : number ) => AnimationsHandle < ID > ;
20
20
setPlaybackRate : (
21
21
name : ID ,
@@ -97,8 +97,8 @@ export const useAnimations = <ID extends string>(
97
97
handle . _pause ( getAnimation ( name ) ) ;
98
98
return externalHandle ;
99
99
} ,
100
- commit : ( name ) => {
101
- handle . _commit (
100
+ persist : ( name ) => {
101
+ handle . _persist (
102
102
getAnimation ( name ) ,
103
103
getTarget ( ) ! ,
104
104
toArray ( getKeyframesAndOptions ( name ) [ 0 ] )
Original file line number Diff line number Diff line change @@ -231,27 +231,24 @@ export const Sequence: StoryObj = {
231
231
} ) ;
232
232
233
233
const onClickRed = useCallback ( async ( ) => {
234
- animate . cancelAll ( ) ;
235
234
try {
236
235
await animate . play ( "red" ) . end ( "red" ) ;
237
236
} finally {
238
- animate . commit ( "red" ) ;
237
+ animate . persist ( "red" ) ;
239
238
}
240
239
} , [ ] ) ;
241
240
const onClickBlue = useCallback ( async ( ) => {
242
- animate . cancelAll ( ) ;
243
241
try {
244
242
await animate . play ( "blue" ) . end ( "blue" ) ;
245
243
} finally {
246
- animate . commit ( "blue" ) ;
244
+ animate . persist ( "blue" ) ;
247
245
}
248
246
} , [ ] ) ;
249
247
const onClickGreen = useCallback ( async ( ) => {
250
- animate . cancelAll ( ) ;
251
248
try {
252
249
await animate . play ( "green" ) . end ( "green" ) ;
253
250
} finally {
254
- animate . commit ( "green" ) ;
251
+ animate . persist ( "green" ) ;
255
252
}
256
253
} , [ ] ) ;
257
254
const onClickAll = useCallback ( async ( ) => {
You can’t perform that action at this time.
0 commit comments