Skip to content

Commit 87b0f8f

Browse files
committed
fix(android): shared element with the target name already added to the transaction
1 parent adb5933 commit 87b0f8f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/core/ui/transition/page-transition.android.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,22 @@ export class PageTransition extends Transition {
262262
newFragment.setSharedElementEnterTransition(transitionSet);
263263
newFragment.setSharedElementReturnTransition(transitionSet);
264264

265+
// Guard against duplicate shared element names being added to the same transaction
266+
const addedSharedElementNames = new Set();
265267
presenting.forEach((v) => {
268+
const name = v?.sharedTransitionTag;
269+
const nativeView = v?.nativeView;
270+
if (!name || !nativeView || addedSharedElementNames.has(name)) {
271+
// prevent duplicates or invalid items
272+
return;
273+
}
266274
setTransitionName(v);
267-
fragmentTransaction.addSharedElement(v.nativeView, v.sharedTransitionTag);
275+
try {
276+
fragmentTransaction.addSharedElement(nativeView, name);
277+
addedSharedElementNames.add(name);
278+
} catch (err) {
279+
// ignore duplicates or issues adding shared element to avoid crashing
280+
}
268281
});
269282
if (toPage.isLoaded) {
270283
onPageLoaded();

0 commit comments

Comments
 (0)