@@ -87,6 +87,8 @@ const {
8787 onChange,
8888 set,
8989 spring,
90+ // @ts -ignore
91+ proc,
9092 sub,
9193 timing,
9294 startClock,
@@ -96,6 +98,79 @@ const {
9698 Value,
9799} = Animated ;
98100
101+ const springHelper = proc (
102+ (
103+ finished : Animated . Value < number > ,
104+ velocity : Animated . Value < number > ,
105+ position : Animated . Value < number > ,
106+ time : Animated . Value < number > ,
107+ prevPosition : Animated . Value < number > ,
108+ toValue : Animated . Adaptable < number > ,
109+ damping : Animated . Adaptable < number > ,
110+ mass : Animated . Adaptable < number > ,
111+ stiffness : Animated . Adaptable < number > ,
112+ overshootClamping : Animated . Adaptable < number > ,
113+ restSpeedThreshold : Animated . Adaptable < number > ,
114+ restDisplacementThreshold : Animated . Adaptable < number > ,
115+ clock : Animated . Clock
116+ ) =>
117+ spring (
118+ clock ,
119+ {
120+ finished,
121+ velocity,
122+ position,
123+ time,
124+ // @ts -ignore
125+ prevPosition,
126+ } ,
127+ {
128+ toValue,
129+ damping,
130+ mass,
131+ stiffness,
132+ overshootClamping,
133+ restDisplacementThreshold,
134+ restSpeedThreshold,
135+ }
136+ )
137+ ) ;
138+
139+ function memoizedSpring (
140+ clock : Animated . Clock ,
141+ state : {
142+ finished : Animated . Value < number > ;
143+ velocity : Animated . Value < number > ;
144+ position : Animated . Value < number > ;
145+ time : Animated . Value < number > ;
146+ } ,
147+ config : {
148+ toValue : Animated . Adaptable < number > ;
149+ damping : Animated . Adaptable < number > ;
150+ mass : Animated . Adaptable < number > ;
151+ stiffness : Animated . Adaptable < number > ;
152+ overshootClamping : Animated . Adaptable < boolean > ;
153+ restSpeedThreshold : Animated . Adaptable < number > ;
154+ restDisplacementThreshold : Animated . Adaptable < number > ;
155+ }
156+ ) {
157+ return springHelper (
158+ state . finished ,
159+ state . velocity ,
160+ state . position ,
161+ state . time ,
162+ new Value ( 0 ) ,
163+ config . toValue ,
164+ config . damping ,
165+ config . mass ,
166+ config . stiffness ,
167+ config . overshootClamping ,
168+ config . restSpeedThreshold ,
169+ config . restDisplacementThreshold ,
170+ clock
171+ ) ;
172+ }
173+
99174export default class Card extends React . Component < Props > {
100175 static defaultProps = {
101176 overlayEnabled : Platform . OS !== 'ios' ,
@@ -216,7 +291,7 @@ export default class Card extends React.Component<Props> {
216291 cond (
217292 eq ( isVisible , 1 ) ,
218293 openingSpec . timing === 'spring'
219- ? spring (
294+ ? memoizedSpring (
220295 this . clock ,
221296 { ...this . transitionState , velocity : this . transitionVelocity } ,
222297 { ...openingSpec . config , toValue : this . toValue }
@@ -227,7 +302,7 @@ export default class Card extends React.Component<Props> {
227302 { ...openingSpec . config , toValue : this . toValue }
228303 ) ,
229304 closingSpec . timing === 'spring'
230- ? spring (
305+ ? memoizedSpring (
231306 this . clock ,
232307 { ...this . transitionState , velocity : this . transitionVelocity } ,
233308 { ...closingSpec . config , toValue : this . toValue }
0 commit comments