@@ -77,7 +77,7 @@ function setTransitionName(view: ViewBase) {
77
77
}
78
78
79
79
export class PageTransition extends Transition {
80
- constructor ( duration ?: number , curve ?: any ) {
80
+ constructor ( duration ?: number , curve ?: any , private pageLoadedTimeout : number = 0 ) {
81
81
// disable custom curves until we can fix the issue with the animation not completing
82
82
if ( curve ) {
83
83
console . warn ( 'PageTransition does not support custom curves at the moment. The passed in curve will be ignored.' ) ;
@@ -178,12 +178,10 @@ export class PageTransition extends Transition {
178
178
const state = SharedTransition . getState ( this . id ) ;
179
179
const pageEnd = state . pageEnd ;
180
180
181
- const { sharedElements, presented, presenting } = SharedTransition . getSharedElements ( fromPage , toPage ) ;
182
- const sharedElementTags = sharedElements . map ( ( v ) => v . sharedTransitionTag ) ;
183
- if ( SharedTransition . DEBUG ) {
184
- console . log ( ` Page: ${ state . activeType === SharedTransitionAnimationType . present ? 'Present' : 'Dismiss' } ` ) ;
185
- console . log ( `1. Found sharedTransitionTags to animate:` , sharedElementTags ) ;
186
- }
181
+ //we can't look for presented right now as the toPage might not be loaded
182
+ // and thus some views like ListView/Pager... might not have loaded their "children"
183
+ // presented will be handled in loaded event of toPage
184
+ const { presenting } = SharedTransition . getSharedElements ( fromPage , toPage ) ;
187
185
188
186
// Note: we can enhance android more over time with element targeting across different screens
189
187
// const pageStart = state.pageStart;
@@ -215,16 +213,15 @@ export class PageTransition extends Transition {
215
213
// independentView.opacity = 0;
216
214
// }
217
215
// }
218
-
219
- toPage . once ( 'loaded' , ( ) => {
220
- presented . filter ( ( v ) => sharedElementTags . includes ( v . sharedTransitionTag ) ) . forEach ( setTransitionName ) ;
221
- newFragment . startPostponedEnterTransition ( ) ;
222
- } ) ;
223
-
224
- sharedElements . forEach ( ( v ) => {
225
- setTransitionName ( v ) ;
226
- fragmentTransaction . addSharedElement ( v . nativeView , v . sharedTransitionTag ) ;
227
- } ) ;
216
+ const onPageLoaded = ( ) => {
217
+ // add a timeout so that Views like ListView / CollectionView can have their children instantiated
218
+ setTimeout ( ( ) => {
219
+ const { presented } = SharedTransition . getSharedElements ( fromPage , toPage ) ;
220
+ // const sharedElementTags = sharedElements.map((v) => v.sharedTransitionTag);
221
+ presented . forEach ( setTransitionName ) ;
222
+ newFragment . startPostponedEnterTransition ( ) ;
223
+ } , this . pageLoadedTimeout ) ;
224
+ } ;
228
225
229
226
fragmentTransaction . setReorderingAllowed ( true ) ;
230
227
@@ -252,6 +249,16 @@ export class PageTransition extends Transition {
252
249
newFragment . postponeEnterTransition ( ) ;
253
250
newFragment . setSharedElementEnterTransition ( transitionSet ) ;
254
251
newFragment . setSharedElementReturnTransition ( transitionSet ) ;
252
+
253
+ presenting . forEach ( ( v ) => {
254
+ setTransitionName ( v ) ;
255
+ fragmentTransaction . addSharedElement ( v . nativeView , v . sharedTransitionTag ) ;
256
+ } ) ;
257
+ if ( toPage . isLoaded ) {
258
+ onPageLoaded ( ) ;
259
+ } else {
260
+ toPage . once ( 'loaded' , onPageLoaded ) ;
261
+ }
255
262
}
256
263
}
257
264
0 commit comments