@@ -70,10 +70,6 @@ export type ControllerProps<State extends Indexable = Indexable> = unknown &
7070 SpringUpdate < State > &
7171 UnknownPartial < FluidProps < State > >
7272
73- /** The props that are cached by `Controller` objects */
74- type CachedProps < State extends Indexable > = RunAsyncState < State > &
75- NarrowValues < EventProps < State > , Function >
76-
7773/** An update that hasn't been applied yet */
7874type PendingProps < State extends Indexable > = ControllerProps < State > & {
7975 keys : string [ ]
@@ -90,10 +86,10 @@ export class Controller<State extends Indexable = UnknownProps>
9086 queue : PendingProps < State > [ ] = [ ]
9187
9288 /** Fallback values for undefined props */
93- defaultProps : EventProps < State > = { }
89+ protected _defaultProps : Indexable = { }
9490
9591 /** These props are used by all future spring values */
96- protected _initialProps ?: any
92+ protected _initialProps ?: Indexable
9793
9894 /** The combined phase of our spring values */
9995 protected _phase : SpringPhase = CREATED
@@ -105,7 +101,7 @@ export class Controller<State extends Indexable = UnknownProps>
105101 protected _frame : UnknownPartial < State > = { }
106102
107103 /** Event handlers and async state are stored here */
108- protected _state : CachedProps < State > = { }
104+ protected _state : Indexable & RunAsyncState < State > = { }
109105
110106 /** The spring values that manage their animations */
111107 protected _springs : Indexable < SpringValue > = { }
@@ -201,12 +197,20 @@ export class Controller<State extends Indexable = UnknownProps>
201197 props . onRest = onRest
202198
203199 each ( BATCHED_EVENTS , key => {
204- const value : any = props [ key ] || this . defaultProps [ key ]
205- if ( value && props . default ) {
206- this . defaultProps [ key ] = value
207- }
200+ const value : any = props [ key ]
208201 if ( is . fun ( value ) ) {
209- this . _state [ key ] = value
202+ if ( props . default ) {
203+ this . _defaultProps [ key ] = value
204+ }
205+ // The "onStart" and "onRest" props are reset to their
206+ // default values once called.
207+ this . _state [ key ] =
208+ key == 'onFrame'
209+ ? value
210+ : ( arg ?: any ) => {
211+ this . _state [ key ] = this . _defaultProps [ key ]
212+ value ( arg )
213+ }
210214 }
211215 } )
212216 }
@@ -313,18 +317,23 @@ export class Controller<State extends Indexable = UnknownProps>
313317 this . _phase = isActive ? ACTIVE : IDLE
314318 if ( isActive ) {
315319 if ( onStart ) onStart ( )
316- } else if ( onRest ) {
317- const result = {
318- value : this . _get ( ) ,
319- finished : true ,
320- cancelled : false ,
320+ } else {
321+ // Reset the "onFrame" prop when done animating.
322+ this . _state . onFrame = this . _defaultProps . onFrame
323+
324+ if ( onRest ) {
325+ const result = {
326+ value : this . _get ( ) ,
327+ finished : true ,
328+ cancelled : false ,
329+ }
330+ each ( this . _results , ( { finished, cancelled } ) => {
331+ if ( ! finished ) result . finished = false
332+ if ( cancelled ) result . cancelled = true
333+ } )
334+ this . _results . clear ( )
335+ onRest ( result )
321336 }
322- each ( this . _results , ( { finished, cancelled } ) => {
323- if ( ! finished ) result . finished = false
324- if ( cancelled ) result . cancelled = true
325- } )
326- this . _results . clear ( )
327- onRest ( result )
328337 }
329338 }
330339
0 commit comments