11import { CubicBezierAnimationCurve , Pair } from "@nativescript/core/ui/animation" ;
2- import { CoreTypes } from "@nativescript/core" ;
2+ import { CoreTypes , Trace } from "@nativescript/core" ;
33import { Animation , AnimationDefinition , Color , View } from "@nativescript/core" ;
44
55import { ease_in , ease_out , ease , linear , ease_in_out , animation_curve , normalizeCurve , partialCurveFrom , reverseCurve , CubicBezier } from "./bezier"
@@ -142,7 +142,11 @@ export function asSvelteTransition(node: NativeViewElementNode<View>, delay: num
142142 if ( ! animation ) {
143143 //create a new animation that will cover us from now to either t=duration or t=0
144144 let target_t = ( direction == AnimationDirection . In ) ? 1 : 0 ;
145- let animProps = nativeAnimationProps ( target_t )
145+ if ( ! node . nativeView . nativeViewProtected ) {
146+ applyAnimAtTime ( target_t ) ;
147+ return ;
148+ }
149+ let animProps = nativeAnimationProps ( target_t ) ;
146150 let nsAnimation : AnimationDefinition = { ...animProps }
147151 nsAnimation . delay = 0 ;
148152 if ( direction == AnimationDirection . Out ) {
@@ -161,11 +165,25 @@ export function asSvelteTransition(node: NativeViewElementNode<View>, delay: num
161165 //console.log("animation created", t, (direction == AnimationDirection.In) ? "Intro" : "Outro", nsAnimation, node);
162166 // kick it off
163167 animation = node . nativeView . createAnimation ( nsAnimation ) ;
164- //we use setTimeout to ensure transition works if triggered
165- //with a suspend animation block like CollectionView item update
166- setTimeout ( ( ) => {
167- animation . play ( ) ;
168- } , 0 ) ;
168+ function animateBlock ( ) {
169+ try {
170+ animation . play ( ) ;
171+ } catch ( error ) {
172+ if ( Trace . isEnabled ( ) ) {
173+ Trace . error ( error ) ;
174+ }
175+ }
176+ }
177+ if ( direction == AnimationDirection . Out ) {
178+ animateBlock ( ) ;
179+ } else {
180+ //we use setTimeout to ensure transition works if triggered
181+ //with a suspend animation block like CollectionView item update
182+ //we dont do it in out or view might already be unloaded
183+ setTimeout ( ( ) => {
184+ animateBlock ( ) ;
185+ } , 0 ) ;
186+ }
169187 }
170188 }
171189
0 commit comments