99} from "../styling/style-properties" ;
1010
1111import { layout } from "../../utils/utils" ;
12+ import { device } from "../../platform" ;
1213import lazy from "../../utils/lazy" ;
1314
1415export * from "./animation-common" ;
@@ -92,6 +93,7 @@ export class Animation extends AnimationBase {
9293 private _propertyResetCallbacks : Array < Function > ;
9394 private _valueSource : "animation" | "keyframe" ;
9495 private _target : View ;
96+ private _resetOnFinish : boolean = true ;
9597
9698 constructor ( animationDefinitions : Array < AnimationDefinitionInternal > , playSequentially ?: boolean ) {
9799 super ( animationDefinitions , playSequentially ) ;
@@ -134,12 +136,18 @@ export class Animation extends AnimationBase {
134136 } ) ;
135137 }
136138
137- public play ( ) : AnimationPromise {
139+ public play ( resetOnFinish ?: boolean ) : AnimationPromise {
140+ if ( resetOnFinish !== undefined ) {
141+ this . _resetOnFinish = resetOnFinish ;
142+ }
143+
138144 if ( this . isPlaying ) {
139145 return this . _rejectAlreadyPlaying ( ) ;
140146 }
141147
142- let animationFinishedPromise = super . play ( ) ;
148+ if ( this . _animatorSet ) {
149+ return this . _play ( ) ;
150+ }
143151
144152 this . _animators = new Array < android . animation . Animator > ( ) ;
145153 this . _propertyUpdateCallbacks = new Array < Function > ( ) ;
@@ -156,21 +164,8 @@ export class Animation extends AnimationBase {
156164
157165 this . _animatorSet = new android . animation . AnimatorSet ( ) ;
158166 this . _animatorSet . addListener ( this . _animatorListener ) ;
159- if ( this . _animators . length > 0 ) {
160- if ( this . _playSequentially ) {
161- this . _animatorSet . playSequentially ( this . _nativeAnimatorsArray ) ;
162- }
163- else {
164- this . _animatorSet . playTogether ( this . _nativeAnimatorsArray ) ;
165- }
166- }
167167
168- if ( traceEnabled ( ) ) {
169- traceWrite ( "Starting " + this . _nativeAnimatorsArray . length + " animations " + ( this . _playSequentially ? "sequentially." : "together." ) , traceCategories . Animation ) ;
170- }
171- this . _animatorSet . setupStartValues ( ) ;
172- this . _animatorSet . start ( ) ;
173- return animationFinishedPromise ;
168+ return this . _play ( ) ;
174169 }
175170
176171 public cancel ( ) : void {
@@ -188,6 +183,33 @@ export class Animation extends AnimationBase {
188183 return _resolveAnimationCurve ( curve ) ;
189184 }
190185
186+ private _play ( ) : AnimationPromise {
187+ const animationFinishedPromise = super . play ( ) ;
188+
189+ if ( device . sdkVersion <= "23" ) {
190+ this . _animatorSet = new android . animation . AnimatorSet ( ) ;
191+ this . _animatorSet . addListener ( this . _animatorListener ) ;
192+ }
193+
194+ if ( this . _animators . length > 0 ) {
195+ if ( this . _playSequentially ) {
196+ this . _animatorSet . playSequentially ( this . _nativeAnimatorsArray ) ;
197+ }
198+ else {
199+ this . _animatorSet . playTogether ( this . _nativeAnimatorsArray ) ;
200+ }
201+ }
202+
203+ if ( traceEnabled ( ) ) {
204+ traceWrite ( "Starting " + this . _nativeAnimatorsArray . length + " animations " + ( this . _playSequentially ? "sequentially." : "together." ) , traceCategories . Animation ) ;
205+ }
206+
207+ this . _animatorSet . setupStartValues ( ) ;
208+ this . _animatorSet . start ( ) ;
209+
210+ return animationFinishedPromise ;
211+ }
212+
191213 private _onAndroidAnimationEnd ( ) { // tslint:disable-line
192214 if ( ! this . isPlaying ) {
193215 // It has been cancelled
@@ -197,7 +219,7 @@ export class Animation extends AnimationBase {
197219 this . _propertyUpdateCallbacks . forEach ( v => v ( ) ) ;
198220 this . _resolveAnimationFinishedPromise ( ) ;
199221
200- if ( this . _target ) {
222+ if ( this . _resetOnFinish && this . _target ) {
201223 this . _target . _removeAnimation ( this ) ;
202224 }
203225 }
0 commit comments