@@ -81,25 +81,25 @@ struct AnimatedValue<Value: AnimatableVectorConvertible>: ~Copyable {
8181 context: & context
8282 )
8383
84- self . currentAnimationValue = Value ( animationBase + animatedVector)
85-
8684 if let finishedAnimationIndex {
8785 removeAnimations ( upThrough: finishedAnimationIndex)
8886 }
8987
90- #if DEBUG
91- if !isAnimating {
92- assert ( self . currentAnimationValue == self . currentTarget)
93- assert ( self . animationBase == self . currentTarget. animatableVector)
88+ if isAnimating {
89+ self . currentAnimationValue = Value ( animationBase + animatedVector)
90+ } else {
91+ // NOTE: avoid floating point weirdness
92+ self . currentAnimationValue = self . currentTarget
93+ self . animationBase = self . currentTarget. animatableVector
9494 }
95- #endif
9695 }
9796
9897 // TODO: figure out the shape for this
9998 func peekFutureValues( _ times: StrideThrough < Double > ) -> [ Value ] {
10099 var results : [ Value ] = [ ]
101100 var contextCopy = context
102101 var runningAnimations = runningAnimations [ ... ]
102+ var base = animationBase
103103
104104 results. reserveCapacity ( times. underestimatedCount)
105105
@@ -110,12 +110,19 @@ struct AnimatedValue<Value: AnimatableVectorConvertible>: ~Copyable {
110110 context: & contextCopy
111111 )
112112
113- results. append ( Value ( self . animationBase + animatedVector) )
114-
115113 if let completedIndex {
116- //TODO: update base
114+ for i in runningAnimations. startIndex... completedIndex {
115+ base += runningAnimations [ i] . target
116+ }
117117 runningAnimations = runningAnimations [ ( completedIndex + 1 ) ... ]
118118 }
119+
120+ if runningAnimations. isEmpty {
121+ results. append ( self . currentTarget)
122+ break
123+ }
124+
125+ results. append ( Value ( base + animatedVector) )
119126 }
120127 return results
121128 }
@@ -138,6 +145,7 @@ private func calculateAnimationAtTime<AnimationList>(
138145) -> ( animatedVector: AnimatableVector , finishedAnimationIndex: AnimationList . Index ? )
139146where AnimationList: Collection < RunningAnimation > {
140147 guard runningAnimations. count > 1 else {
148+ assert ( runningAnimations. first != nil , " Running animations should not be empty " )
141149 if let vector = runningAnimations. first!. animate ( time: time, context: & context, additionalVector: nil ) {
142150 return ( vector, nil )
143151 } else {
@@ -161,7 +169,7 @@ where AnimationList: Collection<RunningAnimation> {
161169 carryOverVector = runningAnimation. target - vector
162170 } else {
163171 finishedAnimationIndex = index
164- totalAnimationVector += runningAnimation . target
172+ // totalAnimationVector = zero
165173 carryOverVector = zero
166174 }
167175
@@ -170,3 +178,17 @@ where AnimationList: Collection<RunningAnimation> {
170178
171179 return ( totalAnimationVector, finishedAnimationIndex)
172180}
181+
182+ internal extension AnimatedValue {
183+ mutating func setValueAndReturnIfAnimationWasStarted( _ value: Value , context: borrowing _RenderContext ) -> Bool {
184+ let wasAnimating = isAnimating
185+
186+ if let animation = context. transaction? . animation {
187+ self . animate ( to: value, animation: AnimationInstance ( startTime: context. currentFrameTime, animation: animation) )
188+ } else {
189+ self . setValue ( value)
190+ }
191+
192+ return isAnimating && !wasAnimating
193+ }
194+ }
0 commit comments