Skip to content

Commit 9f715c0

Browse files
authored
feat(shared-transition): pageOut option for more dynamic page animations (#10350)
1 parent b93cb99 commit 9f715c0

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

packages/core/ui/transition/shared-transition-helper.ios.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class SharedTransitionHelper {
5050
console.log(`2. Take snapshots of shared elements and position them based on presenting view:`);
5151
}
5252

53+
const pageOut = state.pageOut;
5354
const pageStart = state.pageStart;
5455

5556
const startFrame = getRectFromProps(pageStart, getPageStartDefaultsForType(type));
@@ -273,6 +274,14 @@ export class SharedTransitionHelper {
273274
const endFrame = getRectFromProps(pageEnd);
274275
transition.presented.view.frame = CGRectMake(endFrame.x, endFrame.y, endFrame.width, endFrame.height);
275276

277+
if (pageOut) {
278+
if (isNumber(pageOut.opacity)) {
279+
transition.presenting.view.alpha = pageOut?.opacity;
280+
}
281+
282+
const outFrame = getRectFromProps(pageOut);
283+
transition.presenting.view.frame = CGRectMake(outFrame.x, outFrame.y, outFrame.width, outFrame.height);
284+
}
276285
// animate page properties to the following:
277286
// https://stackoverflow.com/a/27997678/1418981
278287
// In order to have proper layout. Seems mostly needed when presenting.
@@ -368,6 +377,7 @@ export class SharedTransitionHelper {
368377
console.log(`2. Add back previously stored sharedElements to dismiss:`);
369378
}
370379

380+
const pageOut = state.pageOut;
371381
const pageEnd = state.pageEnd;
372382
const pageEndTags = pageEnd?.sharedTransitionTags || {};
373383
const pageReturn = state.pageReturn;
@@ -457,6 +467,14 @@ export class SharedTransitionHelper {
457467
const endFrame = getRectFromProps(pageReturn, getPageStartDefaultsForType(type));
458468
transition.presented.view.frame = CGRectMake(endFrame.x, endFrame.y, endFrame.width, endFrame.height);
459469

470+
if (pageOut) {
471+
// always return to defaults if pageOut had been used
472+
transition.presenting.view.alpha = 1;
473+
474+
const outFrame = getRectFromProps(null);
475+
transition.presenting.view.frame = CGRectMake(0, 0, outFrame.width, outFrame.height);
476+
}
477+
460478
for (const presenting of transition.sharedElements.presenting) {
461479
iOSUtils.copyLayerProperties(presenting.snapshot, presenting.view.ios, presenting.propertiesToMatch as any);
462480
presenting.snapshot.frame = presenting.startFrame;

packages/core/ui/transition/shared-transition.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,17 @@ export interface SharedTransitionConfig {
104104
dismiss?: SharedTransitionInteractiveOptions;
105105
};
106106
/**
107-
* View settings to start your transition with.
107+
* View settings applied to the incoming page to start your transition with.
108108
*/
109109
pageStart?: SharedTransitionPageProperties;
110110
/**
111-
* View settings to end your transition with.
111+
* View settings applied to the incoming page to end your transition with.
112112
*/
113113
pageEnd?: SharedTransitionPageWithDurationProperties;
114+
/**
115+
* View settings applied to the outgoing page in your transition.
116+
*/
117+
pageOut?: SharedTransitionPageWithDurationProperties;
114118
/**
115119
* View settings to return to the original page with.
116120
*/

0 commit comments

Comments
 (0)