9
9
} from "../styling/style-properties" ;
10
10
11
11
import { layout } from "../../utils/utils" ;
12
+ import { device } from "../../platform" ;
12
13
import lazy from "../../utils/lazy" ;
13
14
14
15
export * from "./animation-common" ;
@@ -92,6 +93,7 @@ export class Animation extends AnimationBase {
92
93
private _propertyResetCallbacks : Array < Function > ;
93
94
private _valueSource : "animation" | "keyframe" ;
94
95
private _target : View ;
96
+ private _resetOnFinish : boolean = true ;
95
97
96
98
constructor ( animationDefinitions : Array < AnimationDefinitionInternal > , playSequentially ?: boolean ) {
97
99
super ( animationDefinitions , playSequentially ) ;
@@ -134,12 +136,18 @@ export class Animation extends AnimationBase {
134
136
} ) ;
135
137
}
136
138
137
- public play ( ) : AnimationPromise {
139
+ public play ( resetOnFinish ?: boolean ) : AnimationPromise {
140
+ if ( resetOnFinish !== undefined ) {
141
+ this . _resetOnFinish = resetOnFinish ;
142
+ }
143
+
138
144
if ( this . isPlaying ) {
139
145
return this . _rejectAlreadyPlaying ( ) ;
140
146
}
141
147
142
- let animationFinishedPromise = super . play ( ) ;
148
+ if ( this . _animatorSet ) {
149
+ return this . _play ( ) ;
150
+ }
143
151
144
152
this . _animators = new Array < android . animation . Animator > ( ) ;
145
153
this . _propertyUpdateCallbacks = new Array < Function > ( ) ;
@@ -156,21 +164,8 @@ export class Animation extends AnimationBase {
156
164
157
165
this . _animatorSet = new android . animation . AnimatorSet ( ) ;
158
166
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
- }
167
167
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 ( ) ;
174
169
}
175
170
176
171
public cancel ( ) : void {
@@ -188,6 +183,33 @@ export class Animation extends AnimationBase {
188
183
return _resolveAnimationCurve ( curve ) ;
189
184
}
190
185
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
+
191
213
private _onAndroidAnimationEnd ( ) { // tslint:disable-line
192
214
if ( ! this . isPlaying ) {
193
215
// It has been cancelled
@@ -197,7 +219,7 @@ export class Animation extends AnimationBase {
197
219
this . _propertyUpdateCallbacks . forEach ( v => v ( ) ) ;
198
220
this . _resolveAnimationFinishedPromise ( ) ;
199
221
200
- if ( this . _target ) {
222
+ if ( this . _resetOnFinish && this . _target ) {
201
223
this . _target . _removeAnimation ( this ) ;
202
224
}
203
225
}
0 commit comments