Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions fixtures/view-transition/src/components/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ export default function Page({url, navigate}) {
{rotate: '0deg', transformOrigin: '30px 8px'},
{rotate: '360deg', transformOrigin: '30px 8px'},
];
viewTransition.old.animate(keyframes, 250);
viewTransition.new.animate(keyframes, 250);
const animation1 = viewTransition.old.animate(keyframes, 250);
const animation2 = viewTransition.new.animate(keyframes, 250);
return () => {
animation1.cancel();
animation2.cancel();
};
}

function onGestureTransition(
Expand All @@ -105,8 +109,12 @@ export default function Page({url, navigate}) {
rangeStart: (reverse ? rangeEnd : rangeStart) + '%',
rangeEnd: (reverse ? rangeStart : rangeEnd) + '%',
};
viewTransition.old.animate(keyframes, options);
viewTransition.new.animate(keyframes, options);
const animation1 = viewTransition.old.animate(keyframes, options);
const animation2 = viewTransition.new.animate(keyframes, options);
return () => {
animation1.cancel();
animation2.cancel();
};
} else {
// Custom Timeline
const options = {
Expand All @@ -120,11 +128,10 @@ export default function Page({url, navigate}) {
// Let the custom timeline take control of driving the animations.
const cleanup1 = timeline.animate(animation1);
const cleanup2 = timeline.animate(animation2);
// TODO: Support returning a clean up function from ViewTransition events.
// return () => {
// cleanup1();
// cleanup2();
// };
return () => {
cleanup1();
cleanup2();
};
}
}

Expand Down
7 changes: 7 additions & 0 deletions packages/react-art/src/ReactFiberConfigART.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,13 @@ export function startGestureTransition() {

export function stopViewTransition(transition: RunningViewTransition) {}

export function addViewTransitionFinishedListener(
transition: RunningViewTransition,
callback: () => void,
) {
callback();
}

export type ViewTransitionInstance = null | {name: string, ...};

export function createViewTransitionInstance(
Expand Down
8 changes: 8 additions & 0 deletions packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -2337,6 +2337,7 @@ export function startViewTransition(

export type RunningViewTransition = {
skipTransition(): void,
finished: Promise<void>,
...
};

Expand Down Expand Up @@ -2784,6 +2785,13 @@ export function stopViewTransition(transition: RunningViewTransition) {
transition.skipTransition();
}

export function addViewTransitionFinishedListener(
transition: RunningViewTransition,
callback: () => void,
) {
transition.finished.finally(callback);
}

interface ViewTransitionPseudoElementType extends mixin$Animatable {
_scope: HTMLElement;
_selector: string;
Expand Down
7 changes: 7 additions & 0 deletions packages/react-native-renderer/src/ReactFiberConfigNative.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,13 @@ export function startGestureTransition(

export function stopViewTransition(transition: RunningViewTransition) {}

export function addViewTransitionFinishedListener(
transition: RunningViewTransition,
callback: () => void,
) {
callback();
}

export type ViewTransitionInstance = null | {name: string, ...};

export function createViewTransitionInstance(
Expand Down
7 changes: 7 additions & 0 deletions packages/react-noop-renderer/src/createReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,13 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {

stopViewTransition(transition: RunningViewTransition) {},

addViewTransitionFinishedListener(
transition: RunningViewTransition,
callback: () => void,
) {
callback();
},

createViewTransitionInstance(name: string): ViewTransitionInstance {
return null;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const startViewTransition = shim;
export type RunningViewTransition = null;
export const startGestureTransition = shim;
export const stopViewTransition = shim;
export const addViewTransitionFinishedListener = shim;
export type ViewTransitionInstance = null | {name: string, ...};
export const createViewTransitionInstance = shim;
export type GestureTimeline = any;
Expand Down
40 changes: 30 additions & 10 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ import {
startViewTransition,
startGestureTransition,
stopViewTransition,
addViewTransitionFinishedListener,
createViewTransitionInstance,
flushHydrationEvents,
} from './ReactFiberConfig';
Expand Down Expand Up @@ -733,8 +734,9 @@ let pendingEffectsRenderEndTime: number = -0; // Profiling-only
let pendingPassiveTransitions: Array<Transition> | null = null;
let pendingRecoverableErrors: null | Array<CapturedValue<mixed>> = null;
let pendingViewTransition: null | RunningViewTransition = null;
let pendingViewTransitionEvents: Array<(types: Array<string>) => void> | null =
null;
let pendingViewTransitionEvents: Array<
(types: Array<string>) => void | (() => void),
> | null = null;
let pendingTransitionTypes: null | TransitionTypes = null;
let pendingDidIncludeRenderPhaseUpdate: boolean = false;
let pendingSuspendedCommitReason: SuspendedCommitReason = null; // Profiling-only
Expand Down Expand Up @@ -899,7 +901,10 @@ export function requestDeferredLane(): Lane {

export function scheduleViewTransitionEvent(
fiber: Fiber,
callback: ?(instance: ViewTransitionInstance, types: Array<string>) => void,
callback: ?(
instance: ViewTransitionInstance,
types: Array<string>,
) => void | (() => void),
): void {
if (enableViewTransition) {
if (callback != null) {
Expand All @@ -925,7 +930,7 @@ export function scheduleGestureTransitionEvent(
options: GestureOptionsRequired,
instance: ViewTransitionInstance,
types: Array<string>,
) => void,
) => void | (() => void),
): void {
if (enableGestureTransition) {
if (callback != null) {
Expand Down Expand Up @@ -4143,6 +4148,7 @@ function flushSpawnedWork(): void {

pendingEffectsStatus = NO_PENDING_EFFECTS;

const committedViewTransition = pendingViewTransition;
pendingViewTransition = null; // The view transition has now fully started.

// Tell Scheduler to yield at the end of the frame, so the browser has an
Expand Down Expand Up @@ -4262,9 +4268,14 @@ function flushSpawnedWork(): void {
// Normalize the type. This is lazily created only for events.
pendingTypes = [];
}
for (let i = 0; i < pendingEvents.length; i++) {
const viewTransitionEvent = pendingEvents[i];
viewTransitionEvent(pendingTypes);
if (committedViewTransition !== null) {
for (let i = 0; i < pendingEvents.length; i++) {
const viewTransitionEvent = pendingEvents[i];
const cleanup = viewTransitionEvent(pendingTypes);
if (cleanup !== undefined) {
addViewTransitionFinishedListener(committedViewTransition, cleanup);
}
}
}
}
}
Expand Down Expand Up @@ -4532,9 +4543,18 @@ function flushGestureAnimations(): void {
// Normalize the type. This is lazily created only for events.
pendingTypes = [];
}
for (let i = 0; i < pendingEvents.length; i++) {
const viewTransitionEvent = pendingEvents[i];
viewTransitionEvent(pendingTypes);
const appliedGesture = root.pendingGestures;
if (appliedGesture !== null) {
const runningTransition = appliedGesture.running;
if (runningTransition !== null) {
for (let i = 0; i < pendingEvents.length; i++) {
const viewTransitionEvent = pendingEvents[i];
const cleanup = viewTransitionEvent(pendingTypes);
if (cleanup !== undefined) {
addViewTransitionFinishedListener(runningTransition, cleanup);
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ export const hasInstanceAffectedParent = $$$config.hasInstanceAffectedParent;
export const startViewTransition = $$$config.startViewTransition;
export const startGestureTransition = $$$config.startGestureTransition;
export const stopViewTransition = $$$config.stopViewTransition;
export const addViewTransitionFinishedListener =
$$$config.addViewTransitionFinishedListener;
export const getCurrentGestureOffset = $$$config.getCurrentGestureOffset;
export const createViewTransitionInstance =
$$$config.createViewTransitionInstance;
Expand Down
7 changes: 7 additions & 0 deletions packages/react-test-renderer/src/ReactFiberConfigTestHost.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,13 @@ export function startGestureTransition(

export function stopViewTransition(transition: RunningViewTransition) {}

export function addViewTransitionFinishedListener(
transition: RunningViewTransition,
callback: () => void,
) {
callback();
}

export type ViewTransitionInstance = null | {name: string, ...};

export function createViewTransitionInstance(
Expand Down
28 changes: 20 additions & 8 deletions packages/shared/ReactTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,34 +303,46 @@ export type ViewTransitionProps = {
exit?: ViewTransitionClass,
share?: ViewTransitionClass,
update?: ViewTransitionClass,
onEnter?: (instance: ViewTransitionInstance, types: Array<string>) => void,
onExit?: (instance: ViewTransitionInstance, types: Array<string>) => void,
onShare?: (instance: ViewTransitionInstance, types: Array<string>) => void,
onUpdate?: (instance: ViewTransitionInstance, types: Array<string>) => void,
onEnter?: (
instance: ViewTransitionInstance,
types: Array<string>,
) => void | (() => void),
onExit?: (
instance: ViewTransitionInstance,
types: Array<string>,
) => void | (() => void),
onShare?: (
instance: ViewTransitionInstance,
types: Array<string>,
) => void | (() => void),
onUpdate?: (
instance: ViewTransitionInstance,
types: Array<string>,
) => void | (() => void),
onGestureEnter?: (
timeline: GestureProvider,
options: GestureOptionsRequired,
instance: ViewTransitionInstance,
types: Array<string>,
) => void,
) => void | (() => void),
onGestureExit?: (
timeline: GestureProvider,
options: GestureOptionsRequired,
instance: ViewTransitionInstance,
types: Array<string>,
) => void,
) => void | (() => void),
onGestureShare?: (
timeline: GestureProvider,
options: GestureOptionsRequired,
instance: ViewTransitionInstance,
types: Array<string>,
) => void,
) => void | (() => void),
onGestureUpdate?: (
timeline: GestureProvider,
options: GestureOptionsRequired,
instance: ViewTransitionInstance,
types: Array<string>,
) => void,
) => void | (() => void),
};

export type ActivityProps = {
Expand Down
Loading